From b09f8344e6253bcb41071d168a80ad77a14a9015 Mon Sep 17 00:00:00 2001 From: jjstnlee Date: Sun, 21 Apr 2024 16:25:27 -0700 Subject: [PATCH] Added favorite button and updated styling --- assets/save_story.png | Bin 1052 -> 0 bytes assets/saved_story.png | Bin 12911 -> 0 bytes package-lock.json | 22 ++++++ package.json | 5 +- src/app/(tabs)/story/index.tsx | 31 +++++---- src/app/(tabs)/story/styles.ts | 6 ++ .../FavoriteStoryButton.tsx | 63 ++++++++++++++++++ .../SaveStoryButton/SaveStoryButton.tsx | 24 ++++--- src/queries/savedStories.tsx | 24 ++++++- 9 files changed, 149 insertions(+), 26 deletions(-) delete mode 100644 assets/save_story.png delete mode 100644 assets/saved_story.png create mode 100644 src/components/FavoriteStoryButton/FavoriteStoryButton.tsx diff --git a/assets/save_story.png b/assets/save_story.png deleted file mode 100644 index 65b2ea6e4dd47e1c590ef1cbe5d7afc29d8fcca7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1052 zcmV+%1mpXOP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91JfH&r1ONa40RR91JOBUy0E^%0TmS$AhDk(0RA>e5n@@7uFciimr$e`7 zhCjm&P7v1VhMpkVWYbNP6Eryi^aM>$(8;zeN=^{ENH^V(6Qo@wfn;E^B&pr+b1h;E2p>P%^ zpbQq?-QDePZEbx)!+h{wlCB94d0Rp7Dd53i@ClWUJ+Q82S)K8Cd|s(k*x2~g@AvBv zl1CH3Rpd;qVzKz~->L8O;o+ePUuKrbW`fVi zqM-RzouJ&`-(P#ciMQ+o$~yrUE$teUld(|NMSdNuoR(_(yQfn;M+^dj^sVI7We(n$i%k7S&sd<5^duoYdS(=jKw9*6>g(U-yqNOC) z$t;{?>qU`$<1GA2r@nU*mXIMN=))V14f=4r*LT@(7=xLG;_HeuMsDMM!AIJIj+ z-`aK91W&7fuzLz$U`I&ND}KE^SwwMKU=uto54IuPy_r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O+d75q1_hu~@ARX&0WA8rnd##d%06 z%Leppj)hV|g0LT=4pKD7s4*&dn#R?6-Q-zsG~Qe#R|``jyyv?Drx!w-=)1qW#ZZXD zCcsk2p`oFrag(`I(gzGqhi?1eRbr#gZ!6S8#5xD(K@G=4wd)d$Zb@{}MCqNcA{j%K z{dg`r);IAVty^|ffp$b$+mhGnyo8dH&{+`Ei_;?+_Y8)xyn#{7`x#_AaO&LSg-&p; zBkS0tTd5>EgG2w);zQ{FU5ReOi)xL5hny%vYWU?`%l3OrJ{cp~vAN)x2!Z`}`@S_;3+4Fq3{$@rwIi=%Q zORk-}BSzO?%za=|3dmZ*b!TT9=2FSu z98Cx^nceX6)tgyl0*n0EM(~U`=jbCBu)zl_QZrr&Q-{N--|D{1aa{Ub3}VjuDeYG@ zNO9?UlsPs1*p-Q_;Wu})?F`+omy;VX`SH0Dr>4#$?zOmz^LoJdQ7S29wrk6j>cLqV zwJ@6n=Q9s-CeJx*U+FsQ>@UadhungYzc5!j3_9%9y)wqD!&8KHsV~bMNt{<6J|!ha1xm9WwmiTc2OZisON_R<{#@Y%E^i#S zv++}x?Fztkp1<={h{i>M2ELF8fvtxY!3}De_w6%ekjxB@qv_ShjA(TU#l6* zHQt3P%LApH^PITq<)P)4%6_hwP%X83cjzwj=$s7+Od&C)B{uTUb zBbcDbouE%~w@UVkH3*!;QddK0cQhU#QMT0-0fj=Y>IAChI JufUi@{VzM@4g>%I diff --git a/package-lock.json b/package-lock.json index 68298471..32f7ac9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,6 +69,7 @@ }, "devDependencies": { "@babel/core": "^7.20.0", + "@iconify/react": "^4.1.1", "@types/react": "~18.2.14", "@types/react-native": "^0.72.3", "@types/react-native-htmlview": "^0.16.1", @@ -3714,6 +3715,27 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, + "node_modules/@iconify/react": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@iconify/react/-/react-4.1.1.tgz", + "integrity": "sha512-jed14EjvKjee8mc0eoscGxlg7mSQRkwQG3iX3cPBCO7UlOjz0DtlvTqxqEcHUJGh+z1VJ31Yhu5B9PxfO0zbdg==", + "dev": true, + "dependencies": { + "@iconify/types": "^2.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/cyberalien" + }, + "peerDependencies": { + "react": ">=16" + } + }, + "node_modules/@iconify/types": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz", + "integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==", + "dev": true + }, "node_modules/@jest/create-cache-key-function": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz", diff --git a/package.json b/package.json index d15d3b50..78b6c810 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "expo": "~49.0.11", "expo-constants": "~14.4.2", "expo-font": "~11.4.0", + "expo-image": "~1.3.5", "expo-linking": "~5.0.2", "expo-router": "^2.0.0", "expo-status-bar": "~1.6.0", @@ -68,11 +69,11 @@ "react-native-vector-icons": "^10.0.2", "react-scroll-to-top": "^3.0.0", "use-debounce": "^10.0.0", - "validator": "^13.11.0", - "expo-image": "~1.3.5" + "validator": "^13.11.0" }, "devDependencies": { "@babel/core": "^7.20.0", + "@iconify/react": "^4.1.1", "@types/react": "~18.2.14", "@types/react-native": "^0.72.3", "@types/react-native-htmlview": "^0.16.1", diff --git a/src/app/(tabs)/story/index.tsx b/src/app/(tabs)/story/index.tsx index 2995426d..d630daa2 100644 --- a/src/app/(tabs)/story/index.tsx +++ b/src/app/(tabs)/story/index.tsx @@ -16,6 +16,8 @@ import { RenderHTML } from 'react-native-render-html'; import { SafeAreaView } from 'react-native-safe-area-context'; import styles from './styles'; +import FavoriteStoryButton from '../../../components/FavoriteStoryButton/FavoriteStoryButton'; +import SaveStoryButton from '../../../components/SaveStoryButton/SaveStoryButton'; import { fetchStory } from '../../../queries/stories'; import { Story } from '../../../queries/types'; import colors from '../../../styles/colors'; @@ -113,20 +115,23 @@ function StoryScreen() { )} /> - - + + Share Story + + + { + isStoryInFavorites(storyId, user?.id).then(storyInReadingList => { + setStoryIsFavorited(storyInReadingList); + }); + }, [storyId]); + + useEffect(() => { + isStoryInFavorites(storyId, user?.id).then(storyInReadingList => + setStoryIsFavorited(storyInReadingList), + ); + }, [storyId]); + + const favoriteStory = async (favorited: boolean) => { + setStoryIsFavorited(favorited); + + if (favorited) { + await addUserStoryToFavorites(user?.id, storyId); + } else { + await deleteUserStoryToFavorites(user?.id, storyId); + } + }; + + return ( + favoriteStory(!storyIsFavorited)}> + {storyIsFavorited ? ( + + + + ) : ( + + + + )} + + ); +} diff --git a/src/components/SaveStoryButton/SaveStoryButton.tsx b/src/components/SaveStoryButton/SaveStoryButton.tsx index c4d43315..cf1f3a04 100644 --- a/src/components/SaveStoryButton/SaveStoryButton.tsx +++ b/src/components/SaveStoryButton/SaveStoryButton.tsx @@ -1,21 +1,19 @@ import { useEffect, useState } from 'react'; +import { TouchableOpacity } from 'react-native-gesture-handler'; +import Svg, { Path } from 'react-native-svg'; + import { addUserStoryToReadingList, deleteUserStoryToReadingList, isStoryInReadingList, } from '../../queries/savedStories'; -import { usePubSub } from '../../utils/PubSubContext'; import { useSession } from '../../utils/AuthContext'; -import { Image } from 'expo-image'; -import { TouchableOpacity } from 'react-native-gesture-handler'; +import { usePubSub } from '../../utils/PubSubContext'; type SaveStoryButtonProps = { storyId: number; }; -const saveStoryImage = require('../../../assets/save_story.png'); -const savedStoryImage = require('../../../assets/saved_story.png'); - export default function SaveStoryButton({ storyId }: SaveStoryButtonProps) { const { user } = useSession(); const [storyIsSaved, setStoryIsSaved] = useState(false); @@ -55,9 +53,19 @@ export default function SaveStoryButton({ storyId }: SaveStoryButtonProps) { return ( saveStory(!storyIsSaved)}> {storyIsSaved ? ( - + + + ) : ( - + + + )} ); diff --git a/src/queries/savedStories.tsx b/src/queries/savedStories.tsx index 0416ecb8..605fb44b 100644 --- a/src/queries/savedStories.tsx +++ b/src/queries/savedStories.tsx @@ -26,7 +26,7 @@ async function fetchUserStories( return []; } - let storyData = []; + const storyData = []; for (const storyObject of storyObjects) { const storyId = storyObject['story_id']; const { data, error } = await supabase.rpc('fetch_story', { @@ -64,7 +64,7 @@ async function addUserStory( ) { const { error } = await supabase .from('saved_stories') - .upsert([{ user_id: user_id, story_id: story_id, name: name }]) + .upsert([{ user_id, story_id, name }]) .select(); if (error) { @@ -131,7 +131,7 @@ export async function isStoryInReadingList( storyId: number, userId: string | undefined, ): Promise { - let { data, error } = await supabase.rpc('is_story_saved_for_user', { + const { data, error } = await supabase.rpc('is_story_saved_for_user', { list_name: 'reading list', story_db_id: storyId, user_uuid: userId, @@ -144,3 +144,21 @@ export async function isStoryInReadingList( return data; } + +export async function isStoryInFavorites( + storyId: number, + userId: string | undefined, +): Promise { + const { data, error } = await supabase.rpc('is_story_saved_for_user', { + list_name: 'favorites', + story_db_id: storyId, + user_uuid: userId, + }); + + if (error) { + console.error(error); + return false; + } + + return data; +}