1- <!-- Inbox View showing a list of books and zimfarm notifications -->
1+ <!-- Inbox View showing a list of books, zimfarm notifications, and events -->
22
33<template >
44 <TabsList :active-tab =" currentTab" :tab-options =" tabOptions" @tab-changed =" handleTabChange" />
1515 @filters-changed =" handleZimfarmFiltersChange"
1616 @clear-filters =" clearFilters"
1717 />
18+ <EventFilters
19+ v-if =" currentTab == 'events'"
20+ :filters =" eventFilters"
21+ @filters-changed =" handleEventFiltersChange"
22+ @clear-filters =" clearFilters"
23+ />
1824 <BookTable
1925 v-show =" currentTab == 'books'"
2026 :headers =" headers"
2430 :loading-text =" loadingStore.loadingText"
2531 :errors =" errors"
2632 :filters =" bookFilters"
27- :selected-books =" selectedBooks"
28- :show-selection =" true"
2933 :show-filters =" true"
3034 @limit-changed =" handleLimitChange"
3135 @load-data =" loadData"
32- @selection-changed =" handleSelectionChanged"
3336 />
3437 <ZimfarmNotificationTable
3538 v-show =" currentTab == 'zimfarm_notifications'"
4043 :loading-text =" loadingStore.loadingText"
4144 :errors =" errors"
4245 :filters =" zimfarmFilters"
43- :selected-zimfarm-notifications =" selectedZimfarmNotifications"
44- :show-selection =" true"
4546 @limit-changed =" handleLimitChange"
4647 @load-data =" loadData"
47- @selection-changed =" handleSelectionChanged"
48+ />
49+ <EventTable
50+ v-show =" currentTab == 'events'"
51+ :headers =" headers"
52+ :events =" events"
53+ :paginator =" paginator"
54+ :loading =" loadingStore.isLoading"
55+ :loading-text =" loadingStore.loadingText"
56+ :errors =" errors"
57+ @limit-changed =" handleLimitChange"
58+ @load-data =" loadData"
4859 />
4960</template >
5061
@@ -54,11 +65,15 @@ import BookFilters from '@/components/BookFilters.vue'
5465import BookTable from ' @/components/BookTable.vue'
5566import ZimfarmNotificationFilters from ' @/components/ZimfarmNotificationFilters.vue'
5667import ZimfarmNotificationTable from ' @/components/ZimfarmNotificationTable.vue'
68+ import EventFilters from ' @/components/EventFilters.vue'
69+ import EventTable from ' @/components/EventTable.vue'
5770import { useLoadingStore } from ' @/stores/loading'
5871import { useBookStore } from ' @/stores/book'
5972import { useZimfarmNotificationStore } from ' @/stores/zimfarmNotification'
73+ import { useEventStore } from ' @/stores/event'
6074import type { BookLight } from ' @/types/book'
6175import type { ZimfarmNotificationLight } from ' @/types/zimfarmNotification'
76+ import type { EventLight } from ' @/types/event'
6277import type { Paginator } from ' @/types/base'
6378import { computed , onBeforeUnmount , onMounted , ref , watch } from ' vue'
6479import { useRouter , useRoute } from ' vue-router'
@@ -68,12 +83,14 @@ const route = useRoute()
6883
6984const bookStore = useBookStore ()
7085const zimfarmNotificationStore = useZimfarmNotificationStore ()
86+ const eventStore = useEventStore ()
7187const loadingStore = useLoadingStore ()
7288
7389// Filter options
7490const tabOptions = [
7591 { value: ' books' , label: ' BOOKS' },
7692 { value: ' zimfarm_notifications' , label: ' ZIMFARM NOTIFICATIONS' },
93+ { value: ' events' , label: ' EVENTS' },
7794]
7895
7996// Define headers for the table
@@ -92,6 +109,12 @@ const headers = computed(() => {
92109 { title: ' Received' , value: ' received_at' },
93110 { title: ' Status' , value: ' status' },
94111 ]
112+ case ' events' :
113+ return [
114+ { title: ' ID' , value: ' id' },
115+ { title: ' Created' , value: ' created_at' },
116+ { title: ' Topic' , value: ' topic' },
117+ ]
95118 default :
96119 return []
97120 }
@@ -102,12 +125,22 @@ const currentTab = computed(() => {
102125 return (Array .isArray (tab ) ? tab [0 ] : tab ) || ' books'
103126})
104127
105- const defaultLimit = computed (() =>
106- currentTab .value == ' book' ? bookStore .defaultLimit : zimfarmNotificationStore .defaultLimit ,
107- )
128+ const defaultLimit = computed (() => {
129+ switch (currentTab .value ) {
130+ case ' books' :
131+ return bookStore .defaultLimit
132+ case ' zimfarm_notifications' :
133+ return zimfarmNotificationStore .defaultLimit
134+ case ' events' :
135+ return eventStore .defaultLimit
136+ default :
137+ return 20
138+ }
139+ })
108140
109141const books = ref <BookLight []>([])
110142const zimfarmNotifications = ref <ZimfarmNotificationLight []>([])
143+ const events = ref <EventLight []>([])
111144const paginator = ref <Paginator >({
112145 page: Number (route .query .page ) || 1 ,
113146 page_size: defaultLimit .value ,
@@ -151,9 +184,19 @@ const zimfarmFilters = computed(() => {
151184 return derived
152185})
153186
187+ const eventFilters = computed (() => {
188+ const query = router .currentRoute .value .query
189+ const derived = {
190+ topic: ' ' ,
191+ }
192+ if (query .topic && typeof query .topic === ' string' ) {
193+ derived .topic = query .topic
194+ }
195+
196+ return derived
197+ })
198+
154199const intervalId = ref <number | null >(null )
155- const selectedBooks = ref <string []>([])
156- const selectedZimfarmNotifications = ref <string []>([])
157200
158201const handleTabChange = (newTab : string ) => {
159202 // Navigate to the new tab route
@@ -164,23 +207,28 @@ const handleTabChange = (newTab: string) => {
164207 })
165208}
166209
167- // Clear selections when switching tabs
168- watch (currentTab , () => {
169- selectedBooks .value = []
170- selectedZimfarmNotifications .value = []
171- })
172-
173210async function loadData(limit : number , skip : number , tab ? : string , hideLoading : boolean = false ) {
174211 if (! tab ) {
175212 tab = currentTab .value
176213 }
177214
178215 if (! hideLoading ) {
179- loadingStore .startLoading (
180- tab === ' books' ? ' Fetching books...' : ' Fetching zimfarm notifications...' ,
181- )
216+ let loadingText = ' Fetching data...'
217+ switch (tab ) {
218+ case ' books' :
219+ loadingText = ' Fetching books...'
220+ break
221+ case ' zimfarm_notifications' :
222+ loadingText = ' Fetching zimfarm notifications...'
223+ break
224+ case ' events' :
225+ loadingText = ' Fetching events...'
226+ break
227+ }
228+ loadingStore .startLoading (loadingText )
182229 books .value = []
183230 zimfarmNotifications .value = []
231+ events .value = []
184232 }
185233
186234 switch (tab ) {
@@ -213,6 +261,13 @@ async function loadData(limit: number, skip: number, tab?: string, hideLoading:
213261 zimfarmNotificationStore .savePaginatorLimit (limit )
214262 paginator .value = { ... zimfarmNotificationStore .paginator }
215263 break
264+ case ' events' :
265+ await eventStore .fetchEvents (limit , skip , eventFilters .value .topic || undefined )
266+ events .value = eventStore .events
267+ errors .value = eventStore .errors
268+ eventStore .savePaginatorLimit (limit )
269+ paginator .value = { ... eventStore .paginator }
270+ break
216271 default :
217272 throw new Error (` Invalid tab: ${tab } ` )
218273 }
@@ -230,6 +285,9 @@ async function handleLimitChange(newLimit: number) {
230285 case ' zimfarm_notifications' :
231286 zimfarmNotificationStore .savePaginatorLimit (newLimit )
232287 break
288+ case ' events' :
289+ eventStore .savePaginatorLimit (newLimit )
290+ break
233291 }
234292
235293 if (paginator .value .page != 1 ) {
@@ -245,7 +303,7 @@ async function handleLimitChange(newLimit: number) {
245303}
246304
247305function updateUrlFilters(
248- sourceFilters : typeof bookFilters .value | typeof ZimfarmNotificationFilters .value ,
306+ sourceFilters : typeof bookFilters .value | typeof zimfarmFilters . value | typeof eventFilters .value ,
249307) {
250308 // create query object from selected filters
251309 const query: Record <string , string | string []> = {}
@@ -255,7 +313,7 @@ function updateUrlFilters(
255313 query .tab = currentTab .value
256314 }
257315
258- if (sourceFilters .id ) {
316+ if (' id ' in sourceFilters && sourceFilters .id ) {
259317 query .id = sourceFilters .id
260318 }
261319
@@ -267,6 +325,10 @@ function updateUrlFilters(
267325 query .flag = sourceFilters .flag
268326 }
269327
328+ if (' topic' in sourceFilters && sourceFilters .topic ) {
329+ query .topic = sourceFilters .topic
330+ }
331+
270332 router .push ({
271333 name: route .name ,
272334 query: Object .keys (query ).length > 0 ? query : undefined ,
@@ -281,6 +343,9 @@ async function clearFilters() {
281343 case ' zimfarm_notifications' :
282344 updateUrlFilters ({ id: ' ' })
283345 break
346+ case ' events' :
347+ updateUrlFilters ({ topic: ' ' })
348+ break
284349 }
285350}
286351
@@ -292,15 +357,8 @@ async function handleZimfarmFiltersChange(newFilters: typeof zimfarmFilters.valu
292357 updateUrlFilters (newFilters )
293358}
294359
295- function handleSelectionChanged(newSelection : string []) {
296- switch (currentTab .value ) {
297- case ' books' :
298- selectedBooks .value = newSelection
299- break
300- case ' zimfarm_notifications' :
301- selectedZimfarmNotifications .value = newSelection
302- break
303- }
360+ async function handleEventFiltersChange(newFilters : typeof eventFilters .value ) {
361+ updateUrlFilters (newFilters )
304362}
305363
306364watch (
0 commit comments