-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Query Migration #1656
React Query Migration #1656
Changes from 1 commit
1336a7f
e7138a7
c5e2687
8b6165e
61e6288
a1b41e3
1cbaa94
d2628ce
e43bf91
712df06
10b2fd0
1befc83
0796456
d938ade
d82fc39
1d0d510
f563d0c
c3aa668
eab699a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,65 @@ | ||
import { api } from "@/utils/api"; | ||
import { authenticate } from "@/utils/auth"; | ||
import { db } from "@/utils/firebase"; | ||
import { collection, doc, getDoc, getDocs } from "firebase/firestore"; | ||
|
||
type Status = { | ||
pending: number; | ||
accepted: number; | ||
rejected: number; | ||
}; | ||
|
||
type Sizes = { | ||
XS?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. u can make this a record with enums |
||
S?: number; | ||
M?: number; | ||
L?: number; | ||
XL?: number; | ||
XXL?: number; | ||
}; | ||
|
||
interface Stats { | ||
teams: Status | Sizes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. record with enums |
||
participants: Status | Sizes; | ||
volunteers: Status | Sizes; | ||
judges: Status | Sizes; | ||
mentors: Status | Sizes; | ||
committees: Status | Sizes; | ||
sponsors: Status | Sizes; | ||
panels: Status | Sizes; | ||
admins: Status | Sizes; | ||
} | ||
|
||
type Event = { | ||
attendance: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. record |
||
name: string; | ||
}; | ||
|
||
export const getStats = async () => { | ||
const [statistics, events] = await Promise.all([ | ||
getDoc(doc(db, "statistics", "statistics")), | ||
getDocs(collection(db, "events")), | ||
]); | ||
|
||
const { | ||
teams, | ||
participants, | ||
teams, | ||
volunteers, | ||
judges, | ||
mentors, | ||
committees, | ||
sponsors, | ||
panels, | ||
admins, | ||
} = statistics.data(); | ||
} = statistics.data() as Stats; | ||
|
||
const attendees = {}; | ||
const attendees: Record<string, number> = {}; | ||
|
||
events.forEach((doc) => { | ||
const { name, attendance } = doc.data(); | ||
const { name, attendance } = doc.data() as Event; | ||
attendees[name] = attendance; | ||
}); | ||
|
||
const users = { | ||
admins, | ||
participants, | ||
teams, | ||
judges, | ||
|
@@ -36,23 +68,60 @@ export const getStats = async () => { | |
committees, | ||
sponsors, | ||
panels, | ||
admins, | ||
}; | ||
|
||
const sizeData = ["XS", "S", "M", "L", "XL", "XXL"]; | ||
const statusData = ["1", "0", "-1"]; | ||
|
||
const size = {}; | ||
const status = {}; | ||
const defaultShirts: Sizes = { | ||
XS: 0, | ||
S: 0, | ||
M: 0, | ||
L: 0, | ||
XL: 0, | ||
XXL: 0, | ||
}; | ||
|
||
const size = { | ||
teams: { ...defaultShirts }, | ||
participants: { ...defaultShirts }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cant u just say |
||
volunteers: { ...defaultShirts }, | ||
judges: { ...defaultShirts }, | ||
mentors: { ...defaultShirts }, | ||
committees: { ...defaultShirts }, | ||
sponsors: { ...defaultShirts }, | ||
panels: { ...defaultShirts }, | ||
admins: { ...defaultShirts }, | ||
}; | ||
|
||
const defaultRoles: Status = { | ||
pending: 0, | ||
accepted: 0, | ||
rejected: 0, | ||
}; | ||
|
||
const status = { | ||
teams: { ...defaultRoles }, | ||
participants: { ...defaultRoles }, | ||
volunteers: { ...defaultRoles }, | ||
judges: { ...defaultRoles }, | ||
mentors: { ...defaultRoles }, | ||
committees: { ...defaultRoles }, | ||
sponsors: { ...defaultRoles }, | ||
panels: { ...defaultRoles }, | ||
admins: { ...defaultRoles }, | ||
}; | ||
|
||
Object.entries(users).forEach(([group, entries]) => { | ||
size[group] = Object.fromEntries( | ||
const role = group as keyof Stats; | ||
|
||
size[role] = Object.fromEntries( | ||
Object.entries(entries).filter(([key]) => sizeData.includes(key)), | ||
); | ||
) as Sizes; | ||
|
||
status[group] = Object.fromEntries( | ||
status[role] = Object.fromEntries( | ||
Object.entries(entries).filter(([key]) => statusData.includes(key)), | ||
); | ||
) as Status; | ||
}); | ||
|
||
return { users: { status, size }, events: attendees }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type Event = { | ||
assignee?: string; | ||
category?: string; | ||
color?: string; | ||
description: string; | ||
end: { | ||
dateTime: string; | ||
timeZone: string; | ||
}; | ||
hidden: boolean; | ||
id: string; | ||
start: { | ||
dateTime: string; | ||
timeZone: string; | ||
}; | ||
startDate?: Date; | ||
endDate?: Date; | ||
summary: string; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it a record with enums