Skip to content

Commit 5314e98

Browse files
committed
Refactor
1 parent ce4d017 commit 5314e98

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/components/ContentCard/ContentCard.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ function ContentCard({
4343
const [storyIsSaved, setStoryIsSaved] = useState(false);
4444
const { channels, initializeChannel, publish } = usePubSub();
4545

46-
const savedStoryImageComponent = useMemo(() => {
47-
return <Image style={{ width: 30, height: 30 }} source={savedStoryImage} />;
48-
}, []);
49-
const saveStoryImageComponent = useMemo(() => {
50-
return <Image style={{ width: 30, height: 30 }} source={saveStoryImage} />;
51-
}, []);
52-
5346
useEffect(() => {
5447
isStoryInReadingList(storyId, user?.id).then(storyInReadingList => {
5548
setStoryIsSaved(storyInReadingList);
@@ -121,9 +114,17 @@ function ContentCard({
121114
</View>
122115
</View>
123116
<TouchableOpacity onPress={() => saveStory(!storyIsSaved)}>
124-
{storyIsSaved
125-
? savedStoryImageComponent
126-
: saveStoryImageComponent}
117+
{storyIsSaved ? (
118+
<Image
119+
style={{ width: 30, height: 30 }}
120+
source={savedStoryImage}
121+
/>
122+
) : (
123+
<Image
124+
style={{ width: 30, height: 30 }}
125+
source={saveStoryImage}
126+
/>
127+
)}
127128
</TouchableOpacity>
128129
</View>
129130
</View>

src/components/PreviewCard/PreviewCard.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ function PreviewCard({
5252
const [storyIsSaved, setStoryIsSaved] = useState(false);
5353
const { channels, initializeChannel, publish } = usePubSub();
5454

55-
const savedStoryImageComponent = useMemo(() => {
56-
return <Image style={{ width: 30, height: 30 }} source={savedStoryImage} />;
57-
}, []);
58-
const saveStoryImageComponent = useMemo(() => {
59-
return <Image style={{ width: 30, height: 30 }} source={saveStoryImage} />;
60-
}, []);
61-
6255
useEffect(() => {
6356
isStoryInReadingList(storyId, user?.id).then(storyInReadingList => {
6457
setStoryIsSaved(storyInReadingList);
@@ -81,7 +74,8 @@ function PreviewCard({
8174

8275
const saveStory = async (saved: boolean) => {
8376
setStoryIsSaved(saved);
84-
publish(storyId, saved);
77+
publish(storyId, saved); // update other cards with this story
78+
8579
if (saved) {
8680
await addUserStoryToReadingList(user?.id, storyId);
8781
} else {
@@ -97,7 +91,17 @@ function PreviewCard({
9791
{title}
9892
</Text>
9993
<TouchableOpacity onPress={() => saveStory(!storyIsSaved)}>
100-
{storyIsSaved ? savedStoryImageComponent : saveStoryImageComponent}
94+
{storyIsSaved ? (
95+
<Image
96+
style={{ width: 30, height: 30 }}
97+
source={savedStoryImage}
98+
/>
99+
) : (
100+
<Image
101+
style={{ width: 30, height: 30 }}
102+
source={saveStoryImage}
103+
/>
104+
)}
101105
</TouchableOpacity>
102106
</View>
103107
<View style={styles.body}>

0 commit comments

Comments
 (0)