From ce4d017e1df6ccd909aff67ec599797ba0bb6cf7 Mon Sep 17 00:00:00 2001 From: Aditya Pawar Date: Wed, 17 Apr 2024 17:42:13 -0700 Subject: [PATCH] Bug fixes --- src/components/ContentCard/ContentCard.tsx | 28 +++++++-------------- src/components/PreviewCard/PreviewCard.tsx | 29 ++++++---------------- src/queries/savedStories.tsx | 4 ++- src/utils/AuthContext.tsx | 12 ++++----- src/utils/PubSubContext.tsx | 19 ++++++-------- 5 files changed, 34 insertions(+), 58 deletions(-) diff --git a/src/components/ContentCard/ContentCard.tsx b/src/components/ContentCard/ContentCard.tsx index 034ff6fa..d0930189 100644 --- a/src/components/ContentCard/ContentCard.tsx +++ b/src/components/ContentCard/ContentCard.tsx @@ -44,32 +44,22 @@ function ContentCard({ const { channels, initializeChannel, publish } = usePubSub(); const savedStoryImageComponent = useMemo(() => { - return ( - - ) - }, []) + return ; + }, []); const saveStoryImageComponent = useMemo(() => { - return ( - - ) - }, []) + return ; + }, []); useEffect(() => { isStoryInReadingList(storyId, user?.id).then(storyInReadingList => { - setStoryIsSaved(storyInReadingList) + setStoryIsSaved(storyInReadingList); initializeChannel(storyId); }); }, [storyId]); useEffect(() => { // if another card updates this story, update it here also - if (typeof channels[storyId] !== "undefined") { + if (typeof channels[storyId] !== 'undefined') { setStoryIsSaved(channels[storyId]); } }, [channels[storyId]]); @@ -131,9 +121,9 @@ function ContentCard({ saveStory(!storyIsSaved)}> - {storyIsSaved ? - savedStoryImageComponent : saveStoryImageComponent - } + {storyIsSaved + ? savedStoryImageComponent + : saveStoryImageComponent} diff --git a/src/components/PreviewCard/PreviewCard.tsx b/src/components/PreviewCard/PreviewCard.tsx index fcb7b0b2..d07304d4 100644 --- a/src/components/PreviewCard/PreviewCard.tsx +++ b/src/components/PreviewCard/PreviewCard.tsx @@ -53,37 +53,26 @@ function PreviewCard({ const { channels, initializeChannel, publish } = usePubSub(); const savedStoryImageComponent = useMemo(() => { - return ( - - ) - }, []) + return ; + }, []); const saveStoryImageComponent = useMemo(() => { - return ( - - ) - }, []) + return ; + }, []); useEffect(() => { isStoryInReadingList(storyId, user?.id).then(storyInReadingList => { - setStoryIsSaved(storyInReadingList) + setStoryIsSaved(storyInReadingList); initializeChannel(storyId); }); }, [storyId]); useEffect(() => { // if another card updates this story, update it here also - if (typeof channels[storyId] !== "undefined") { - setStoryIsSaved(channels[storyId]) + if (typeof channels[storyId] !== 'undefined') { + setStoryIsSaved(channels[storyId]); } }, [channels[storyId]]); - useEffect(() => { isStoryInReadingList(storyId, user?.id).then(storyInReadingList => setStoryIsSaved(storyInReadingList), @@ -108,9 +97,7 @@ function PreviewCard({ {title} saveStory(!storyIsSaved)}> - {storyIsSaved ? - savedStoryImageComponent : saveStoryImageComponent - } + {storyIsSaved ? savedStoryImageComponent : saveStoryImageComponent} diff --git a/src/queries/savedStories.tsx b/src/queries/savedStories.tsx index 78c4e53d..0416ecb8 100644 --- a/src/queries/savedStories.tsx +++ b/src/queries/savedStories.tsx @@ -70,7 +70,9 @@ async function addUserStory( if (error) { if (process.env.NODE_ENV !== 'production') { throw new Error( - `An error occured when trying to set user saved stories: ${JSON.stringify(error)}`, + `An error occured when trying to set user saved stories: ${JSON.stringify( + error, + )}`, ); } } diff --git a/src/utils/AuthContext.tsx b/src/utils/AuthContext.tsx index 34d711da..4273a1cb 100644 --- a/src/utils/AuthContext.tsx +++ b/src/utils/AuthContext.tsx @@ -31,13 +31,13 @@ export interface AuthState { resendVerification: (email: string) => Promise; resetPassword: (email: string) => Promise< | { - data: object; - error: null; - } + data: object; + error: null; + } | { - data: null; - error: AuthError; - } + data: null; + error: AuthError; + } >; updateUser: (attributes: UserAttributes) => Promise; signOut: () => Promise; diff --git a/src/utils/PubSubContext.tsx b/src/utils/PubSubContext.tsx index 5bfe68ae..ffc4c1df 100644 --- a/src/utils/PubSubContext.tsx +++ b/src/utils/PubSubContext.tsx @@ -1,9 +1,4 @@ -import React, { - createContext, - useContext, - useMemo, - useState, -} from 'react'; +import React, { createContext, useContext, useMemo, useState } from 'react'; export interface PubSubState { channels: Record; @@ -31,17 +26,19 @@ export function BooleanPubSubProvider({ }: { children: React.ReactNode; }) { - const [channels, setChannels] = useState>({}) + const [channels, setChannels] = useState>( + {}, + ); const initializeChannel = (id: number) => { if (!(id in channels)) { - setChannels({ ...channels, [id]: undefined }) + setChannels({ ...channels, [id]: undefined }); } - } + }; const publish = (id: number, message: boolean) => { - setChannels({ ...channels, [id]: message }) - } + setChannels({ ...channels, [id]: message }); + }; const authContextValue = useMemo( () => ({