1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-23 13:29:35 +02:00

Added option to reorder bookmarks

This commit is contained in:
Paweł Malak 2021-11-25 16:54:27 +01:00
parent a02814aa02
commit ec5f50aba4
5 changed files with 35 additions and 10 deletions

View file

@ -10,7 +10,7 @@
text-transform: uppercase; text-transform: uppercase;
} }
.BookmarkCard h3:hover { .BookmarkHeader:hover {
cursor: pointer; cursor: pointer;
} }

View file

@ -16,9 +16,12 @@ import { iconParser, isImage, isSvg, isUrl, urlParser } from '../../../utility';
interface Props { interface Props {
category: Category; category: Category;
fromHomepage?: boolean;
} }
export const BookmarkCard = (props: Props): JSX.Element => { export const BookmarkCard = (props: Props): JSX.Element => {
const { category, fromHomepage = false } = props;
const { config } = useSelector((state: State) => state.config); const { config } = useSelector((state: State) => state.config);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -27,15 +30,18 @@ export const BookmarkCard = (props: Props): JSX.Element => {
return ( return (
<div className={classes.BookmarkCard}> <div className={classes.BookmarkCard}>
<h3 <h3
className={fromHomepage ? '' : classes.BookmarkHeader}
onClick={() => { onClick={() => {
setEditCategory(props.category); if (!fromHomepage) {
setEditCategory(category);
}
}} }}
> >
{props.category.name} {category.name}
</h3> </h3>
<div className={classes.Bookmarks}> <div className={classes.Bookmarks}>
{props.category.bookmarks.map((bookmark: Bookmark) => { {category.bookmarks.map((bookmark: Bookmark) => {
const redirectUrl = urlParser(bookmark.url)[1]; const redirectUrl = urlParser(bookmark.url)[1];
let iconEl: JSX.Element = <Fragment></Fragment>; let iconEl: JSX.Element = <Fragment></Fragment>;

View file

@ -11,27 +11,39 @@ interface Props {
categories: Category[]; categories: Category[];
totalCategories?: number; totalCategories?: number;
searching: boolean; searching: boolean;
fromHomepage?: boolean;
} }
export const BookmarkGrid = (props: Props): JSX.Element => { export const BookmarkGrid = (props: Props): JSX.Element => {
const {
categories,
totalCategories,
searching,
fromHomepage = false,
} = props;
let bookmarks: JSX.Element; let bookmarks: JSX.Element;
if (props.categories.length) { if (categories.length) {
if (props.searching && !props.categories[0].bookmarks.length) { if (searching && !categories[0].bookmarks.length) {
bookmarks = <Message>No bookmarks match your search criteria</Message>; bookmarks = <Message>No bookmarks match your search criteria</Message>;
} else { } else {
bookmarks = ( bookmarks = (
<div className={classes.BookmarkGrid}> <div className={classes.BookmarkGrid}>
{props.categories.map( {categories.map(
(category: Category): JSX.Element => ( (category: Category): JSX.Element => (
<BookmarkCard category={category} key={category.id} /> <BookmarkCard
category={category}
fromHomepage={fromHomepage}
key={category.id}
/>
) )
)} )}
</div> </div>
); );
} }
} else { } else {
if (props.totalCategories) { if (totalCategories) {
bookmarks = ( bookmarks = (
<Message> <Message>
There are no pinned categories. You can pin them from the{' '} There are no pinned categories. You can pin them from the{' '}

View file

@ -69,12 +69,17 @@ export const Bookmarks = (props: Props): JSX.Element => {
}, [isAuthenticated]); }, [isAuthenticated]);
useEffect(() => { useEffect(() => {
if (categoryInEdit && !showTable) { if (categoryInEdit) {
setTableContentType(ContentType.bookmark); setTableContentType(ContentType.bookmark);
setShowTable(true); setShowTable(true);
} }
}, [categoryInEdit]); }, [categoryInEdit]);
useEffect(() => {
setShowTable(false);
setEditCategory(null);
}, []);
// Form actions // Form actions
const toggleModal = (): void => { const toggleModal = (): void => {
setModalIsOpen(!modalIsOpen); setModalIsOpen(!modalIsOpen);
@ -108,6 +113,7 @@ export const Bookmarks = (props: Props): JSX.Element => {
const showTableForEditing = (contentType: ContentType) => { const showTableForEditing = (contentType: ContentType) => {
// We're in the edit mode and the same button was clicked - go back to list // We're in the edit mode and the same button was clicked - go back to list
if (showTable && contentType === tableContentType) { if (showTable && contentType === tableContentType) {
setEditCategory(null);
setShowTable(false); setShowTable(false);
} else { } else {
setShowTable(true); setShowTable(true);

View file

@ -151,6 +151,7 @@ export const Home = (): JSX.Element => {
} }
totalCategories={categories.length} totalCategories={categories.length}
searching={!!localSearch} searching={!!localSearch}
fromHomepage={true}
/> />
)} )}
</Fragment> </Fragment>