@@ -9,19 +9,19 @@ const eventStore = useEventStore();
99
1010<template >
1111 <div class =" container" >
12- <Loading v-if =" loading " />
12+ <Loading v-if =" loadingEvents " />
1313 <div v-else >
14- <button
14+ <RouterLink
1515 v-if =" screenStore.mobile"
1616 class =" btn btn-primary mb-2"
1717 type =" button"
18- @click = " returnHome() "
18+ :to = " showPast ? '/history' : '/' "
1919 >
2020 All Events
21- </button >
21+ </RouterLink >
2222 <div class =" row" >
2323 <!-- Left column: List of cards -->
24- <Transition @after-leave =" showDetail = true" name =" mobile" >
24+ <Transition @after-leave =" showDetail = true" name =" mobile" appear >
2525 <div v-if =" !screenStore.mobile || showList" class =" noOverflow col-md-4 pb-1" >
2626 <EventCard
2727 v-for =" (event, index) in eventStore.events"
@@ -33,7 +33,7 @@ const eventStore = useEventStore();
3333 </div >
3434 </Transition >
3535 <!-- Right column: Display selected card details -->
36- <Transition @after-leave =" showList = true" name =" mobile" >
36+ <Transition @after-leave =" showList = true" name =" mobile" appear >
3737 <div class =" noOverflow col-md-8 pb-1" v-if =" !screenStore.mobile || showDetail" >
3838 <RouterView />
3939 </div >
@@ -44,49 +44,24 @@ const eventStore = useEventStore();
4444</template >
4545
4646<script lang="ts">
47- import { PopupType } from ' @/models' ;
4847import { defineComponent } from ' vue' ;
49- import { usePopupStore } from ' @/stores/popup' ;
5048import { useScreenStore } from ' @/stores/screen' ;
5149
5250export default defineComponent ({
5351 props: {
54- showPast: Boolean ,
55- id: Number
52+ showPast: Boolean
5653 },
5754 data() {
5855 let screenStore = useScreenStore ();
5956 return {
6057 showList: true ,
6158 showDetail: false ,
6259 screenStore ,
63- loading: true
60+ loadingEvents: false ,
61+ firstLoad: true
6462 };
6563 },
6664 methods: {
67- async fetchCardData() {
68- const popupStore = usePopupStore ();
69- try {
70- const response = await fetch (
71- ' /api/v1/event/?' +
72- new URLSearchParams ({
73- past: this .showPast .toString ()
74- }).toString ()
75- );
76- if (! response .ok ) {
77- popupStore .addPopup (PopupType .Danger , ` Failed to Get Events (${response .status }) ` );
78- return ;
79- }
80- const data = await response .json ();
81- const eventStore = useEventStore ();
82- eventStore .setEvents (data );
83- eventStore .sortEvents (this .showPast );
84- this .loading = false ;
85- } catch (error ) {
86- console .error (error );
87- popupStore .addPopup (PopupType .Danger , ' Failed to Get Events. An unknown error occured.' );
88- }
89- },
9065 selectEvent() {
9166 if (this .screenStore .width < 768 ) {
9267 this .showList = false ;
@@ -96,8 +71,29 @@ export default defineComponent({
9671 this .showDetail = false ;
9772 }
9873 },
99- created() {
100- this .fetchCardData (); // Fetch card data when the component is created
74+ mounted() {
75+ if (this .$route .params .id != undefined && this .screenStore .width < 768 ) {
76+ this .showList = false ;
77+
78+ // this feels so cursed but i don't know how to make it work otherwise
79+ // it work being when you first visit a page the transition doesn't run
80+ // I thought this would help but it doesn't https://vuejs.org/guide/built-ins/transition#transition-on-appear
81+ if (this .firstLoad ) {
82+ this .showDetail = true ;
83+ }
84+ }
85+
86+ this .firstLoad = false ;
87+ },
88+ async created() {
89+ const eventStore = useEventStore ();
90+ if (! eventStore .isLoaded ) {
91+ this .loadingEvents = true ;
92+ }
93+
94+ if (await eventStore .loadEvents (this .showPast )) {
95+ this .loadingEvents = false ;
96+ }
10197 },
10298 provide() {
10399 return {
0 commit comments