diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index cf83ba51f..23493f1b9 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -19,7 +19,7 @@ import { VariableSizeList as List } from 'react-window'; import Collections from './components/Collections'; import SadFace from 'components/SadFace'; import Upload from './components/Upload'; -import { collection, fetchCollections, collectionLatestFile, getCollectionLatestFile } from 'services/collectionService'; +import { collection, fetchCollections, collectionLatestFile, getCollectionLatestFile, getFavItemIds } from 'services/collectionService'; enum ITEM_TYPE { TIME = 'TIME', @@ -100,6 +100,7 @@ export default function Gallery(props) { collectionLatestFile[] >([]); const [data, setData] = useState(); + const [favItemIds, setFavItemIds] = useState>(); const [open, setOpen] = useState(false); const [options, setOptions] = useState({ history: false, @@ -120,11 +121,13 @@ export default function Gallery(props) { const encryptionKey = await getActualKey(); const collections = await fetchCollections(token, encryptionKey); const data = await fetchData(token, collections); - setLoading(false); + const collectionLatestFile = await getCollectionLatestFile(collections, token); + const favItemIds = await getFavItemIds(data); setCollections(collections); setData(data); - const collectionLatestFile = await getCollectionLatestFile(collections, token); setCollectionLatestFile(collectionLatestFile); + setFavItemIds(favItemIds); + setLoading(false); }; main(); props.setUploadButtonView(true); @@ -395,6 +398,8 @@ export default function Gallery(props) { options={options} onClose={handleClose} gettingData={getSlideData} + favItemIds={favItemIds} + setFavItemIds={setFavItemIds} /> ) : ( diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 238c3014a..ceceab254 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -114,6 +114,15 @@ export const getCollectionLatestFile = async ( })) }; +export const getFavItemIds = async (files: file[]): Promise> => { + + let favCollection: collection = (await localForage.getItem('fav-collection'))[0]; + if (!favCollection) + return new Set(); + + return new Set(files.filter(file => file.collectionID === Number(favCollection.id)).map((file): number => file.id)); +} + export const createAlbum = async (albumName: string) => { return AddCollection(albumName, CollectionType.album); } @@ -178,4 +187,4 @@ const addtoCollection = async (collection: collection, files: file[]) => { })); await HTTPService.post(`${ENDPOINT}/collections/add-files`, params, { token }); -} \ No newline at end of file +}