From 75a370cc06ded9215384e2e6a17aa2feb665a7b3 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Wed, 24 Jul 2024 18:00:33 +0530 Subject: [PATCH] Implement focus mode to click into full text of the note --- src/interface/web/app/search/page.tsx | 65 ++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/src/interface/web/app/search/page.tsx b/src/interface/web/app/search/page.tsx index 30be4f5d..6b85c0d3 100644 --- a/src/interface/web/app/search/page.tsx +++ b/src/interface/web/app/search/page.tsx @@ -9,7 +9,8 @@ import NavMenu from '../components/navMenu/navMenu'; import styles from './search.module.css'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; -import { Folder, FolderOpen, GithubLogo, LinkSimple, MagnifyingGlass, NoteBlank, NotionLogo } from '@phosphor-icons/react'; +import { ArrowLeft, ArrowRight, Folder, FolderOpen, GithubLogo, LinkSimple, MagnifyingGlass, NoteBlank, NotionLogo } from '@phosphor-icons/react'; +import { Button } from '@/components/ui/button'; interface AdditionalData { file: string; @@ -36,16 +37,21 @@ function getNoteTypeIcon(source: string) { return ; } -function Note(note: SearchResult) { +interface NoteResultProps { + note: SearchResult; + setFocusSearchResult: (note: SearchResult) => void; +} + +function Note(props: NoteResultProps) { + const note = props.note; const isFileNameURL = (note.additional.file || '').startsWith('http'); const fileName = isFileNameURL ? note.additional.heading : note.additional.file.split('/').pop(); - console.log("note.additional.file", note.additional.file); - console.log("filename", fileName); + return ( -
+
{getNoteTypeIcon(note.additional.source)}
@@ -57,6 +63,7 @@ function Note(note: SearchResult) {
{note.entry}
+ { @@ -72,7 +79,38 @@ function Note(note: SearchResult) { ); +} +function focusNote(note: SearchResult) { + const isFileNameURL = (note.additional.file || '').startsWith('http'); + const fileName = isFileNameURL ? note.additional.heading : note.additional.file.split('/').pop(); + return ( + + + + {fileName} + + + { + isFileNameURL ? + + {note.additional.file} + + : +
+ {note.additional.file} +
+ } +
+ +
+ +
+ {note.entry} +
+
+
+ ); } export default function Search() { @@ -82,6 +120,7 @@ export default function Search() { const [title, setTitle] = useState('Search'); const [searchResults, setSearchResults] = useState([]); const [searchResultsLoading, setSearchResultsLoading] = useState(false); + const [focusSearchResult, setFocusSearchResult] = useState(null); useEffect(() => { setIsMobileWidth(window.innerWidth < 786); @@ -150,13 +189,25 @@ export default function Search() {
{ - searchResults.length > 0 && + focusSearchResult && +
+ + {focusNote(focusSearchResult)} +
+ } + { + !focusSearchResult && searchResults.length > 0 &&
{ searchResults.map((result, index) => { return ( - + ); }) }