Skip to content

Commit ce4d017

Browse files
committed
Bug fixes
1 parent 47b3c11 commit ce4d017

File tree

5 files changed

+34
-58
lines changed

5 files changed

+34
-58
lines changed

src/components/ContentCard/ContentCard.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,22 @@ function ContentCard({
4444
const { channels, initializeChannel, publish } = usePubSub();
4545

4646
const savedStoryImageComponent = useMemo(() => {
47-
return (
48-
<Image
49-
style={{ width: 30, height: 30 }}
50-
source={savedStoryImage}
51-
/>
52-
)
53-
}, [])
47+
return <Image style={{ width: 30, height: 30 }} source={savedStoryImage} />;
48+
}, []);
5449
const saveStoryImageComponent = useMemo(() => {
55-
return (
56-
<Image
57-
style={{ width: 30, height: 30 }}
58-
source={saveStoryImage}
59-
/>
60-
)
61-
}, [])
50+
return <Image style={{ width: 30, height: 30 }} source={saveStoryImage} />;
51+
}, []);
6252

6353
useEffect(() => {
6454
isStoryInReadingList(storyId, user?.id).then(storyInReadingList => {
65-
setStoryIsSaved(storyInReadingList)
55+
setStoryIsSaved(storyInReadingList);
6656
initializeChannel(storyId);
6757
});
6858
}, [storyId]);
6959

7060
useEffect(() => {
7161
// if another card updates this story, update it here also
72-
if (typeof channels[storyId] !== "undefined") {
62+
if (typeof channels[storyId] !== 'undefined') {
7363
setStoryIsSaved(channels[storyId]);
7464
}
7565
}, [channels[storyId]]);
@@ -131,9 +121,9 @@ function ContentCard({
131121
</View>
132122
</View>
133123
<TouchableOpacity onPress={() => saveStory(!storyIsSaved)}>
134-
{storyIsSaved ?
135-
savedStoryImageComponent : saveStoryImageComponent
136-
}
124+
{storyIsSaved
125+
? savedStoryImageComponent
126+
: saveStoryImageComponent}
137127
</TouchableOpacity>
138128
</View>
139129
</View>

src/components/PreviewCard/PreviewCard.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,26 @@ function PreviewCard({
5353
const { channels, initializeChannel, publish } = usePubSub();
5454

5555
const savedStoryImageComponent = useMemo(() => {
56-
return (
57-
<Image
58-
style={{ width: 30, height: 30 }}
59-
source={savedStoryImage}
60-
/>
61-
)
62-
}, [])
56+
return <Image style={{ width: 30, height: 30 }} source={savedStoryImage} />;
57+
}, []);
6358
const saveStoryImageComponent = useMemo(() => {
64-
return (
65-
<Image
66-
style={{ width: 30, height: 30 }}
67-
source={saveStoryImage}
68-
/>
69-
)
70-
}, [])
59+
return <Image style={{ width: 30, height: 30 }} source={saveStoryImage} />;
60+
}, []);
7161

7262
useEffect(() => {
7363
isStoryInReadingList(storyId, user?.id).then(storyInReadingList => {
74-
setStoryIsSaved(storyInReadingList)
64+
setStoryIsSaved(storyInReadingList);
7565
initializeChannel(storyId);
7666
});
7767
}, [storyId]);
7868

7969
useEffect(() => {
8070
// if another card updates this story, update it here also
81-
if (typeof channels[storyId] !== "undefined") {
82-
setStoryIsSaved(channels[storyId])
71+
if (typeof channels[storyId] !== 'undefined') {
72+
setStoryIsSaved(channels[storyId]);
8373
}
8474
}, [channels[storyId]]);
8575

86-
8776
useEffect(() => {
8877
isStoryInReadingList(storyId, user?.id).then(storyInReadingList =>
8978
setStoryIsSaved(storyInReadingList),
@@ -108,9 +97,7 @@ function PreviewCard({
10897
{title}
10998
</Text>
11099
<TouchableOpacity onPress={() => saveStory(!storyIsSaved)}>
111-
{storyIsSaved ?
112-
savedStoryImageComponent : saveStoryImageComponent
113-
}
100+
{storyIsSaved ? savedStoryImageComponent : saveStoryImageComponent}
114101
</TouchableOpacity>
115102
</View>
116103
<View style={styles.body}>

src/queries/savedStories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ async function addUserStory(
7070
if (error) {
7171
if (process.env.NODE_ENV !== 'production') {
7272
throw new Error(
73-
`An error occured when trying to set user saved stories: ${JSON.stringify(error)}`,
73+
`An error occured when trying to set user saved stories: ${JSON.stringify(
74+
error,
75+
)}`,
7476
);
7577
}
7678
}

src/utils/AuthContext.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export interface AuthState {
3131
resendVerification: (email: string) => Promise<AuthResponse>;
3232
resetPassword: (email: string) => Promise<
3333
| {
34-
data: object;
35-
error: null;
36-
}
34+
data: object;
35+
error: null;
36+
}
3737
| {
38-
data: null;
39-
error: AuthError;
40-
}
38+
data: null;
39+
error: AuthError;
40+
}
4141
>;
4242
updateUser: (attributes: UserAttributes) => Promise<UserResponse>;
4343
signOut: () => Promise<void>;

src/utils/PubSubContext.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import React, {
2-
createContext,
3-
useContext,
4-
useMemo,
5-
useState,
6-
} from 'react';
1+
import React, { createContext, useContext, useMemo, useState } from 'react';
72

83
export interface PubSubState {
94
channels: Record<number, boolean>;
@@ -31,17 +26,19 @@ export function BooleanPubSubProvider({
3126
}: {
3227
children: React.ReactNode;
3328
}) {
34-
const [channels, setChannels] = useState<Record<number, boolean | undefined>>({})
29+
const [channels, setChannels] = useState<Record<number, boolean | undefined>>(
30+
{},
31+
);
3532

3633
const initializeChannel = (id: number) => {
3734
if (!(id in channels)) {
38-
setChannels({ ...channels, [id]: undefined })
35+
setChannels({ ...channels, [id]: undefined });
3936
}
40-
}
37+
};
4138

4239
const publish = (id: number, message: boolean) => {
43-
setChannels({ ...channels, [id]: message })
44-
}
40+
setChannels({ ...channels, [id]: message });
41+
};
4542

4643
const authContextValue = useMemo(
4744
() => ({

0 commit comments

Comments
 (0)