Skip to content

Commit

Permalink
Add default state to saved story button
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapawar1 committed Apr 18, 2024
1 parent 92be7d0 commit ace4f89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app/(tabs)/library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function LibraryScreen() {
</View>
</View>

<View style={{ width: "100%" }}>
<View style={{ width: "100%", flex: 1, marginBottom: 100 }}>
{favoritesSelected &&
<FlatList
data={favoriteStories}
Expand Down Expand Up @@ -122,6 +122,7 @@ function LibraryScreen() {
<PreviewCard
key={item.title}
storyId={item.id}
defaultSavedStoriesState={true}
title={item.title}
image={item.featured_media}
author={item.author_name}
Expand Down
4 changes: 3 additions & 1 deletion src/components/PreviewCard/PreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type PreviewCardProps = {
storyId: number;
author: string;
authorImage: string;
defaultSavedStoriesState?: boolean
excerpt: { html: string };
tags: string[];
pressFunction: (event: GestureResponderEvent) => void;
Expand All @@ -35,6 +36,7 @@ function PreviewCard({
authorImage,
excerpt,
tags,
defaultSavedStoriesState = false,
pressFunction,
}: PreviewCardProps) {
return (
Expand All @@ -46,7 +48,7 @@ function PreviewCard({
</Text>
<TouchableOpacity style={{ alignSelf: 'flex-end' }}>
<View>
<SaveStoryButton storyId={storyId} />
<SaveStoryButton storyId={storyId} defaultState={defaultSavedStoriesState} />
</View>
</TouchableOpacity>
</View>
Expand Down
5 changes: 3 additions & 2 deletions src/components/SaveStoryButton/SaveStoryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { TouchableOpacity } from 'react-native-gesture-handler';

type SaveStoryButtonProps = {
storyId: number;
defaultState?: boolean
};

const saveStoryImage = require('../../../assets/save_story.png');
const savedStoryImage = require('../../../assets/saved_story.png');

export default function SaveStoryButton({ storyId }: SaveStoryButtonProps) {
export default function SaveStoryButton({ storyId, defaultState = false }: SaveStoryButtonProps) {
const { user } = useSession();
const [storyIsSaved, setStoryIsSaved] = useState(false);
const [storyIsSaved, setStoryIsSaved] = useState(defaultState);
const { channels, initializeChannel, publish } = usePubSub();

useEffect(() => {
Expand Down

0 comments on commit ace4f89

Please sign in to comment.