diff --git a/frontend/components/Bookmark/BookmarkCard.tsx b/frontend/components/Bookmark/BookmarkCard.tsx index ac167cdd..998cb7f1 100644 --- a/frontend/components/Bookmark/BookmarkCard.tsx +++ b/frontend/components/Bookmark/BookmarkCard.tsx @@ -136,9 +136,12 @@ export default function BookmarkCard({ bookmark }: Readonly) { useEffect(() => { if (bookmark) { const tagList: string[] = []; - bookmark.tags.forEach((tag: Tag) => { - tagList.push(tag.title); - }); + if (bookmark.tags.length == 0) tagList.push("untagged"); + else { + bookmark.tags.forEach((tag: Tag) => { + tagList.push(tag.title); + }); + } setStrTags(tagList); } }, [bookmark]); @@ -211,7 +214,11 @@ export default function BookmarkCard({ bookmark }: Readonly) { ); } api.deleteTagById(bookmark.id, tagId); - let titles = currentBookmark.current.tags.map((t) => t.title); // just the titles display + // if there are no tags to display, display "untagged", else display the tags for the bookmark + let titles = + currentBookmark.current.tags.length !== 0 + ? currentBookmark.current.tags.map((t) => t.title) + : ["untagged"]; // just the titles display setStrTags(titles); // update the sidebar. @@ -227,7 +234,10 @@ export default function BookmarkCard({ bookmark }: Readonly) { const onPushTag = (tag: string) => addTagToBookmark(bookmark, tag).then((action) => { dispatch(action); - setStrTags([...strTags, tag]); + setStrTags((prev) => { + const cleaned = prev.filter((t) => t != "untagged"); + return [...cleaned, tag]; + }); currentBookmark.current.tags.push({ id: action.id, title: action.title }); }); diff --git a/frontend/components/Bookmark/NewBookmarkCard.tsx b/frontend/components/Bookmark/NewBookmarkCard.tsx index 024094f6..228ff5d3 100644 --- a/frontend/components/Bookmark/NewBookmarkCard.tsx +++ b/frontend/components/Bookmark/NewBookmarkCard.tsx @@ -112,6 +112,7 @@ export default function NewBookmarkCard() { // FIXME tags.push({ title: tagInput, id: -1 }); } + let newBkmk: Bookmark = { id: -1, title: submittedBmk.title || submittedBmk.url, diff --git a/frontend/components/Tags/TagList.tsx b/frontend/components/Tags/TagList.tsx index 48ebb851..2888b042 100644 --- a/frontend/components/Tags/TagList.tsx +++ b/frontend/components/Tags/TagList.tsx @@ -9,12 +9,19 @@ import itemStyle from "./tag-list-item.module.scss"; import menuStyle from "styles/tag.module.scss"; import { useSelectedTags } from "@/contexts/SelectedContext"; import { useScreenSize } from "@/contexts/ScreenSizeContext"; +import { useBookmarks } from "@/contexts/BookmarkContext"; // import bookmarks for the "untagged" tag + const TagList = () => { const userAuth = useAuth(); const tagMap = useTags(); const [loading, setLoading] = useState(false); const { selected, setSelected } = useSelectedTags(); const isPC = useScreenSize(); + const bookmark = useBookmarks(); + // check if at least one bookmark has no tags + const hasUntaggedBookmark = bookmark.fetchedBookmarks.some( + (t) => t.tags.length === 0, + ); useEffect(() => { if (userAuth && tagMap.size == 0) { setLoading(true); @@ -51,6 +58,22 @@ const TagList = () => { } let groupItems: any = []; + // adds "untagged" tag to the tag list + if (hasUntaggedBookmark) { + groupItems.push( + + + , + ); + } tagMap.forEach((tagCnt) => { groupItems.push(