From ec5f50aba49712e6cc6d1b0687c9a0b788d20cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Malak?= Date: Thu, 25 Nov 2021 16:54:27 +0100 Subject: [PATCH] Added option to reorder bookmarks --- .../BookmarkCard/BookmarkCard.module.css | 2 +- .../Bookmarks/BookmarkCard/BookmarkCard.tsx | 12 +++++++--- .../Bookmarks/BookmarkGrid/BookmarkGrid.tsx | 22 ++++++++++++++----- client/src/components/Bookmarks/Bookmarks.tsx | 8 ++++++- client/src/components/Home/Home.tsx | 1 + 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css index c61217d..2fd52f0 100644 --- a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css +++ b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css @@ -10,7 +10,7 @@ text-transform: uppercase; } -.BookmarkCard h3:hover { +.BookmarkHeader:hover { cursor: pointer; } diff --git a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx index fe6c97d..8891460 100644 --- a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx +++ b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx @@ -16,9 +16,12 @@ import { iconParser, isImage, isSvg, isUrl, urlParser } from '../../../utility'; interface Props { category: Category; + fromHomepage?: boolean; } export const BookmarkCard = (props: Props): JSX.Element => { + const { category, fromHomepage = false } = props; + const { config } = useSelector((state: State) => state.config); const dispatch = useDispatch(); @@ -27,15 +30,18 @@ export const BookmarkCard = (props: Props): JSX.Element => { return (

{ - setEditCategory(props.category); + if (!fromHomepage) { + setEditCategory(category); + } }} > - {props.category.name} + {category.name}

- {props.category.bookmarks.map((bookmark: Bookmark) => { + {category.bookmarks.map((bookmark: Bookmark) => { const redirectUrl = urlParser(bookmark.url)[1]; let iconEl: JSX.Element = ; diff --git a/client/src/components/Bookmarks/BookmarkGrid/BookmarkGrid.tsx b/client/src/components/Bookmarks/BookmarkGrid/BookmarkGrid.tsx index 01a5ed1..7e26c32 100644 --- a/client/src/components/Bookmarks/BookmarkGrid/BookmarkGrid.tsx +++ b/client/src/components/Bookmarks/BookmarkGrid/BookmarkGrid.tsx @@ -11,27 +11,39 @@ interface Props { categories: Category[]; totalCategories?: number; searching: boolean; + fromHomepage?: boolean; } export const BookmarkGrid = (props: Props): JSX.Element => { + const { + categories, + totalCategories, + searching, + fromHomepage = false, + } = props; + let bookmarks: JSX.Element; - if (props.categories.length) { - if (props.searching && !props.categories[0].bookmarks.length) { + if (categories.length) { + if (searching && !categories[0].bookmarks.length) { bookmarks = No bookmarks match your search criteria; } else { bookmarks = (
- {props.categories.map( + {categories.map( (category: Category): JSX.Element => ( - + ) )}
); } } else { - if (props.totalCategories) { + if (totalCategories) { bookmarks = ( There are no pinned categories. You can pin them from the{' '} diff --git a/client/src/components/Bookmarks/Bookmarks.tsx b/client/src/components/Bookmarks/Bookmarks.tsx index f461d48..5bbe324 100644 --- a/client/src/components/Bookmarks/Bookmarks.tsx +++ b/client/src/components/Bookmarks/Bookmarks.tsx @@ -69,12 +69,17 @@ export const Bookmarks = (props: Props): JSX.Element => { }, [isAuthenticated]); useEffect(() => { - if (categoryInEdit && !showTable) { + if (categoryInEdit) { setTableContentType(ContentType.bookmark); setShowTable(true); } }, [categoryInEdit]); + useEffect(() => { + setShowTable(false); + setEditCategory(null); + }, []); + // Form actions const toggleModal = (): void => { setModalIsOpen(!modalIsOpen); @@ -108,6 +113,7 @@ export const Bookmarks = (props: Props): JSX.Element => { const showTableForEditing = (contentType: ContentType) => { // We're in the edit mode and the same button was clicked - go back to list if (showTable && contentType === tableContentType) { + setEditCategory(null); setShowTable(false); } else { setShowTable(true); diff --git a/client/src/components/Home/Home.tsx b/client/src/components/Home/Home.tsx index d369aaa..e24e5c0 100644 --- a/client/src/components/Home/Home.tsx +++ b/client/src/components/Home/Home.tsx @@ -151,6 +151,7 @@ export const Home = (): JSX.Element => { } totalCategories={categories.length} searching={!!localSearch} + fromHomepage={true} /> )}