From dece1c5ff2bf78b3dd0021dc0d65a4d92d398c7e Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 19 Mar 2022 20:33:00 +0530 Subject: [PATCH] update detected words ui --- .../MachineLearning/TextDetection.tsx | 23 ---------- src/components/MachineLearning/WordList.tsx | 44 +++++++++++++++++++ src/components/PhotoSwipe/PhotoSwipe.tsx | 16 +++---- 3 files changed, 52 insertions(+), 31 deletions(-) delete mode 100644 src/components/MachineLearning/TextDetection.tsx create mode 100644 src/components/MachineLearning/WordList.tsx diff --git a/src/components/MachineLearning/TextDetection.tsx b/src/components/MachineLearning/TextDetection.tsx deleted file mode 100644 index 16f2ec7e3..000000000 --- a/src/components/MachineLearning/TextDetection.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { CodeBlock } from 'components/CodeBlock'; -import React, { useState, useEffect } from 'react'; -import { EnteFile } from 'types/file'; -import mlIDbStorage from 'utils/storage/mlIDbStorage'; - -export function TextDetection(props: { file: EnteFile }) { - const [text, setText] = useState(null); - useEffect(() => { - let didCancel = false; - const main = async () => { - const text = await mlIDbStorage.getAllTextMap(); - const detectedWords = text.get(props.file.id)?.detection.data.text; - - !didCancel && setText(detectedWords); - }; - main(); - return () => { - didCancel = true; - }; - }, [props.file]); - - return ; -} diff --git a/src/components/MachineLearning/WordList.tsx b/src/components/MachineLearning/WordList.tsx new file mode 100644 index 000000000..119be3f8c --- /dev/null +++ b/src/components/MachineLearning/WordList.tsx @@ -0,0 +1,44 @@ +import { Chip } from 'components/pages/gallery/Collections'; +import React, { useState, useEffect } from 'react'; +import { EnteFile } from 'types/file'; +import mlIDbStorage from 'utils/storage/mlIDbStorage'; + +export function WordList(props: { file: EnteFile }) { + const [words, setWords] = useState([]); + useEffect(() => { + let didCancel = false; + const main = async () => { + const texts = await mlIDbStorage.getAllTextMap(); + const uniqueDetectedWords = [ + ...new Set( + (texts.get(props.file.id) ?? []).map( + (text) => text.detection.word + ) + ), + ]; + + !didCancel && setWords(uniqueDetectedWords); + }; + main(); + return () => { + didCancel = true; + }; + }, [props.file]); + + return ( +
+ {words.map((object) => ( + + {object} + + ))} +
+ ); +} diff --git a/src/components/PhotoSwipe/PhotoSwipe.tsx b/src/components/PhotoSwipe/PhotoSwipe.tsx index 743dc5c76..d3e97d9f2 100644 --- a/src/components/PhotoSwipe/PhotoSwipe.tsx +++ b/src/components/PhotoSwipe/PhotoSwipe.tsx @@ -53,7 +53,7 @@ import { sleep } from 'utils/common'; import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery'; import { GalleryContext } from 'pages/gallery'; import { ObjectLabelList } from 'components/MachineLearning/ObjectList'; -import { TextDetection } from 'components/MachineLearning/TextDetection'; +import { WordList } from 'components/MachineLearning/WordList'; const SmallLoadingSpinner = () => (
{constants.TEXT} -
@@ -543,12 +543,12 @@ function PhotoSwipe(props: Iprops) { updateItems(items); }, [items]); - useEffect(() => { - if (photoSwipe) { - photoSwipe.options.arrowKeys = !showInfo; - photoSwipe.options.escKey = !showInfo; - } - }, [showInfo]); + // useEffect(() => { + // if (photoSwipe) { + // photoSwipe.options.arrowKeys = !showInfo; + // photoSwipe.options.escKey = !showInfo; + // } + // }, [showInfo]); function updateFavButton() { setIsFav(isInFav(this?.currItem));