Skip to content

Commit

Permalink
New stuff yktv
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed Jun 19, 2024
1 parent b8790d5 commit 1089748
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 60 deletions.
13 changes: 10 additions & 3 deletions frontend/mobile/src/app/app/club/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef } from 'react';
import { useEffect, useRef } from 'react';
import { Dimensions, Linking } from 'react-native';
import Animated, {
interpolate,
Expand All @@ -22,7 +22,8 @@ import {
import { SACColors } from '@/src/app/design-system';
import { Button } from '@/src/app/design-system/components/Button/Button';
import useClub from '@/src/hooks/useClub';
import { useAppSelector } from '@/src/store/store';
import { setClubId } from '@/src/store/slices/clubSlice';
import { useAppDispatch, useAppSelector } from '@/src/store/store';

import { AboutSection } from '../../design-system/components/AboutSection/AboutSection';
import AnimatedImageHeader from '../../design-system/components/AnimatedImageHeader/AnimatedImageHeader';
Expand All @@ -46,7 +47,13 @@ const ClubPage = () => {
const bottomSheet = useRef<BottomSheet>(null);

const club = useAppSelector((state) => state.club);
const { setRetriggerFetch, apiLoading, apiError } = useClub(id as string);
const dispatch = useAppDispatch();
const { setRetriggerFetch, apiLoading, apiError } = useClub();

useEffect(() => {
dispatch(setClubId(id));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const headerAnimatedStyle = useAnimatedStyle(() => {
return {
Expand Down
13 changes: 10 additions & 3 deletions frontend/mobile/src/app/app/event/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef } from 'react';
import { useEffect, useRef } from 'react';
import { Dimensions } from 'react-native';
import Animated, {
interpolate,
Expand All @@ -17,7 +17,8 @@ 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 { useAppSelector } from '@/src/store/store';
import { setEventId } from '@/src/store/slices/eventSlice';
import { useAppDispatch, useAppSelector } from '@/src/store/store';

import AnimatedImageHeader from '../../design-system/components/AnimatedImageHeader/AnimatedImageHeader';
import PageError from '../../design-system/components/PageError/PageError';
Expand Down Expand Up @@ -58,12 +59,18 @@ const EventPage = () => {
const scrollRef = useAnimatedRef<Animated.ScrollView>();
const scrollOffset = useScrollViewOffset(scrollRef);

const dispatch = useAppDispatch();
const event = useAppSelector((state) => state.event);
const { name: clubName, logo: clubLogo } = useAppSelector(
(state) => state.club
);

const { setRetriggerFetch, apiLoading, apiError } = useEvent(id as string);
const { setRetriggerFetch, apiLoading, apiError } = useEvent();

useEffect(() => {
dispatch(setEventId(id));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const headerAnimatedStyle = useAnimatedStyle(() => {
return {
Expand Down
27 changes: 10 additions & 17 deletions frontend/mobile/src/hooks/useClub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { clubApi } from '@generatesac/lib';
import { setClub, setClubEvents, setClubTags } from '../store/slices/clubSlice';
import { useAppDispatch, useAppSelector } from '../store/store';

const useClub = (id: string) => {
const useClub = () => {
const [retriggerFetch, setRetriggerFetch] = useState(false);

const [getClub, { isLoading: clubLoading, error: clubError }] =
Expand All @@ -16,26 +16,27 @@ const useClub = (id: string) => {
clubApi.useLazyClubEventsQuery();

const dispatch = useAppDispatch();
const { shouldPreview, id: clubId } = useAppSelector((state) => state.club);
const { id: clubId } = useAppSelector((state) => state.club);

const apiLoading = clubLoading || tagsLoading || eventsLoading;
const apiError = clubError || tagsError || eventsError;

useEffect(() => {
if ((id !== '' && (id !== clubId || shouldPreview)) || apiError) {
getClub(id).then(({ data: clubData }) => {
if (clubId !== '') {
getClub(clubId).then(({ data: clubData }) => {
if (clubData) {
console.log(clubData);
dispatch(setClub(clubData));
}
});

getClubTags(id).then(({ data: tagData }) => {
getClubTags(clubId).then(({ data: tagData }) => {
if (tagData) {
dispatch(setClubTags(tagData));
}
});

getEvents({ id }).then(({ data: eventData }) => {
getEvents({ id: clubId }).then(({ data: eventData }) => {
if (eventData) {
const sortedEvents = [...eventData];
sortedEvents.sort((a, b) => {
Expand All @@ -49,21 +50,13 @@ const useClub = (id: string) => {
new Date(event.end_time).getTime() >
new Date().getTime()
);
console.log('events', events);
dispatch(setClubEvents(events));
}
});
}
}, [
retriggerFetch,
id,
getClub,
getClubTags,
getEvents,
dispatch,
clubId,
apiError,
shouldPreview
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [retriggerFetch, clubId]);

return {
setRetriggerFetch,
Expand Down
46 changes: 13 additions & 33 deletions frontend/mobile/src/hooks/useEvent.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,43 @@
import { useEffect, useState } from 'react';

import { clubApi, eventApi } from '@generatesac/lib';
import { eventApi } from '@generatesac/lib';

import { setClub } from '../store/slices/clubSlice';
import { setClubId } from '../store/slices/clubSlice';
import { setEvent, setEventTags } from '../store/slices/eventSlice';
import { useAppDispatch, useAppSelector } from '../store/store';

const useEvent = (id: string) => {
const useEvent = () => {
const [retriggerFetch, setRetriggerFetch] = useState(false);

const [getEvent, { isLoading: eventLoading, error: eventError }] =
eventApi.useLazyEventQuery();
const [getClub, { isLoading: clubLoading, error: clubError }] =
clubApi.useLazyClubQuery();
const [getEventTags, { isLoading: tagsLoading, error: tagsError }] =
eventApi.useLazyEventTagsQuery();

const dispatch = useAppDispatch();
const { shouldPreview, id: eventId } = useAppSelector(
(state) => state.event
);
const { id: eventId } = useAppSelector((state) => state.event);

const apiLoading = eventLoading || clubLoading || tagsLoading;
const apiError = eventError || clubError || tagsError;
const apiLoading = eventLoading || tagsLoading;
const apiError = eventError || tagsError;

useEffect(() => {
if ((id !== '' && (id !== eventId || shouldPreview)) || apiError) {
if (eventId !== '') {
// Fetch events
getEvent(id).then(({ data: eventData }) => {
dispatch(setEvent(eventData));
getEvent(eventId).then(({ data: eventData }) => {
if (eventData) {
// Fetch club
getClub(eventData.host as string).then(
({ data: clubData }) => {
if (clubData) {
dispatch(setClub(clubData));
}
}
);
dispatch(setEvent(eventData));
dispatch(setClubId(eventData?.host));
}
});

getEventTags(id).then(({ data: tagData }) => {
getEventTags(eventId).then(({ data: tagData }) => {
if (tagData) {
dispatch(setEventTags(tagData));
}
});
}
}, [
retriggerFetch,
id,
getClub,
getEvent,
getEventTags,
dispatch,
eventId,
shouldPreview,
apiError
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [retriggerFetch, eventId]);

return {
setRetriggerFetch,
Expand Down
6 changes: 2 additions & 4 deletions frontend/mobile/src/hooks/usePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const usePreview = () => {
const { shouldPreview: clubShouldPreview, id: clubId } = useAppSelector(
(state) => state.club
);
const { apiLoading: eventApiLoading, apiError: eventApiError } =
useEvent(eventId);
const { apiLoading: clubApiLoading, apiError: clubApiError } =
useClub(clubId);
const { apiLoading: eventApiLoading, apiError: eventApiError } = useEvent();
const { apiLoading: clubApiLoading, apiError: clubApiError } = useClub();

useEffect(() => {
dispatch(setEventShouldPreview(false));
Expand Down

0 comments on commit 1089748

Please sign in to comment.