Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions frontend/components/Bookmark/BookmarkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ export default function BookmarkCard({ bookmark }: Readonly<BookmarkProp>) {
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]);
Expand Down Expand Up @@ -211,7 +214,11 @@ export default function BookmarkCard({ bookmark }: Readonly<BookmarkProp>) {
);
}
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.
Expand All @@ -227,7 +234,10 @@ export default function BookmarkCard({ bookmark }: Readonly<BookmarkProp>) {
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 });
});

Expand Down
1 change: 1 addition & 0 deletions frontend/components/Bookmark/NewBookmarkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions frontend/components/Tags/TagList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -51,6 +58,22 @@ const TagList = () => {
}

let groupItems: any = [];
// adds "untagged" tag to the tag list
if (hasUntaggedBookmark) {
groupItems.push(
<ListGroup.Item key={"untagged-item"} className={`${itemStyle.item}`}>
<button
onClick={(event) => selectTag(event, "untagged")}
className={`d-flex btn ${itemStyle.btn} justify-content-between align-items-start`}
>
untagged
<Badge bg="primary" pill>
{bookmark.fetchedBookmarks.filter((b) => b.tags.length == 0).length}
</Badge>
</button>
</ListGroup.Item>,
);
}
tagMap.forEach((tagCnt) => {
groupItems.push(
<ListGroup.Item
Expand Down