Skip to content

Commit faae53f

Browse files
authored
Merge pull request #19 from BigSpaceships/master
Removed /event route and fixed phone UI bugs
2 parents b76a6a0 + d65bed8 commit faae53f

File tree

5 files changed

+71
-49
lines changed

5 files changed

+71
-49
lines changed

src/frontend/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import PopupGroup from './components/PopupGroup.vue';
77
<template>
88
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
99
<div class="container">
10-
<a class="navbar-brand abs" href="/">Rideboard</a>
10+
<RouterLink class="navbar-brand abs" to="/">Rideboard</RouterLink>
1111
<button
1212
class="navbar-toggler navbar-toggler-right"
1313
type="button"

src/frontend/src/components/ShareEventButton.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ export default defineComponent({
1414
methods: {
1515
copyLink() {
1616
const popupStore = usePopupStore();
17-
const baseUrl = window.location.host;
1817
19-
const urlToCopy = baseUrl + '/event/' + this.eventId;
18+
const urlToCopy = window.location.href;
2019
2120
try {
2221
navigator.clipboard.writeText(urlToCopy);

src/frontend/src/router/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async function handleEventIdRedirects(
3131

3232
const jsonData: Event = await response.json();
3333

34-
const isInPast = new Date(jsonData.startTime).getTime() < Date.now();
34+
const isInPast = new Date(jsonData.endTime).getTime() < Date.now();
3535

3636
const isGoingToPast = to.path.includes('history');
3737

@@ -42,7 +42,7 @@ async function handleEventIdRedirects(
4242
if (isInPast) {
4343
return { path: `/history/${to.params.id}` };
4444
} else {
45-
return { path: `${to.params.id}` };
45+
return { path: `/${to.params.id}` };
4646
}
4747
}
4848

@@ -89,11 +89,6 @@ const router = createRouter({
8989
props: (route) => ({ id: Number(route.params.id) })
9090
}
9191
]
92-
},
93-
{
94-
path: '/event/:id',
95-
beforeEnter: handleEventIdRedirects,
96-
component: NoEventDetails // This never gets used but has to be here for the beforeEnter to be called
9792
}
9893
]
9994
});

src/frontend/src/stores/events.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineStore } from 'pinia';
2-
import { type Car, type Event } from '@/models';
2+
import { PopupType, type Car, type Event } from '@/models';
3+
import { usePopupStore } from './popup';
34

45
function sortByStartDate(a: Event, b: Event) {
56
return new Date(a.startTime).getTime() - new Date(b.startTime).getTime();
@@ -8,7 +9,9 @@ function sortByStartDate(a: Event, b: Event) {
89
export const useEventStore = defineStore('events', {
910
state: () => ({
1011
events: [] as Event[],
11-
id: null as number | null
12+
id: null as number | null,
13+
isLoaded: false,
14+
isHistory: false
1215
}),
1316
getters: {
1417
selectedEvent(state) {
@@ -21,11 +24,40 @@ export const useEventStore = defineStore('events', {
2124
}
2225
},
2326
actions: {
27+
async loadEvents(showPast: boolean) {
28+
const popupStore = usePopupStore();
29+
try {
30+
const response = await fetch(
31+
'/api/v1/event/?' +
32+
new URLSearchParams({
33+
past: showPast.toString()
34+
}).toString()
35+
);
36+
if (!response.ok) {
37+
popupStore.addPopup(PopupType.Danger, `Failed to Get Events (${response.status})`);
38+
return;
39+
}
40+
const data = await response.json();
41+
const eventStore = useEventStore();
42+
eventStore.setEvents(data, showPast);
43+
eventStore.sortEvents(showPast);
44+
45+
return true;
46+
} catch (error) {
47+
console.error(error);
48+
popupStore.addPopup(PopupType.Danger, 'Failed to Get Events. An unknown error occured.');
49+
50+
return false;
51+
}
52+
},
2453
addEvent(event: Event) {
2554
this.events.push(event);
2655
},
27-
setEvents(events: Event[]) {
56+
setEvents(events: Event[], isHistory: boolean) {
2857
this.events = events;
58+
59+
this.isHistory = isHistory;
60+
this.isLoaded = true;
2961
},
3062
setEventId(id: number) {
3163
this.id = id;

src/frontend/src/views/HomeView.vue

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
4847
import { defineComponent } from 'vue';
49-
import { usePopupStore } from '@/stores/popup';
5048
import { useScreenStore } from '@/stores/screen';
5149
5250
export 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

Comments
 (0)