From afeef67c58b67acc879ec2b62e3610a6c7f6438a Mon Sep 17 00:00:00 2001 From: Alder Whiteford Date: Thu, 20 Jun 2024 15:43:20 -0400 Subject: [PATCH] Linting --- .../mobile/src/app/app/(tabs)/profile.tsx | 10 ++-- frontend/mobile/src/app/app/event/[id].tsx | 50 ++++++++++++------- .../src/app/app/event/components/overview.tsx | 9 ++-- .../src/app/app/event/components/register.tsx | 50 +++++++++++++------ frontend/mobile/src/app/app/user/events.tsx | 17 +++---- frontend/mobile/src/hooks/useEvent.ts | 19 +++++-- .../mobile/src/store/slices/eventSlice.ts | 2 +- frontend/mobile/src/store/slices/userSlice.ts | 2 +- 8 files changed, 96 insertions(+), 63 deletions(-) diff --git a/frontend/mobile/src/app/app/(tabs)/profile.tsx b/frontend/mobile/src/app/app/(tabs)/profile.tsx index 27e8cc78..38df8e82 100644 --- a/frontend/mobile/src/app/app/(tabs)/profile.tsx +++ b/frontend/mobile/src/app/app/(tabs)/profile.tsx @@ -6,20 +6,20 @@ import { router } from 'expo-router'; import { IconDefinition, + faCalendar, faSignOutAlt, - faUser, - faCalendar + faUser } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'; import { GlobalLayout } from '@/src/app/design-system/components/GlobalLayout/GlobalLayout'; +import { resetClub } from '@/src/store/slices/clubSlice'; +import { resetEvent } from '@/src/store/slices/eventSlice'; import { resetAccessToken } from '@/src/store/slices/globalSlice'; +import { resetUser } from '@/src/store/slices/userSlice'; import { useAppDispatch, useAppSelector } from '@/src/store/store'; import { Box, Colors, SACColors, Spacing, Text } from '../../design-system'; -import { resetEvent } from '@/src/store/slices/eventSlice'; -import { resetUser } from '@/src/store/slices/userSlice'; -import { resetClub } from '@/src/store/slices/clubSlice'; type ProfileItemProps = { icon: IconDefinition; diff --git a/frontend/mobile/src/app/app/event/[id].tsx b/frontend/mobile/src/app/app/event/[id].tsx index 9b621f64..6a5565c2 100644 --- a/frontend/mobile/src/app/app/event/[id].tsx +++ b/frontend/mobile/src/app/app/event/[id].tsx @@ -12,12 +12,13 @@ import { Stack, useLocalSearchParams } from 'expo-router'; import { EventPreview, EventType, eventApi } from '@generatesac/lib'; import BottomSheet from '@gorhom/bottom-sheet'; -import { Arrow, Box, KebabMenu } from '@/src/app/design-system'; +import { Arrow, Box } from '@/src/app/design-system'; import { SACColors } from '@/src/app/design-system'; import { Button } from '@/src/app/design-system/components/Button/Button'; import { description, events, tags } from '@/src/consts/event-page'; import useEvent from '@/src/hooks/useEvent'; import { setEventId } from '@/src/store/slices/eventSlice'; +import { setUserRSVPs } from '@/src/store/slices/userSlice'; import { useAppDispatch, useAppSelector } from '@/src/store/store'; import AnimatedImageHeader from '../../design-system/components/AnimatedImageHeader/AnimatedImageHeader'; @@ -29,7 +30,6 @@ import { Overview } from './components/overview'; import { RegisterBottomSheet } from './components/register'; import { ShareEventBottomSheet } from './components/share-event'; import EventPageSkeleton from './components/skeleton'; -import { setUserRSVPs } from '@/src/store/slices/userSlice'; const MockEvent = { eventImage: @@ -66,7 +66,9 @@ const EventPage = () => { const { name: clubName, logo: clubLogo } = useAppSelector( (state) => state.club ); - const [userAttending, setUserAttending] = useState(event.rsvps.includes(userId)) + const [userAttending, setUserAttending] = useState( + event.rsvps.includes(userId) + ); const { setRetriggerFetch, apiLoading, apiError } = useEvent(); const [registerUser] = eventApi.useCreateEventRegistrationMutation(); @@ -84,10 +86,10 @@ const EventPage = () => { }, [userAttending]); const handleRegistration = () => { - registerUser({ user_id: userId, event_id: id as string }) - .then(({ error }) => { + registerUser({ user_id: userId, event_id: id as string }).then( + ({ error }) => { if (error) { - throw new Error() + throw new Error(); } else { setUserAttending(true); const eventPreview: EventPreview = { @@ -99,25 +101,31 @@ const EventPage = () => { end_time: event.end_time, location: event.location, event_type: event.event_type, - link: event.link, - } - dispatch(setUserRSVPs([...event.rsvps, eventPreview ])) + link: event.link + }; + dispatch(setUserRSVPs([...event.rsvps, eventPreview])); } - }) - } + } + ); + }; const handleUnregistration = () => { - unregisterUser({ user_id: userId, event_id: id as string }) - .then(({ error }) => { + unregisterUser({ user_id: userId, event_id: id as string }).then( + ({ error }) => { if (error) { console.log(error); throw new Error(); } else { setUserAttending(false); - dispatch(setUserRSVPs([...rsvps.filter((event) => event.id !== id)])) + dispatch( + setUserRSVPs([ + ...rsvps.filter((event) => event.id !== id) + ]) + ); } - }) - } + } + ); + }; const headerAnimatedStyle = useAnimatedStyle(() => { return { @@ -147,7 +155,7 @@ const EventPage = () => { - ), + ) }} /> { register.current?.snapToIndex(0) } > - {userAttending ? 'Registered': 'Register'} + {userAttending + ? 'Registered' + : 'Register'} { location={event?.location as string} eventType={event?.event_type as EventType} userAttending={userAttending} - onSubmit={userAttending ? handleUnregistration : handleRegistration} + onSubmit={ + userAttending ? handleUnregistration : handleRegistration + } ref={register} /> = { - 'in_person': 'In Person', - 'virtual': 'Virtual', - 'hybrid': 'Hybrid' -} + in_person: 'In Person', + virtual: 'Virtual', + hybrid: 'Hybrid' +}; interface OverviewProps { logo: string; diff --git a/frontend/mobile/src/app/app/event/components/register.tsx b/frontend/mobile/src/app/app/event/components/register.tsx index d75dfe15..ab186ea7 100644 --- a/frontend/mobile/src/app/app/event/components/register.tsx +++ b/frontend/mobile/src/app/app/event/components/register.tsx @@ -33,10 +33,21 @@ interface RegisterSheetProps { const RegisterBottomSheet = forwardRef( ( - { eventType, eventName, location, eventDetail, startTime, endTime, userAttending, onSubmit }, + { + eventType, + eventName, + location, + eventDetail, + startTime, + endTime, + userAttending, + onSubmit + }, ref ) => { - const [sheet, setSheet] = useState(userAttending ? 'unregister' : 'register'); + const [sheet, setSheet] = useState( + userAttending ? 'unregister' : 'register' + ); const renderBackdrop = useCallback( (props: any) => ( @@ -49,7 +60,10 @@ const RegisterBottomSheet = forwardRef( [] ); - const handleRegistrationNavAndSubmit = (submit: boolean, nextSheet?: string) => { + const handleRegistrationNavAndSubmit = ( + submit: boolean, + nextSheet?: string + ) => { try { if (submit) { onSubmit(); @@ -58,7 +72,7 @@ const RegisterBottomSheet = forwardRef( setSheet(nextSheet); } } catch {} - } + }; const CALENDAR_INFO: CalendarLink = { eventDetail: eventDetail, @@ -76,16 +90,23 @@ const RegisterBottomSheet = forwardRef( enablePanDownToClose backgroundStyle={{ backgroundColor: 'white' }} backdropComponent={renderBackdrop} - onClose={() => setSheet(userAttending ? 'unregister' : 'register')} + onClose={() => + setSheet(userAttending ? 'unregister' : 'register') + } > - {sheet === 'unregister' && ( - - )} + {sheet === 'unregister' && } {sheet === 'register' && ( - + )} {sheet === 'attend' && ( - handleRegistrationNavAndSubmit(true, 'save')} /> + + handleRegistrationNavAndSubmit(true, 'save') + } + /> )} {sheet === 'save' && ( = ({ onClick }) => { Are you sure you want to unregister from this event? - ); -} +}; interface RegisterProps { - onClick: (submit: boolean, nextSheet?: string) => void + onClick: (submit: boolean, nextSheet?: string) => void; eventType: EventType; } diff --git a/frontend/mobile/src/app/app/user/events.tsx b/frontend/mobile/src/app/app/user/events.tsx index 01ecea17..06468936 100644 --- a/frontend/mobile/src/app/app/user/events.tsx +++ b/frontend/mobile/src/app/app/user/events.tsx @@ -1,18 +1,15 @@ -import { useEffect } from 'react'; import { SafeAreaView } from 'react-native'; import { Stack, router } from 'expo-router'; -import { userApi } from '@generatesac/lib'; - import { useAppSelector } from '@/src/store/store'; import { Arrow, Box, Button, Text } from '../../design-system'; -import { GlobalLayout } from '../../design-system/components/GlobalLayout/GlobalLayout'; import { EventCard } from '../../design-system/components/EventCard'; +import { GlobalLayout } from '../../design-system/components/GlobalLayout/GlobalLayout'; const UserEvents = () => { - const { id, rsvps } = useAppSelector((state) => state.user); + const { rsvps } = useAppSelector((state) => state.user); return ( <> @@ -37,9 +34,9 @@ const UserEvents = () => { {rsvps.map((event) => { return ( - { endTime={event.end_time} image={event.host_logo ?? ''} /> - ) + ); })} diff --git a/frontend/mobile/src/hooks/useEvent.ts b/frontend/mobile/src/hooks/useEvent.ts index 71dd3af7..27cbffec 100644 --- a/frontend/mobile/src/hooks/useEvent.ts +++ b/frontend/mobile/src/hooks/useEvent.ts @@ -3,7 +3,11 @@ import { useEffect, useState } from 'react'; import { eventApi } from '@generatesac/lib'; import { setClubId } from '../store/slices/clubSlice'; -import { setEvent, setEventAttendees, setEventTags } from '../store/slices/eventSlice'; +import { + setEvent, + setEventAttendees, + setEventTags +} from '../store/slices/eventSlice'; import { useAppDispatch, useAppSelector } from '../store/store'; const useEvent = () => { @@ -13,7 +17,10 @@ const useEvent = () => { eventApi.useLazyEventQuery(); const [getEventTags, { isLoading: tagsLoading, error: tagsError }] = eventApi.useLazyEventTagsQuery(); - const [getEventAttendees, { isLoading: attendeesLoading, error: attendeesError }] = eventApi.useLazyEventRegistrationsQuery(); + const [ + getEventAttendees, + { isLoading: attendeesLoading, error: attendeesError } + ] = eventApi.useLazyEventRegistrationsQuery(); const dispatch = useAppDispatch(); const { id: eventId } = useAppSelector((state) => state.event); @@ -39,10 +46,12 @@ const useEvent = () => { getEventAttendees(eventId).then(({ data: attendeeData }) => { if (attendeeData) { - const attendeeIds = attendeeData.map((attendeeData) => attendeeData.id) - dispatch(setEventAttendees(attendeeIds)) + const attendeeIds = attendeeData.map( + (attendeeData) => attendeeData.id + ); + dispatch(setEventAttendees(attendeeIds)); } - }) + }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [retriggerFetch, eventId]); diff --git a/frontend/mobile/src/store/slices/eventSlice.ts b/frontend/mobile/src/store/slices/eventSlice.ts index 799589b3..ffdabbf7 100644 --- a/frontend/mobile/src/store/slices/eventSlice.ts +++ b/frontend/mobile/src/store/slices/eventSlice.ts @@ -24,7 +24,7 @@ const initialState: Event & EventClubState = { preview: '', host: '', tags: [], - rsvps: [], + rsvps: [] }; export const eventSlice = createSlice({ diff --git a/frontend/mobile/src/store/slices/userSlice.ts b/frontend/mobile/src/store/slices/userSlice.ts index cdf7d5d6..d51c881b 100644 --- a/frontend/mobile/src/store/slices/userSlice.ts +++ b/frontend/mobile/src/store/slices/userSlice.ts @@ -14,7 +14,7 @@ const initialState: User & UserState = { name: '', role: 'student', following: [], - rsvps: [], + rsvps: [] }; export const userSlice = createSlice({