From 4ea4756a1f2d384dde7b78b14419e4af3a68a9b0 Mon Sep 17 00:00:00 2001 From: gitschwifty <16038050+gitschwifty@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:21:08 -0400 Subject: [PATCH] lint --- front-end/src/components/Tickets.tsx | 416 +++++++++++++-------------- front-end/src/stores/Store.ts | 402 +++++++++++++------------- 2 files changed, 409 insertions(+), 409 deletions(-) diff --git a/front-end/src/components/Tickets.tsx b/front-end/src/components/Tickets.tsx index 854e7f4..be30af8 100644 --- a/front-end/src/components/Tickets.tsx +++ b/front-end/src/components/Tickets.tsx @@ -1,196 +1,196 @@ -import dayjs from "dayjs"; -import React from "react"; - -import { observer } from "../mobx/misc"; -import WindowObservables from "../mobx/WindowObservables"; -import Store from "../stores/Store"; -import Button from "./core/Button"; -import Col from "./core/Col"; -import LoadingDots from "./core/LoadingDots"; -import Modal from "./core/Modal"; -import Spacer from "./core/Spacer"; -import PurchaseTicketsModal from "./tickets/PurchaseTicketsModal"; -import Ticket from "./tickets/Ticket"; +import dayjs from 'dayjs' +import React from 'react' + +import { observer } from '../mobx/misc' +import WindowObservables from '../mobx/WindowObservables' +import Store from '../stores/Store' +import Button from './core/Button' +import Col from './core/Col' +import LoadingDots from './core/LoadingDots' +import Modal from './core/Modal' +import Spacer from './core/Spacer' +import PurchaseTicketsModal from './tickets/PurchaseTicketsModal' +import Ticket from './tickets/Ticket' export default observer(() => { - const loading = Store.accountInfo.state.kind === "loading"; - const loadingOrError = loading || Store.accountInfo.state.kind === "error"; - - const { application_status } = Store.accountInfo.state.result ?? {}; - - return ( - - {loading ? ( - - ) : Store.accountInfo.state.kind === "error" || + const loading = Store.accountInfo.state.kind === 'loading' + const loadingOrError = loading || Store.accountInfo.state.kind === 'error' + + const { application_status } = Store.accountInfo.state.result ?? {} + + return ( + + {loading ? ( + + ) : Store.accountInfo.state.kind === 'error' || Store.accountInfo.state.result == null ? ( - "Failed to load" - ) : Store.accountInfo.state.kind === "result" ? ( - <> -

My tickets

+ 'Failed to load' + ) : Store.accountInfo.state.kind === 'result' ? ( + <> +

My tickets

- + - {/* {Store.accountInfo.state.result.allowed_to_purchase + {/* {Store.accountInfo.state.result.allowed_to_purchase ? <> */} - {Store.festivals.state.result?.map((festival) => { - const tickets = - Store.purchasedTicketsByFestival[festival.festival_id] ?? []; - const otherPurchases = - Store.nonTicketPurchasesByFestival[festival.festival_id] ?? []; - const cabinName = - festival.festival_id === "4821bd6a-9e16-4944-b9a1-afe3256ff18d" - ? Store.vibecampCabin - : null; - - return ( -
-

{festival.festival_name}

- - - - {tickets.length === 0 && ( - <> -
- {"(after you purchase tickets they'll show up here)"} -
- - - )} - - {tickets.map((ticket, index) => ( - - {index > 0 && } - - - ))} - - {cabinName !== null && cabinName.state.result !== null ? ( - cabinName.state.result === "" ? ( - -
No Cabin
-
- ) : ( - + {Store.festivals.state.result?.map((festival) => { + const tickets = + Store.purchasedTicketsByFestival[festival.festival_id] ?? [] + const otherPurchases = + Store.nonTicketPurchasesByFestival[festival.festival_id] ?? [] + const cabinName = + festival.festival_id === '4821bd6a-9e16-4944-b9a1-afe3256ff18d' + ? Store.vibecampCabin + : null + + return ( +
+

{festival.festival_name}

+ + + + {tickets.length === 0 && ( + <> +
+ {'(after you purchase tickets they\'ll show up here)'} +
+ + + )} + + {tickets.map((ticket, index) => ( + + {index > 0 && } + + + ))} + + {cabinName !== null && cabinName.state.result !== null ? ( + cabinName.state.result === '' ? ( + +
No Cabin
+
+ ) : ( + Cabin: {cabinName.state.result} - - ) - ) : null} + + ) + ) : null} - {Store.purchaseTypes.state.result && + {Store.purchaseTypes.state.result && otherPurchases.length > 0 && ( -
+
Other purchases: - -
- {otherPurchases.map((p, i) => ( -
0 ? "var(--controls-border)" : undefined, - }} - key={p.purchase_id} - > - 1x{" "} - { - Store.purchaseTypes.state.result?.find( - (t) => t.purchase_type_id === p.purchase_type_id - )?.description - } -
- ))} -
-
- )} - - {festival.sales_are_open && ( - <> - - - - - )} - - {festival.info_url && ( - <> - - - + +
+ {otherPurchases.map((p, i) => ( +
0 ? 'var(--controls-border)' : undefined, + }} + key={p.purchase_id} + > + 1x{' '} + { + Store.purchaseTypes.state.result?.find( + (t) => t.purchase_type_id === p.purchase_type_id + )?.description + } +
+ ))} +
+
+ )} + + {festival.sales_are_open && ( + <> + + + + + )} + + {festival.info_url && ( + <> + + + Info about {festival.festival_name} - - + + open_in_new - - - - )} - - - - + + + + )} + + + + Need financial aid? Apply here - - + + open_in_new - - - - -
- -
- ); - })} - - {/* */} - {/* */} - {/* + + + + +
+ +
+ ) + })} + + {/* */} + {/* */} + {/* : <>

Welcome! @@ -237,44 +237,44 @@ export default observer(() => { */} - + -
+
Questions or issues?  - Email us -
- - ) : null} - - - {() => Store.accountInfo.state.result && } - - - ); -}); + Email us +
+ + ) : null} + + + {() => Store.accountInfo.state.result && } + + + ) +}) const closeTicketPurchaseModal = () => { - WindowObservables.assignHashState({ ticketPurchaseModalState: null }); -}; + WindowObservables.assignHashState({ ticketPurchaseModalState: null }) +} const openTicketPurchaseModal = (festival_id: string) => () => { - WindowObservables.assignHashState({ ticketPurchaseModalState: festival_id }); -}; + WindowObservables.assignHashState({ ticketPurchaseModalState: festival_id }) +} const closeApplicationModal = () => { - WindowObservables.assignHashState({ applicationModalOpen: false }); -}; + WindowObservables.assignHashState({ applicationModalOpen: false }) +} const handleApplicationSubmissionSuccess = () => { - closeApplicationModal(); - void Store.accountInfo.load(); -}; + closeApplicationModal() + void Store.accountInfo.load() +} const openApplicationModal = () => { - WindowObservables.assignHashState({ applicationModalOpen: true }); -}; + WindowObservables.assignHashState({ applicationModalOpen: true }) +} diff --git a/front-end/src/stores/Store.ts b/front-end/src/stores/Store.ts index 5f01654..55135bd 100644 --- a/front-end/src/stores/Store.ts +++ b/front-end/src/stores/Store.ts @@ -1,241 +1,241 @@ -import dayjs, { Dayjs } from "dayjs"; -import jwtDecode from "jwt-decode"; -import { autorun, makeAutoObservable } from "mobx"; +import dayjs, { Dayjs } from 'dayjs' +import jwtDecode from 'jwt-decode' +import { autorun, makeAutoObservable } from 'mobx' -import { Tables } from "../../../back-end/types/db-types.ts"; -import { VibeJWTPayload } from "../../../back-end/types/misc"; -import { ONE_YEAR_MS } from "../../../back-end/utils/constants.ts"; +import { Tables } from '../../../back-end/types/db-types.ts' +import { VibeJWTPayload } from '../../../back-end/types/misc' +import { ONE_YEAR_MS } from '../../../back-end/utils/constants.ts' import { - given, - objectEntries, - objectFromEntries, -} from "../../../back-end/utils/misc.ts"; -import { request } from "../mobx/request"; -import { jsonParse } from "../utils"; -import { vibefetch } from "../vibefetch"; + given, + objectEntries, + objectFromEntries, +} from '../../../back-end/utils/misc.ts' +import { request } from '../mobx/request' +import { jsonParse } from '../utils' +import { vibefetch } from '../vibefetch' -const JWT_KEY = "jwt"; +const JWT_KEY = 'jwt' class Store { - constructor() { - makeAutoObservable(this); + constructor() { + makeAutoObservable(this) - autorun(() => { - localStorage.setItem(JWT_KEY, JSON.stringify(this.jwt)); - }); - } + autorun(() => { + localStorage.setItem(JWT_KEY, JSON.stringify(this.jwt)) + }) + } + + readonly purchaseTypes = request(() => + vibefetch(null, '/tables/purchase_type', 'get', undefined).then( + (res) => res.body + ) + ) - readonly purchaseTypes = request(() => - vibefetch(null, "/tables/purchase_type", "get", undefined).then( - (res) => res.body + readonly discounts = request(() => + vibefetch(null, '/tables/discount', 'get', undefined).then( + (res) => res.body + ) ) - ); - readonly discounts = request(() => - vibefetch(null, "/tables/discount", "get", undefined).then( - (res) => res.body + readonly festivals = request(() => + vibefetch(null, '/tables/festival', 'get', undefined) + .then((res) => res.body) + .then((f) => + f?.map((f) => ({ + ...f, + start_date: dayjs.utc(f.start_date), + end_date: dayjs.utc(f.end_date), + })) + ) + .then((f) => + f?.sort((a, b) => festivalComparator(a) - festivalComparator(b)) + ) ) - ); - - readonly festivals = request(() => - vibefetch(null, "/tables/festival", "get", undefined) - .then((res) => res.body) - .then((f) => - f?.map((f) => ({ - ...f, - start_date: dayjs.utc(f.start_date), - end_date: dayjs.utc(f.end_date), - })) - ) - .then((f) => - f?.sort((a, b) => festivalComparator(a) - festivalComparator(b)) - ) - ); - - readonly festivalSites = request(() => - vibefetch(null, "/tables/festival_site", "get", undefined).then( - (res) => res.body + + readonly festivalSites = request(() => + vibefetch(null, '/tables/festival_site', 'get', undefined).then( + (res) => res.body + ) ) - ); - readonly eventSites = request(() => - vibefetch(null, "/tables/event_site", "get", undefined).then( - (res) => res.body + readonly eventSites = request(() => + vibefetch(null, '/tables/event_site', 'get', undefined).then( + (res) => res.body + ) ) - ); - get festivalsWithSalesOpen() { - return this.festivals.state.result?.filter((f) => f.sales_are_open) ?? []; - } + get festivalsWithSalesOpen() { + return this.festivals.state.result?.filter((f) => f.sales_are_open) ?? [] + } - readonly festivalsHappeningAt = (date: Dayjs) => - this.festivals.state.result?.filter( - (e) => - date.isAfter(dayjs.utc(e.start_date)) && + readonly festivalsHappeningAt = (date: Dayjs) => + this.festivals.state.result?.filter( + (e) => + date.isAfter(dayjs.utc(e.start_date)) && date.isBefore(dayjs.utc(e.end_date)) - ) ?? []; - /// User - jwt: string | null = - given(localStorage.getItem(JWT_KEY), (jwt) => { - const parsed = jsonParse(jwt); - - if (typeof parsed === "string") { - return parsed; - } else { - return null; - } - }) ?? null; - - readonly logOut = () => { - this.jwt = null; - }; - - get loggedIn() { - return this.jwt != null; - } - - get jwtPayload() { - if (this.jwt != null) { - try { - return jwtDecode(this.jwt); - } catch {} + ) ?? [] + /// User + jwt: string | null = + given(localStorage.getItem(JWT_KEY), (jwt) => { + const parsed = jsonParse(jwt) + + if (typeof parsed === 'string') { + return parsed + } else { + return null + } + }) ?? null + + readonly logOut = () => { + this.jwt = null } - } - - readonly vibecampCabin = request(async () => { - if (this.jwt != null) { - const res = await vibefetch(this.jwt, "/account/cabin", "get", undefined); - if (res.body) { - return res.body?.cabin_name; - } else { - return "unknown error"; - } - } else { - return null; + + get loggedIn() { + return this.jwt != null } - }); - readonly accountInfo = request(async () => { - if (this.jwt != null) { - const res = await vibefetch(this.jwt, "/account", "get", undefined); + get jwtPayload() { + if (this.jwt != null) { + try { + return jwtDecode(this.jwt) + } catch {} + } + } + + readonly vibecampCabin = request(async () => { + if (this.jwt != null) { + const res = await vibefetch(this.jwt, '/account/cabin', 'get', undefined) + if (res.body) { + return res.body?.cabin_name + } else { + return 'unknown error' + } + } else { + return null + } + }) + + readonly accountInfo = request(async () => { + if (this.jwt != null) { + const res = await vibefetch(this.jwt, '/account', 'get', undefined) - // if JWT token doesn't work, clear it and kick user back to the login screen - if (res.status === 401) { - this.jwt = null; - } + // if JWT token doesn't work, clear it and kick user back to the login screen + if (res.status === 401) { + this.jwt = null + } - return res.body; - } else { - return null; + return res.body + } else { + return null + } + }) + + get primaryAttendee() { + return this.accountInfo.state.result?.attendees.find( + (a) => a.is_primary_for_account + ) } - }); - - get primaryAttendee() { - return this.accountInfo.state.result?.attendees.find( - (a) => a.is_primary_for_account - ); - } - - get purchasesByFestival() { - const purchasesByFestival: Record< - Tables["festival"]["festival_id"], - Tables["purchase"][] + + get purchasesByFestival() { + const purchasesByFestival: Record< + Tables['festival']['festival_id'], + Tables['purchase'][] > = objectFromEntries( - this.festivals.state.result?.map((f) => [f.festival_id, []]) ?? [] - ); + this.festivals.state.result?.map((f) => [f.festival_id, []]) ?? [] + ) - const accountInfo = this.accountInfo.state.result; + const accountInfo = this.accountInfo.state.result - if (accountInfo != null) { - for (const purchase of accountInfo.purchases) { - const festival_id = this.purchaseTypes.state.result?.find( - (t) => t.purchase_type_id === purchase.purchase_type_id - )?.festival_id; + if (accountInfo != null) { + for (const purchase of accountInfo.purchases) { + const festival_id = this.purchaseTypes.state.result?.find( + (t) => t.purchase_type_id === purchase.purchase_type_id + )?.festival_id - if (festival_id) { - const arr = purchasesByFestival[festival_id]; + if (festival_id) { + const arr = purchasesByFestival[festival_id] - if (arr) { - arr.push(purchase); - } + if (arr) { + arr.push(purchase) + } + } + } } - } + + return purchasesByFestival } - return purchasesByFestival; - } - - get purchasedTicketsByFestival() { - return objectFromEntries( - objectEntries(this.purchasesByFestival).map( - ([festival_id, purchases]) => [ - festival_id, - purchases.filter( - (p) => - this.purchaseTypes.state.result?.find( - (t) => t.purchase_type_id === p.purchase_type_id - )?.is_attendance_ticket - ), - ] - ) - ); - } - - get nonTicketPurchasesByFestival() { - return objectFromEntries( - objectEntries(this.purchasesByFestival).map( - ([festival_id, purchases]) => [ - festival_id, - purchases.filter( - (p) => - !this.purchaseTypes.state.result?.find( - (t) => t.purchase_type_id === p.purchase_type_id - )?.is_attendance_ticket - ), - ] - ) - ); - } - - /// Events - readonly allEvents = request(async () => { - if (this.jwt != null) { - return ( - await vibefetch(this.jwt, "/events", "get", undefined) - ).body?.events.map((e) => ({ - ...e, - start_datetime: dayjs.utc(e.start_datetime), - end_datetime: e.end_datetime ? dayjs.utc(e.end_datetime) : null, - })); - } else { - return null; + get purchasedTicketsByFestival() { + return objectFromEntries( + objectEntries(this.purchasesByFestival).map( + ([festival_id, purchases]) => [ + festival_id, + purchases.filter( + (p) => + this.purchaseTypes.state.result?.find( + (t) => t.purchase_type_id === p.purchase_type_id + )?.is_attendance_ticket + ), + ] + ) + ) } - }); - - readonly bookmarks = request( - async () => { - if (this.jwt != null) { - return (await vibefetch(this.jwt, "/event/bookmarks", "get", undefined)) - .body; - } else { - return null; - } - }, - { keepLatest: true } - ); + + get nonTicketPurchasesByFestival() { + return objectFromEntries( + objectEntries(this.purchasesByFestival).map( + ([festival_id, purchases]) => [ + festival_id, + purchases.filter( + (p) => + !this.purchaseTypes.state.result?.find( + (t) => t.purchase_type_id === p.purchase_type_id + )?.is_attendance_ticket + ), + ] + ) + ) + } + + /// Events + readonly allEvents = request(async () => { + if (this.jwt != null) { + return ( + await vibefetch(this.jwt, '/events', 'get', undefined) + ).body?.events.map((e) => ({ + ...e, + start_datetime: dayjs.utc(e.start_datetime), + end_datetime: e.end_datetime ? dayjs.utc(e.end_datetime) : null, + })) + } else { + return null + } + }) + + readonly bookmarks = request( + async () => { + if (this.jwt != null) { + return (await vibefetch(this.jwt, '/event/bookmarks', 'get', undefined)) + .body + } else { + return null + } + }, + { keepLatest: true } + ) } -const storeInstance = new Store(); +const storeInstance = new Store() const festivalComparator = (festival: { start_date: Dayjs; end_date: Dayjs | null; }) => { - const isInPast = festival.end_date?.isBefore(dayjs.utc()); - const oneHundredYears = 100 * ONE_YEAR_MS; - const modifier = isInPast ? oneHundredYears : 0; // push past events to the bottom of the list + const isInPast = festival.end_date?.isBefore(dayjs.utc()) + const oneHundredYears = 100 * ONE_YEAR_MS + const modifier = isInPast ? oneHundredYears : 0 // push past events to the bottom of the list - return festival.start_date.valueOf() + modifier; -}; + return festival.start_date.valueOf() + modifier +} -export default storeInstance; +export default storeInstance