Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed Jun 20, 2024
1 parent 5e97526 commit afeef67
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 63 deletions.
10 changes: 5 additions & 5 deletions frontend/mobile/src/app/app/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 31 additions & 19 deletions frontend/mobile/src/app/app/event/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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:
Expand Down Expand Up @@ -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();
Expand All @@ -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 = {
Expand All @@ -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)

Check warning on line 122 in frontend/mobile/src/app/app/event/[id].tsx

View workflow job for this annotation

GitHub Actions / Lint

'event' is already declared in the upper scope on line 65 column 11
])
);
}
})
}
}
);
};

const headerAnimatedStyle = useAnimatedStyle(() => {
return {
Expand Down Expand Up @@ -147,7 +155,7 @@ const EventPage = () => {
<Animated.View style={headerAnimatedStyle}>
<Arrow color={apiError ? 'black' : 'white'} />
</Animated.View>
),
)
}}
/>
<Animated.ScrollView
Expand Down Expand Up @@ -188,7 +196,9 @@ const EventPage = () => {
register.current?.snapToIndex(0)
}
>
{userAttending ? 'Registered': 'Register'}
{userAttending
? 'Registered'
: 'Register'}
</Button>
</Box>
<AboutEvent
Expand Down Expand Up @@ -216,7 +226,9 @@ const EventPage = () => {
location={event?.location as string}
eventType={event?.event_type as EventType}
userAttending={userAttending}
onSubmit={userAttending ? handleUnregistration : handleRegistration}
onSubmit={
userAttending ? handleUnregistration : handleRegistration
}
ref={register}
/>
<Description
Expand Down
9 changes: 4 additions & 5 deletions frontend/mobile/src/app/app/event/components/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { Avatar } from '@rneui/base';
import { Box, Colors, SACColors, Text } from '@/src/app/design-system';
import { setClubId, setClubShouldPreview } from '@/src/store/slices/clubSlice';
import { useAppDispatch } from '@/src/store/store';
import { firstLetterUppercase } from '@/src/utils/string';
import { createOptions, eventTime } from '@/src/utils/time';

const eventTypeMappings: Record<EventType, string> = {
'in_person': 'In Person',
'virtual': 'Virtual',
'hybrid': 'Hybrid'
}
in_person: 'In Person',
virtual: 'Virtual',
hybrid: 'Hybrid'
};

interface OverviewProps {
logo: string;
Expand Down
50 changes: 34 additions & 16 deletions frontend/mobile/src/app/app/event/components/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,21 @@ interface RegisterSheetProps {

const RegisterBottomSheet = forwardRef<Ref, RegisterSheetProps>(
(
{ 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) => (
Expand All @@ -49,7 +60,10 @@ const RegisterBottomSheet = forwardRef<Ref, RegisterSheetProps>(
[]
);

const handleRegistrationNavAndSubmit = (submit: boolean, nextSheet?: string) => {
const handleRegistrationNavAndSubmit = (
submit: boolean,
nextSheet?: string
) => {
try {
if (submit) {
onSubmit();
Expand All @@ -58,7 +72,7 @@ const RegisterBottomSheet = forwardRef<Ref, RegisterSheetProps>(
setSheet(nextSheet);
}
} catch {}
}
};

const CALENDAR_INFO: CalendarLink = {
eventDetail: eventDetail,
Expand All @@ -76,16 +90,23 @@ const RegisterBottomSheet = forwardRef<Ref, RegisterSheetProps>(
enablePanDownToClose
backgroundStyle={{ backgroundColor: 'white' }}
backdropComponent={renderBackdrop}
onClose={() => setSheet(userAttending ? 'unregister' : 'register')}
onClose={() =>
setSheet(userAttending ? 'unregister' : 'register')
}
>
{sheet === 'unregister' && (
<Unregister onClick={onSubmit} />
)}
{sheet === 'unregister' && <Unregister onClick={onSubmit} />}
{sheet === 'register' && (
<Register onClick={handleRegistrationNavAndSubmit} eventType={eventType} />
<Register
onClick={handleRegistrationNavAndSubmit}
eventType={eventType}
/>
)}
{sheet === 'attend' && (
<AttendanceType onPress={() => handleRegistrationNavAndSubmit(true, 'save')} />
<AttendanceType
onPress={() =>
handleRegistrationNavAndSubmit(true, 'save')
}
/>
)}
{sheet === 'save' && (
<SaveEvent
Expand Down Expand Up @@ -117,19 +138,16 @@ const Unregister: React.FC<UnregisterProps> = ({ onClick }) => {
Are you sure you want to unregister from this event?
</Text>
<Box marginTop="s" flexDirection="column" gap="s">
<Button
onPress={() => onClick()}
variant="standardButton"
>
<Button onPress={() => onClick()} variant="standardButton">
<Text>Yes</Text>
</Button>
</Box>
</Box>
);
}
};

interface RegisterProps {
onClick: (submit: boolean, nextSheet?: string) => void
onClick: (submit: boolean, nextSheet?: string) => void;
eventType: EventType;
}

Expand Down
17 changes: 6 additions & 11 deletions frontend/mobile/src/app/app/user/events.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
Expand All @@ -37,9 +34,9 @@ const UserEvents = () => {
<Box gap="s" width="100%">
{rsvps.map((event) => {
return (
<EventCard
<EventCard
key={event.id}
variant='club'
variant="club"
event={event.name}
eventId={event.id}
club={event.host_name}
Expand All @@ -48,15 +45,13 @@ const UserEvents = () => {
endTime={event.end_time}
image={event.host_logo ?? ''}
/>
)
);
})}
<Box marginTop="m">
<Button
variant="standardButton"
color="darkRed"
onPress={() =>
router.push('/app/calendar')
}
onPress={() => router.push('/app/calendar')}
>
Explore New Events
</Button>
Expand Down
19 changes: 14 additions & 5 deletions frontend/mobile/src/hooks/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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);
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/mobile/src/store/slices/eventSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const initialState: Event & EventClubState = {
preview: '',
host: '',
tags: [],
rsvps: [],
rsvps: []
};

export const eventSlice = createSlice({
Expand Down
2 changes: 1 addition & 1 deletion frontend/mobile/src/store/slices/userSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const initialState: User & UserState = {
name: '',
role: 'student',
following: [],
rsvps: [],
rsvps: []
};

export const userSlice = createSlice({
Expand Down

0 comments on commit afeef67

Please sign in to comment.