mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-22 12:59:36 +02:00
add bookmark sorting (#3)
This commit is contained in:
parent
31cf2bc5ad
commit
2c659d1e51
21 changed files with 1021 additions and 437 deletions
|
@ -6,7 +6,7 @@ import classes from './AppGrid.module.css';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
apps: App[]
|
apps: App[];
|
||||||
totalCategories?: number;
|
totalCategories?: number;
|
||||||
searching: boolean;
|
searching: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ interface ComponentProps {
|
||||||
reorderAppCategories: (categories: Category[]) => void;
|
reorderAppCategories: (categories: Category[]) => void;
|
||||||
updateHandler: (data: Category | App) => void;
|
updateHandler: (data: Category | App) => void;
|
||||||
pinApp: (app: App) => void;
|
pinApp: (app: App) => void;
|
||||||
deleteApp: (id: number) => void;
|
deleteApp: (id: number, categoryId: number) => void;
|
||||||
reorderApps: (apps: App[]) => void;
|
reorderApps: (apps: App[]) => void;
|
||||||
updateConfig: (formData: any) => void;
|
updateConfig: (formData: any) => void;
|
||||||
createNotification: (notification: NewNotification) => void;
|
createNotification: (notification: NewNotification) => void;
|
||||||
|
@ -75,7 +75,7 @@ const AppTable = (props: ComponentProps): JSX.Element => {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (proceed) {
|
if (proceed) {
|
||||||
props.deleteApp(app.id);
|
props.deleteApp(app.id, app.categoryId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,23 +25,18 @@ interface ComponentProps {
|
||||||
|
|
||||||
export enum ContentType {
|
export enum ContentType {
|
||||||
category,
|
category,
|
||||||
app
|
app,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Apps = (props: ComponentProps): JSX.Element => {
|
const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
const {
|
const { apps, getApps, getAppCategories, categories, loading, searching = false } = props;
|
||||||
apps,
|
|
||||||
getApps,
|
|
||||||
getAppCategories,
|
|
||||||
categories,
|
|
||||||
loading,
|
|
||||||
searching = false
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||||
const [isInEdit, setIsInEdit] = useState(false);
|
const [isInEdit, setIsInEdit] = useState(false);
|
||||||
const [tableContentType, setTableContentType] = useState(ContentType.category);
|
const [tableContentType, setTableContentType] = useState(
|
||||||
|
ContentType.category
|
||||||
|
);
|
||||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||||
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
||||||
name: "",
|
name: "",
|
||||||
|
@ -49,10 +44,11 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
orderId: 0,
|
orderId: 0,
|
||||||
type: "apps",
|
type: "apps",
|
||||||
|
apps: [],
|
||||||
bookmarks: [],
|
bookmarks: [],
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date()
|
updatedAt: new Date(),
|
||||||
})
|
});
|
||||||
const [appInUpdate, setAppInUpdate] = useState<App>({
|
const [appInUpdate, setAppInUpdate] = useState<App>({
|
||||||
name: "string",
|
name: "string",
|
||||||
url: "string",
|
url: "string",
|
||||||
|
@ -75,18 +71,17 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
if (categories.length === 0) {
|
if (categories.length === 0) {
|
||||||
getAppCategories();
|
getAppCategories();
|
||||||
}
|
}
|
||||||
}, [getAppCategories])
|
}, [getAppCategories]);
|
||||||
|
|
||||||
const toggleModal = (): void => {
|
const toggleModal = (): void => {
|
||||||
setModalIsOpen(!modalIsOpen);
|
setModalIsOpen(!modalIsOpen);
|
||||||
// setIsInUpdate(false);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const addActionHandler = (contentType: ContentType) => {
|
const addActionHandler = (contentType: ContentType) => {
|
||||||
setFormContentType(contentType);
|
setFormContentType(contentType);
|
||||||
setIsInUpdate(false);
|
setIsInUpdate(false);
|
||||||
toggleModal();
|
toggleModal();
|
||||||
}
|
};
|
||||||
|
|
||||||
const editActionHandler = (contentType: ContentType) => {
|
const editActionHandler = (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
|
||||||
|
@ -96,11 +91,11 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
setIsInEdit(true);
|
setIsInEdit(true);
|
||||||
setTableContentType(contentType);
|
setTableContentType(contentType);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const instanceOfCategory = (object: any): object is Category => {
|
const instanceOfCategory = (object: any): object is Category => {
|
||||||
return "apps" in object;
|
return "apps" in object;
|
||||||
}
|
};
|
||||||
|
|
||||||
const goToUpdateMode = (data: Category | App): void => {
|
const goToUpdateMode = (data: Category | App): void => {
|
||||||
setIsInUpdate(true);
|
setIsInUpdate(true);
|
||||||
|
@ -112,7 +107,7 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
setAppInUpdate(data);
|
setAppInUpdate(data);
|
||||||
}
|
}
|
||||||
toggleModal();
|
toggleModal();
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
@ -157,7 +152,7 @@ const mapStateToProps = (state: GlobalState) => {
|
||||||
loading: state.app.loading,
|
loading: state.app.loading,
|
||||||
categories: state.app.categories,
|
categories: state.app.categories,
|
||||||
apps: state.app.apps,
|
apps: state.app.apps,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, { getApps, getAppCategories })(Apps);
|
export default connect(mapStateToProps, { getApps, getAppCategories })(Apps);
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import { Bookmark, Category } from '../../../interfaces';
|
|
||||||
import classes from './BookmarkCard.module.css';
|
|
||||||
|
|
||||||
import Icon from '../../UI/Icons/Icon/Icon';
|
|
||||||
import { iconParser, urlParser, searchConfig } from '../../../utility';
|
|
||||||
import { Fragment } from 'react';
|
import { Fragment } from 'react';
|
||||||
|
|
||||||
|
import { Bookmark, Category } from '../../../interfaces';
|
||||||
|
import { iconParser, searchConfig, urlParser } from '../../../utility';
|
||||||
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
|
import classes from './BookmarkCard.module.css';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
category: Category;
|
category: Category;
|
||||||
|
bookmarks: Bookmark[]
|
||||||
|
pinHandler?: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookmarkCard = (props: ComponentProps): JSX.Element => {
|
const BookmarkCard = (props: ComponentProps): JSX.Element => {
|
||||||
|
@ -14,7 +16,7 @@ const BookmarkCard = (props: ComponentProps): JSX.Element => {
|
||||||
<div className={classes.BookmarkCard}>
|
<div className={classes.BookmarkCard}>
|
||||||
<h3>{props.category.name}</h3>
|
<h3>{props.category.name}</h3>
|
||||||
<div className={classes.Bookmarks}>
|
<div className={classes.Bookmarks}>
|
||||||
{props.category.bookmarks.map((bookmark: Bookmark) => {
|
{props.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>;
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { Category } from '../../../interfaces';
|
import { Bookmark, Category } from '../../../interfaces';
|
||||||
import BookmarkCard from '../BookmarkCard/BookmarkCard';
|
import BookmarkCard from '../BookmarkCard/BookmarkCard';
|
||||||
import classes from './BookmarkGrid.module.css';
|
import classes from './BookmarkGrid.module.css';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
|
bookmarks: Bookmark[];
|
||||||
totalCategories?: number;
|
totalCategories?: number;
|
||||||
searching: boolean;
|
searching: boolean;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,7 @@ const BookmarkGrid = (props: ComponentProps): JSX.Element => {
|
||||||
<div className={classes.BookmarkGrid}>
|
<div className={classes.BookmarkGrid}>
|
||||||
{props.categories.map(
|
{props.categories.map(
|
||||||
(category: Category): JSX.Element => (
|
(category: Category): JSX.Element => (
|
||||||
<BookmarkCard category={category} key={category.id} />
|
<BookmarkCard key={category.id} category={category} bookmarks={props.bookmarks.filter( (bookmark: Bookmark) => bookmark.categoryId === category.id)} />
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,8 +8,11 @@ import {
|
||||||
createNotification,
|
createNotification,
|
||||||
deleteBookmark,
|
deleteBookmark,
|
||||||
deleteBookmarkCategory,
|
deleteBookmarkCategory,
|
||||||
|
pinBookmark,
|
||||||
pinBookmarkCategory,
|
pinBookmarkCategory,
|
||||||
reorderBookmarkCategories,
|
reorderBookmarkCategories,
|
||||||
|
reorderBookmarks,
|
||||||
|
updateConfig,
|
||||||
} from '../../../store/actions';
|
} from '../../../store/actions';
|
||||||
import { searchConfig } from '../../../utility';
|
import { searchConfig } from '../../../utility';
|
||||||
import Icon from '../../UI/Icons/Icon/Icon';
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
|
@ -20,16 +23,21 @@ import classes from './BookmarkTable.module.css';
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
contentType: ContentType;
|
contentType: ContentType;
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
|
bookmarks: Bookmark[];
|
||||||
pinBookmarkCategory: (category: Category) => void;
|
pinBookmarkCategory: (category: Category) => void;
|
||||||
deleteBookmarkCategory: (id: number) => void;
|
deleteBookmarkCategory: (id: number) => void;
|
||||||
updateHandler: (data: Category | Bookmark) => void;
|
|
||||||
deleteBookmark: (bookmarkId: number, categoryId: number) => void;
|
|
||||||
createNotification: (notification: NewNotification) => void;
|
|
||||||
reorderBookmarkCategories: (categories: Category[]) => void;
|
reorderBookmarkCategories: (categories: Category[]) => void;
|
||||||
|
updateHandler: (data: Category | Bookmark) => void;
|
||||||
|
pinBookmark: (bookmark: Bookmark) => void;
|
||||||
|
deleteBookmark: (id: number, categoryId: number) => void;
|
||||||
|
reorderBookmarks: (bookmarks: Bookmark[]) => void;
|
||||||
|
updateConfig: (formData: any) => void;
|
||||||
|
createNotification: (notification: NewNotification) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
const [localCategories, setLocalCategories] = useState<Category[]>([]);
|
const [localCategories, setLocalCategories] = useState<Category[]>([]);
|
||||||
|
const [localBookmarks, setLocalBookmarks] = useState<Bookmark[]>([]);
|
||||||
const [isCustomOrder, setIsCustomOrder] = useState<boolean>(false);
|
const [isCustomOrder, setIsCustomOrder] = useState<boolean>(false);
|
||||||
|
|
||||||
// Copy categories array
|
// Copy categories array
|
||||||
|
@ -37,6 +45,11 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
setLocalCategories([...props.categories]);
|
setLocalCategories([...props.categories]);
|
||||||
}, [props.categories]);
|
}, [props.categories]);
|
||||||
|
|
||||||
|
// Copy bookmarks array
|
||||||
|
useEffect(() => {
|
||||||
|
setLocalBookmarks([...props.bookmarks]);
|
||||||
|
}, [props.bookmarks]);
|
||||||
|
|
||||||
// Check ordering
|
// Check ordering
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const order = searchConfig("useOrdering", "");
|
const order = searchConfig("useOrdering", "");
|
||||||
|
@ -66,13 +79,14 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Support keyboard navigation for actions
|
||||||
const keyboardActionHandler = (
|
const keyboardActionHandler = (
|
||||||
e: KeyboardEvent,
|
e: KeyboardEvent,
|
||||||
category: Category,
|
object: any,
|
||||||
handler: Function
|
handler: Function
|
||||||
) => {
|
) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
handler(category);
|
handler(object);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,12 +103,21 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.contentType === ContentType.bookmark) {
|
||||||
|
const tmpBookmarks = [...localBookmarks];
|
||||||
|
const [movedBookmark] = tmpBookmarks.splice(result.source.index, 1);
|
||||||
|
tmpBookmarks.splice(result.destination.index, 0, movedBookmark);
|
||||||
|
|
||||||
|
setLocalBookmarks(tmpBookmarks);
|
||||||
|
props.reorderBookmarks(tmpBookmarks);
|
||||||
|
} else if (props.contentType === ContentType.category) {
|
||||||
const tmpCategories = [...localCategories];
|
const tmpCategories = [...localCategories];
|
||||||
const [movedCategory] = tmpCategories.splice(result.source.index, 1);
|
const [movedCategory] = tmpCategories.splice(result.source.index, 1);
|
||||||
tmpCategories.splice(result.destination.index, 0, movedCategory);
|
tmpCategories.splice(result.destination.index, 0, movedCategory);
|
||||||
|
|
||||||
setLocalCategories(tmpCategories);
|
setLocalCategories(tmpCategories);
|
||||||
props.reorderBookmarkCategories(tmpCategories);
|
props.reorderBookmarkCategories(tmpCategories);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (props.contentType === ContentType.category) {
|
if (props.contentType === ContentType.category) {
|
||||||
|
@ -168,7 +191,9 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={classes.TableAction}
|
className={classes.TableAction}
|
||||||
onClick={() => props.pinBookmarkCategory(category)}
|
onClick={() =>
|
||||||
|
props.pinBookmarkCategory(category)
|
||||||
|
}
|
||||||
onKeyDown={(e) =>
|
onKeyDown={(e) =>
|
||||||
keyboardActionHandler(
|
keyboardActionHandler(
|
||||||
e,
|
e,
|
||||||
|
@ -203,47 +228,132 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const bookmarks: { bookmark: Bookmark; categoryName: string }[] = [];
|
return (
|
||||||
props.categories.forEach((category: Category) => {
|
<Fragment>
|
||||||
category.bookmarks.forEach((bookmark: Bookmark) => {
|
<div className={classes.Message}>
|
||||||
bookmarks.push({
|
{isCustomOrder ? (
|
||||||
bookmark,
|
<p>You can drag and drop single rows to reorder bookmarklication</p>
|
||||||
categoryName: category.name,
|
) : (
|
||||||
});
|
<p>
|
||||||
});
|
Custom order is disabled. You can change it in{" "}
|
||||||
});
|
<Link to="/settings/other">settings</Link>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<DragDropContext onDragEnd={dragEndHandler}>
|
||||||
|
<Droppable droppableId="bookmarks">
|
||||||
|
{(provided) => (
|
||||||
|
<Table
|
||||||
|
headers={["Name", "URL", "Icon", "Category", "Actions"]}
|
||||||
|
innerRef={provided.innerRef}
|
||||||
|
>
|
||||||
|
{localBookmarks.map(
|
||||||
|
(bookmark: Bookmark, index): JSX.Element => {
|
||||||
|
return (
|
||||||
|
<Draggable
|
||||||
|
key={bookmark.id}
|
||||||
|
draggableId={bookmark.id.toString()}
|
||||||
|
index={index}
|
||||||
|
>
|
||||||
|
{(provided, snapshot) => {
|
||||||
|
const style = {
|
||||||
|
border: snapshot.isDragging
|
||||||
|
? "1px solid var(--color-accent)"
|
||||||
|
: "none",
|
||||||
|
borderRadius: "4px",
|
||||||
|
...provided.draggableProps.style,
|
||||||
|
};
|
||||||
|
|
||||||
|
const category = localCategories.find(
|
||||||
|
(category: Category) =>
|
||||||
|
category.id === bookmark.categoryId
|
||||||
|
);
|
||||||
|
const categoryName = category?.name;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table headers={["Name", "URL", "Icon", "Category", "Actions"]}>
|
<tr
|
||||||
{bookmarks.map(
|
{...provided.draggableProps}
|
||||||
(bookmark: { bookmark: Bookmark; categoryName: string }) => {
|
{...provided.dragHandleProps}
|
||||||
return (
|
ref={provided.innerRef}
|
||||||
<tr key={bookmark.bookmark.id}>
|
style={style}
|
||||||
<td>{bookmark.bookmark.name}</td>
|
>
|
||||||
<td>{bookmark.bookmark.url}</td>
|
<td style={{ width: "200px" }}>
|
||||||
<td>{bookmark.bookmark.icon}</td>
|
{bookmark.name}
|
||||||
<td>{bookmark.categoryName}</td>
|
</td>
|
||||||
|
<td style={{ width: "200px" }}>{bookmark.url}</td>
|
||||||
|
<td style={{ width: "200px" }}>
|
||||||
|
{bookmark.icon}
|
||||||
|
</td>
|
||||||
|
<td style={{ width: "200px" }}>{categoryName}</td>
|
||||||
|
{!snapshot.isDragging && (
|
||||||
<td className={classes.TableActions}>
|
<td className={classes.TableActions}>
|
||||||
<div
|
<div
|
||||||
className={classes.TableAction}
|
className={classes.TableAction}
|
||||||
onClick={() => deleteBookmarkHandler(bookmark.bookmark)}
|
onClick={() =>
|
||||||
|
deleteBookmarkHandler(bookmark)
|
||||||
|
}
|
||||||
|
onKeyDown={(e) =>
|
||||||
|
keyboardActionHandler(
|
||||||
|
e,
|
||||||
|
bookmark,
|
||||||
|
deleteBookmarkHandler
|
||||||
|
)
|
||||||
|
}
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
>
|
>
|
||||||
<Icon icon="mdiDelete" />
|
<Icon icon="mdiDelete" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={classes.TableAction}
|
className={classes.TableAction}
|
||||||
onClick={() => props.updateHandler(bookmark.bookmark)}
|
onClick={() =>
|
||||||
|
props.updateHandler(bookmark)
|
||||||
|
}
|
||||||
|
onKeyDown={(e) =>
|
||||||
|
keyboardActionHandler(
|
||||||
|
e,
|
||||||
|
bookmark,
|
||||||
|
props.updateHandler
|
||||||
|
)
|
||||||
|
}
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
>
|
>
|
||||||
<Icon icon="mdiPencil" />
|
<Icon icon="mdiPencil" />
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
className={classes.TableAction}
|
||||||
|
onClick={() => props.pinBookmark(bookmark)}
|
||||||
|
onKeyDown={(e) =>
|
||||||
|
keyboardActionHandler(
|
||||||
|
e,
|
||||||
|
bookmark,
|
||||||
|
props.pinBookmark
|
||||||
|
)
|
||||||
|
}
|
||||||
|
tabIndex={0}
|
||||||
|
>
|
||||||
|
{bookmark.isPinned ? (
|
||||||
|
<Icon
|
||||||
|
icon="mdiPinOff"
|
||||||
|
color="var(--color-accent)"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Icon icon="mdiPin" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
)}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
}}
|
||||||
|
</Draggable>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
</Table>
|
</Table>
|
||||||
|
)}
|
||||||
|
</Droppable>
|
||||||
|
</DragDropContext>
|
||||||
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -251,9 +361,12 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
const actions = {
|
const actions = {
|
||||||
pinBookmarkCategory,
|
pinBookmarkCategory,
|
||||||
deleteBookmarkCategory,
|
deleteBookmarkCategory,
|
||||||
deleteBookmark,
|
|
||||||
createNotification,
|
|
||||||
reorderBookmarkCategories,
|
reorderBookmarkCategories,
|
||||||
|
pinBookmark,
|
||||||
|
deleteBookmark,
|
||||||
|
reorderBookmarks,
|
||||||
|
updateConfig,
|
||||||
|
createNotification,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(null, actions)(BookmarkTable);
|
export default connect(null, actions)(BookmarkTable);
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { connect } from 'react-redux';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { Bookmark, Category, GlobalState } from '../../interfaces';
|
import { Bookmark, Category, GlobalState } from '../../interfaces';
|
||||||
import { getBookmarkCategories } from '../../store/actions';
|
import { getBookmarkCategories, getBookmarks } from '../../store/actions';
|
||||||
import ActionButton from '../UI/Buttons/ActionButton/ActionButton';
|
import ActionButton from '../UI/Buttons/ActionButton/ActionButton';
|
||||||
import Headline from '../UI/Headlines/Headline/Headline';
|
import Headline from '../UI/Headlines/Headline/Headline';
|
||||||
import { Container } from '../UI/Layout/Layout';
|
import { Container } from '../UI/Layout/Layout';
|
||||||
|
@ -18,6 +18,8 @@ interface ComponentProps {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
getBookmarkCategories: () => void;
|
getBookmarkCategories: () => void;
|
||||||
|
bookmarks: Bookmark[];
|
||||||
|
getBookmarks: () => void;
|
||||||
searching: boolean;
|
searching: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@ export enum ContentType {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bookmarks = (props: ComponentProps): JSX.Element => {
|
const Bookmarks = (props: ComponentProps): JSX.Element => {
|
||||||
const { getBookmarkCategories, categories, loading, searching = false } = props;
|
const { bookmarks, getBookmarks, getBookmarkCategories, categories, loading, searching = false } = props;
|
||||||
|
|
||||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||||
|
@ -37,25 +39,34 @@ const Bookmarks = (props: ComponentProps): JSX.Element => {
|
||||||
);
|
);
|
||||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||||
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
||||||
name: '',
|
name: "",
|
||||||
id: -1,
|
id: -1,
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
orderId: 0,
|
orderId: 0,
|
||||||
type: 'bookmarks',
|
type: "bookmarks",
|
||||||
|
apps: [],
|
||||||
bookmarks: [],
|
bookmarks: [],
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
});
|
});
|
||||||
const [bookmarkInUpdate, setBookmarkInUpdate] = useState<Bookmark>({
|
const [bookmarkInUpdate, setBookmarkInUpdate] = useState<Bookmark>({
|
||||||
name: '',
|
name: "",
|
||||||
url: '',
|
url: "",
|
||||||
categoryId: -1,
|
categoryId: -1,
|
||||||
icon: '',
|
icon: "",
|
||||||
id: -1,
|
isPinned: false,
|
||||||
|
orderId: 0,
|
||||||
|
id: 0,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (bookmarks.length === 0) {
|
||||||
|
getBookmarks();
|
||||||
|
}
|
||||||
|
}, [getBookmarks]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (categories.length === 0) {
|
if (categories.length === 0) {
|
||||||
getBookmarkCategories();
|
getBookmarkCategories();
|
||||||
|
@ -83,7 +94,7 @@ const Bookmarks = (props: ComponentProps): JSX.Element => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const instanceOfCategory = (object: any): object is Category => {
|
const instanceOfCategory = (object: any): object is Category => {
|
||||||
return 'bookmarks' in object;
|
return "bookmarks" in object;
|
||||||
};
|
};
|
||||||
|
|
||||||
const goToUpdateMode = (data: Category | Bookmark): void => {
|
const goToUpdateMode = (data: Category | Bookmark): void => {
|
||||||
|
@ -149,11 +160,12 @@ const Bookmarks = (props: ComponentProps): JSX.Element => {
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : !isInEdit ? (
|
) : !isInEdit ? (
|
||||||
<BookmarkGrid categories={categories} searching />
|
<BookmarkGrid categories={categories} bookmarks={bookmarks} searching />
|
||||||
) : (
|
) : (
|
||||||
<BookmarkTable
|
<BookmarkTable
|
||||||
contentType={tableContentType}
|
contentType={tableContentType}
|
||||||
categories={categories}
|
categories={categories}
|
||||||
|
bookmarks={bookmarks}
|
||||||
updateHandler={goToUpdateMode}
|
updateHandler={goToUpdateMode}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -168,4 +180,4 @@ const mapStateToProps = (state: GlobalState) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, { getBookmarkCategories })(Bookmarks);
|
export default connect(mapStateToProps, { getBookmarks, getBookmarkCategories })(Bookmarks);
|
||||||
|
|
|
@ -2,9 +2,8 @@ import { Fragment, useEffect, useState } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { App, Bookmark, Category } from '../../interfaces';
|
import { App, Bookmark, Category, GlobalState } from '../../interfaces';
|
||||||
import { GlobalState } from '../../interfaces/GlobalState';
|
import { getAppCategories, getApps, getBookmarkCategories, getBookmarks } from '../../store/actions';
|
||||||
import { getAppCategories, getApps, getBookmarkCategories } from '../../store/actions';
|
|
||||||
import { searchConfig } from '../../utility';
|
import { searchConfig } from '../../utility';
|
||||||
import AppGrid from '../Apps/AppGrid/AppGrid';
|
import AppGrid from '../Apps/AppGrid/AppGrid';
|
||||||
import BookmarkGrid from '../Bookmarks/BookmarkGrid/BookmarkGrid';
|
import BookmarkGrid from '../Bookmarks/BookmarkGrid/BookmarkGrid';
|
||||||
|
@ -21,12 +20,14 @@ import classes from './Home.module.css';
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
getApps: () => void;
|
getApps: () => void;
|
||||||
getAppCategories: () => void;
|
getAppCategories: () => void;
|
||||||
|
getBookmarks: () => void;
|
||||||
getBookmarkCategories: () => void;
|
getBookmarkCategories: () => void;
|
||||||
appsLoading: boolean;
|
appsLoading: boolean;
|
||||||
bookmarkCategoriesLoading: boolean;
|
bookmarkCategoriesLoading: boolean;
|
||||||
appCategories: Category[];
|
appCategories: Category[];
|
||||||
apps: App[];
|
apps: App[];
|
||||||
bookmarkCategories: Category[];
|
bookmarkCategories: Category[];
|
||||||
|
bookmarks: Bookmark[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Home = (props: ComponentProps): JSX.Element => {
|
const Home = (props: ComponentProps): JSX.Element => {
|
||||||
|
@ -34,9 +35,11 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
getAppCategories,
|
getAppCategories,
|
||||||
getApps,
|
getApps,
|
||||||
getBookmarkCategories,
|
getBookmarkCategories,
|
||||||
|
getBookmarks,
|
||||||
appCategories,
|
appCategories,
|
||||||
apps,
|
apps,
|
||||||
bookmarkCategories,
|
bookmarkCategories,
|
||||||
|
bookmarks,
|
||||||
appsLoading,
|
appsLoading,
|
||||||
bookmarkCategoriesLoading,
|
bookmarkCategoriesLoading,
|
||||||
} = props;
|
} = props;
|
||||||
|
@ -70,12 +73,19 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
}
|
}
|
||||||
}, [getBookmarkCategories]);
|
}, [getBookmarkCategories]);
|
||||||
|
|
||||||
|
// Load bookmarks
|
||||||
|
useEffect(() => {
|
||||||
|
if (bookmarks.length === 0) {
|
||||||
|
getBookmarks();
|
||||||
|
}
|
||||||
|
}, [getBookmarks]);
|
||||||
|
|
||||||
// Refresh greeter and time
|
// Refresh greeter and time
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let interval: any;
|
let interval: any;
|
||||||
|
|
||||||
// Start interval only when hideHeader is false
|
// Start interval only when hideHeader is false
|
||||||
if (searchConfig('hideHeader', 0) !== 1) {
|
if (searchConfig("hideHeader", 0) !== 1) {
|
||||||
interval = setInterval(() => {
|
interval = setInterval(() => {
|
||||||
setHeader({
|
setHeader({
|
||||||
dateTime: dateTime(),
|
dateTime: dateTime(),
|
||||||
|
@ -87,12 +97,16 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Search bookmarks
|
// Search categories
|
||||||
const searchBookmarks = (query: string, categoriesToSearch: Category[]): Category[] => {
|
const searchInCategories = (query: string, categoriesToSearch: Category[]): Category[] => {
|
||||||
const category: Category = {
|
const category: Category = {
|
||||||
name: "Search Results",
|
name: "Search Results",
|
||||||
type: categoriesToSearch[0].type,
|
type: categoriesToSearch[0].type,
|
||||||
isPinned: true,
|
isPinned: true,
|
||||||
|
apps: categoriesToSearch
|
||||||
|
.map((c: Category) => c.apps)
|
||||||
|
.flat()
|
||||||
|
.filter((app: App) => new RegExp(query, 'i').test(app.name)),
|
||||||
bookmarks: categoriesToSearch
|
bookmarks: categoriesToSearch
|
||||||
.map((c: Category) => c.bookmarks)
|
.map((c: Category) => c.bookmarks)
|
||||||
.flat()
|
.flat()
|
||||||
|
@ -136,7 +150,11 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : (
|
) : (
|
||||||
<AppGrid
|
<AppGrid
|
||||||
categories={appCategories.filter((category: Category) => category.isPinned)}
|
categories={
|
||||||
|
!localSearch
|
||||||
|
? appCategories.filter((category: Category) => category.isPinned)
|
||||||
|
: searchInCategories(localSearch, appCategories)
|
||||||
|
}
|
||||||
apps={
|
apps={
|
||||||
!localSearch
|
!localSearch
|
||||||
? apps.filter((app: App) => app.isPinned)
|
? apps.filter((app: App) => app.isPinned)
|
||||||
|
@ -154,7 +172,7 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
<div></div>
|
<div></div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{searchConfig('hideCategories', 0) !== 1 ? (
|
{searchConfig('hideBookmarks', 0) !== 1 ? (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<SectionHeadline title="Bookmarks" link="/bookmarks" />
|
<SectionHeadline title="Bookmarks" link="/bookmarks" />
|
||||||
{bookmarkCategoriesLoading ? (
|
{bookmarkCategoriesLoading ? (
|
||||||
|
@ -164,7 +182,14 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
categories={
|
categories={
|
||||||
!localSearch
|
!localSearch
|
||||||
? bookmarkCategories.filter((category: Category) => category.isPinned)
|
? bookmarkCategories.filter((category: Category) => category.isPinned)
|
||||||
: searchBookmarks(localSearch, bookmarkCategories)
|
: searchInCategories(localSearch, bookmarkCategories)
|
||||||
|
}
|
||||||
|
bookmarks={
|
||||||
|
!localSearch
|
||||||
|
? bookmarks.filter((bookmark: Bookmark) => bookmark.isPinned)
|
||||||
|
: bookmarks.filter((bookmark: Bookmark) =>
|
||||||
|
new RegExp(localSearch, 'i').test(bookmark.name)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
totalCategories={bookmarkCategories.length}
|
totalCategories={bookmarkCategories.length}
|
||||||
searching={!!localSearch}
|
searching={!!localSearch}
|
||||||
|
@ -189,7 +214,8 @@ const mapStateToProps = (state: GlobalState) => {
|
||||||
apps: state.app.apps,
|
apps: state.app.apps,
|
||||||
bookmarkCategoriesLoading: state.bookmark.loading,
|
bookmarkCategoriesLoading: state.bookmark.loading,
|
||||||
bookmarkCategories: state.bookmark.categories,
|
bookmarkCategories: state.bookmark.categories,
|
||||||
|
bookmarks: state.bookmark.bookmarks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps, { getApps, getAppCategories, getBookmarkCategories })(Home);
|
export default connect(mapStateToProps, { getApps, getAppCategories, getBookmarks, getBookmarkCategories })(Home);
|
||||||
|
|
|
@ -28,10 +28,11 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
const [formData, setFormData] = useState<SettingsForm>({
|
const [formData, setFormData] = useState<SettingsForm>({
|
||||||
customTitle: document.title,
|
customTitle: document.title,
|
||||||
pinAppsByDefault: 1,
|
pinAppsByDefault: 1,
|
||||||
|
pinBookmarksByDefault: 1,
|
||||||
pinCategoriesByDefault: 1,
|
pinCategoriesByDefault: 1,
|
||||||
hideHeader: 0,
|
hideHeader: 0,
|
||||||
hideApps: 0,
|
hideApps: 0,
|
||||||
hideCategories: 0,
|
hideBookmarks: 0,
|
||||||
useOrdering: 'createdAt',
|
useOrdering: 'createdAt',
|
||||||
appsSameTab: 0,
|
appsSameTab: 0,
|
||||||
bookmarksSameTab: 0,
|
bookmarksSameTab: 0,
|
||||||
|
@ -46,10 +47,11 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
setFormData({
|
setFormData({
|
||||||
customTitle: searchConfig('customTitle', 'Flame'),
|
customTitle: searchConfig('customTitle', 'Flame'),
|
||||||
pinAppsByDefault: searchConfig('pinAppsByDefault', 1),
|
pinAppsByDefault: searchConfig('pinAppsByDefault', 1),
|
||||||
|
pinBookmarksByDefault: searchConfig('pinBookmarksByDefault', 1),
|
||||||
pinCategoriesByDefault: searchConfig('pinCategoriesByDefault', 1),
|
pinCategoriesByDefault: searchConfig('pinCategoriesByDefault', 1),
|
||||||
hideHeader: searchConfig('hideHeader', 0),
|
hideHeader: searchConfig('hideHeader', 0),
|
||||||
hideApps: searchConfig('hideApps', 0),
|
hideApps: searchConfig('hideApps', 0),
|
||||||
hideCategories: searchConfig('hideCategories', 0),
|
hideBookmarks: searchConfig('hideBookmarks', 0),
|
||||||
useOrdering: searchConfig('useOrdering', 'createdAt'),
|
useOrdering: searchConfig('useOrdering', 'createdAt'),
|
||||||
appsSameTab: searchConfig('appsSameTab', 0),
|
appsSameTab: searchConfig('appsSameTab', 0),
|
||||||
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
|
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
|
||||||
|
@ -125,6 +127,18 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
<option value={0}>False</option>
|
<option value={0}>False</option>
|
||||||
</select>
|
</select>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
<InputGroup>
|
||||||
|
<label htmlFor="pinBookmarksByDefault">Pin new bookmarks by default</label>
|
||||||
|
<select
|
||||||
|
id="pinBookmarksByDefault"
|
||||||
|
name="pinBookmarksByDefault"
|
||||||
|
value={formData.pinBookmarksByDefault}
|
||||||
|
onChange={(e) => inputChangeHandler(e, true)}
|
||||||
|
>
|
||||||
|
<option value={1}>True</option>
|
||||||
|
<option value={0}>False</option>
|
||||||
|
</select>
|
||||||
|
</InputGroup>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<label htmlFor="pinCategoriesByDefault">
|
<label htmlFor="pinCategoriesByDefault">
|
||||||
Pin new categories by default
|
Pin new categories by default
|
||||||
|
@ -204,11 +218,11 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
</select>
|
</select>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<label htmlFor="hideCategories">Hide categories</label>
|
<label htmlFor="hideBookmarks">Hide bookmarks</label>
|
||||||
<select
|
<select
|
||||||
id="hideCategories"
|
id="hideBookmarks"
|
||||||
name="hideCategories"
|
name="hideBookmarks"
|
||||||
value={formData.hideCategories}
|
value={formData.hideBookmarks}
|
||||||
onChange={(e) => inputChangeHandler(e, true)}
|
onChange={(e) => inputChangeHandler(e, true)}
|
||||||
>
|
>
|
||||||
<option value={1}>True</option>
|
<option value={1}>True</option>
|
||||||
|
|
|
@ -5,6 +5,8 @@ export interface Bookmark extends Model {
|
||||||
url: string;
|
url: string;
|
||||||
categoryId: number;
|
categoryId: number;
|
||||||
icon: string;
|
icon: string;
|
||||||
|
isPinned: boolean;
|
||||||
|
orderId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NewBookmark {
|
export interface NewBookmark {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { Bookmark, Model } from '.';
|
import { App, Bookmark, Model } from '.';
|
||||||
|
|
||||||
export interface Category extends Model {
|
export interface Category extends Model {
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
isPinned: boolean;
|
isPinned: boolean;
|
||||||
orderId: number;
|
orderId: number;
|
||||||
|
apps: App[];
|
||||||
bookmarks: Bookmark[];
|
bookmarks: Bookmark[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,11 @@ export interface SearchForm {
|
||||||
export interface SettingsForm {
|
export interface SettingsForm {
|
||||||
customTitle: string;
|
customTitle: string;
|
||||||
pinAppsByDefault: number;
|
pinAppsByDefault: number;
|
||||||
|
pinBookmarksByDefault: number;
|
||||||
pinCategoriesByDefault: number;
|
pinCategoriesByDefault: number;
|
||||||
hideHeader: number;
|
hideHeader: number;
|
||||||
hideApps: number;
|
hideApps: number;
|
||||||
hideCategories: number;
|
hideBookmarks: number;
|
||||||
// hideSearch: number;
|
// hideSearch: number;
|
||||||
// defaultSearchProvider: string;
|
// defaultSearchProvider: string;
|
||||||
useOrdering: string;
|
useOrdering: string;
|
||||||
|
|
|
@ -12,17 +12,21 @@ import {
|
||||||
GetAppCategoriesAction,
|
GetAppCategoriesAction,
|
||||||
GetAppsAction,
|
GetAppsAction,
|
||||||
GetBookmarkCategoriesAction,
|
GetBookmarkCategoriesAction,
|
||||||
|
GetBookmarksAction,
|
||||||
GetConfigAction,
|
GetConfigAction,
|
||||||
PinAppAction,
|
PinAppAction,
|
||||||
PinAppCategoryAction,
|
PinAppCategoryAction,
|
||||||
|
PinBookmarkAction,
|
||||||
PinBookmarkCategoryAction,
|
PinBookmarkCategoryAction,
|
||||||
ReorderAppCategoriesAction,
|
ReorderAppCategoriesAction,
|
||||||
ReorderAppsAction,
|
ReorderAppsAction,
|
||||||
ReorderBookmarkCategoriesAction,
|
ReorderBookmarkCategoriesAction,
|
||||||
|
ReorderBookmarksAction,
|
||||||
SetThemeAction,
|
SetThemeAction,
|
||||||
SortAppCategoriesAction,
|
SortAppCategoriesAction,
|
||||||
SortAppsAction,
|
SortAppsAction,
|
||||||
SortBookmarkCategoriesAction,
|
SortBookmarkCategoriesAction,
|
||||||
|
SortBookmarksAction,
|
||||||
UpdateAppAction,
|
UpdateAppAction,
|
||||||
UpdateAppCategoryAction,
|
UpdateAppCategoryAction,
|
||||||
UpdateBookmarkAction,
|
UpdateBookmarkAction,
|
||||||
|
@ -66,9 +70,16 @@ export enum ActionTypes {
|
||||||
sortBookmarkCategories = 'SORT_BOOKMARK_CATEGORIES',
|
sortBookmarkCategories = 'SORT_BOOKMARK_CATEGORIES',
|
||||||
reorderBookmarkCategories = 'REORDER_BOOKMARK_CATEGORIES',
|
reorderBookmarkCategories = 'REORDER_BOOKMARK_CATEGORIES',
|
||||||
// Bookmarks
|
// Bookmarks
|
||||||
|
getBookmarks = 'GET_BOOKMARKS',
|
||||||
|
getBookmarksSuccess = 'GET_BOOKMARKS_SUCCESS',
|
||||||
|
getBookmarksError = 'GET_BOOKMARKS_ERROR',
|
||||||
|
pinBookmark = 'PIN_BOOKMARK',
|
||||||
addBookmark = 'ADD_BOOKMARK',
|
addBookmark = 'ADD_BOOKMARK',
|
||||||
|
addBookmarkSuccess = 'ADD_BOOKMARK_SUCCESS',
|
||||||
deleteBookmark = 'DELETE_BOOKMARK',
|
deleteBookmark = 'DELETE_BOOKMARK',
|
||||||
updateBookmark = 'UPDATE_BOOKMARK',
|
updateBookmark = 'UPDATE_BOOKMARK',
|
||||||
|
reorderBookmarks = 'REORDER_BOOKMARKS',
|
||||||
|
sortBookmarks = 'SORT_BOOKMARKS',
|
||||||
// Notifications
|
// Notifications
|
||||||
createNotification = 'CREATE_NOTIFICATION',
|
createNotification = 'CREATE_NOTIFICATION',
|
||||||
clearNotification = 'CLEAR_NOTIFICATION',
|
clearNotification = 'CLEAR_NOTIFICATION',
|
||||||
|
@ -109,9 +120,13 @@ export type Action =
|
||||||
| SortBookmarkCategoriesAction
|
| SortBookmarkCategoriesAction
|
||||||
| ReorderBookmarkCategoriesAction
|
| ReorderBookmarkCategoriesAction
|
||||||
// Bookmarks
|
// Bookmarks
|
||||||
|
| GetBookmarksAction<any>
|
||||||
|
| PinBookmarkAction
|
||||||
| AddBookmarkAction
|
| AddBookmarkAction
|
||||||
| DeleteBookmarkAction
|
| DeleteBookmarkAction
|
||||||
| UpdateBookmarkAction
|
| UpdateBookmarkAction
|
||||||
|
| ReorderBookmarksAction
|
||||||
|
| SortBookmarksAction
|
||||||
// Notifications
|
// Notifications
|
||||||
| CreateNotificationAction
|
| CreateNotificationAction
|
||||||
| ClearNotificationAction
|
| ClearNotificationAction
|
||||||
|
|
|
@ -31,11 +31,14 @@ export const getApps = () => async (dispatch: Dispatch) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET CATEGORIES
|
||||||
|
*/
|
||||||
export interface GetAppCategoriesAction<T> {
|
export interface GetAppCategoriesAction<T> {
|
||||||
type:
|
type:
|
||||||
| ActionTypes.getAppCategories
|
| ActionTypes.getAppCategories
|
||||||
| ActionTypes.getAppCategoriesSuccess
|
| ActionTypes.getAppCategoriesSuccess
|
||||||
| ActionTypes.getAppCategoriesSuccess;
|
| ActionTypes.getAppCategoriesError;
|
||||||
payload: T;
|
payload: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +62,9 @@ export const getAppCategories = () => async (dispatch: Dispatch) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ADD CATEGORY
|
||||||
|
*/
|
||||||
export interface AddAppCategoryAction {
|
export interface AddAppCategoryAction {
|
||||||
type: ActionTypes.addAppCategory;
|
type: ActionTypes.addAppCategory;
|
||||||
payload: Category;
|
payload: Category;
|
||||||
|
@ -124,6 +130,9 @@ export const pinApp = (app: App) => async (dispatch: Dispatch) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ADD APP
|
||||||
|
*/
|
||||||
export interface AddAppAction {
|
export interface AddAppAction {
|
||||||
type: ActionTypes.addAppSuccess;
|
type: ActionTypes.addAppSuccess;
|
||||||
payload: App;
|
payload: App;
|
||||||
|
@ -255,14 +264,21 @@ export const updateAppCategory =
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE APP
|
||||||
|
*/
|
||||||
export interface DeleteAppAction {
|
export interface DeleteAppAction {
|
||||||
type: ActionTypes.deleteApp;
|
type: ActionTypes.deleteApp;
|
||||||
payload: number;
|
payload: {
|
||||||
|
appId: number;
|
||||||
|
categoryId: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteApp = (id: number) => async (dispatch: Dispatch) => {
|
export const deleteApp =
|
||||||
|
(appId: number, categoryId: number) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete<ApiResponse<{}>>(`/api/apps/${id}`);
|
await axios.delete<ApiResponse<{}>>(`/api/apps/${appId}`);
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
|
@ -274,22 +290,28 @@ export const deleteApp = (id: number) => async (dispatch: Dispatch) => {
|
||||||
|
|
||||||
dispatch<DeleteAppAction>({
|
dispatch<DeleteAppAction>({
|
||||||
type: ActionTypes.deleteApp,
|
type: ActionTypes.deleteApp,
|
||||||
payload: id,
|
payload: {
|
||||||
|
appId,
|
||||||
|
categoryId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UPDATE APP
|
||||||
|
*/
|
||||||
export interface UpdateAppAction {
|
export interface UpdateAppAction {
|
||||||
type: ActionTypes.updateApp;
|
type: ActionTypes.updateApp;
|
||||||
payload: App;
|
payload: App;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateApp = (id: number, formData: NewApp | FormData) => async (dispatch: Dispatch) => {
|
export const updateApp = (appId: number, formData: NewApp | FormData, previousCategoryId: number) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.put<ApiResponse<App>>(
|
const res = await axios.put<ApiResponse<App>>(
|
||||||
`/api/apps/${id}`,
|
`/api/apps/${appId}`,
|
||||||
formData
|
formData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -301,13 +323,31 @@ export const updateApp = (id: number, formData: NewApp | FormData) => async (di
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await dispatch<UpdateAppAction>({
|
// Check if category was changed
|
||||||
|
const categoryWasChanged = res.data.data.categoryId !== previousCategoryId;
|
||||||
|
|
||||||
|
if (categoryWasChanged) {
|
||||||
|
// Delete app from old category
|
||||||
|
dispatch<DeleteAppAction>({
|
||||||
|
type: ActionTypes.deleteApp,
|
||||||
|
payload: {
|
||||||
|
appId,
|
||||||
|
categoryId: previousCategoryId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add app to the new category
|
||||||
|
dispatch<AddAppAction>({
|
||||||
|
type: ActionTypes.addAppSuccess,
|
||||||
|
payload: res.data.data,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Else update only name/url
|
||||||
|
dispatch<UpdateAppAction>({
|
||||||
type: ActionTypes.updateApp,
|
type: ActionTypes.updateApp,
|
||||||
payload: res.data.data,
|
payload: res.data.data,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Sort apps
|
|
||||||
dispatch<any>(sortApps());
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,69 +5,140 @@ import { ApiResponse, Bookmark, Category, Config, NewBookmark, NewCategory } fro
|
||||||
import { ActionTypes } from './actionTypes';
|
import { ActionTypes } from './actionTypes';
|
||||||
import { CreateNotificationAction } from './notification';
|
import { CreateNotificationAction } from './notification';
|
||||||
|
|
||||||
|
export interface GetBookmarksAction<T> {
|
||||||
|
type:
|
||||||
|
| ActionTypes.getBookmarks
|
||||||
|
| ActionTypes.getBookmarksSuccess
|
||||||
|
| ActionTypes.getBookmarksError;
|
||||||
|
payload: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getBookmarks = () => async (dispatch: Dispatch) => {
|
||||||
|
dispatch<GetBookmarksAction<undefined>>({
|
||||||
|
type: ActionTypes.getBookmarks,
|
||||||
|
payload: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await axios.get<ApiResponse<Bookmark[]>>("/api/bookmarks");
|
||||||
|
|
||||||
|
dispatch<GetBookmarksAction<Bookmark[]>>({
|
||||||
|
type: ActionTypes.getBookmarksSuccess,
|
||||||
|
payload: res.data.data,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET CATEGORIES
|
* GET CATEGORIES
|
||||||
*/
|
*/
|
||||||
export interface GetBookmarkCategoriesAction<T> {
|
export interface GetBookmarkCategoriesAction<T> {
|
||||||
type: ActionTypes.getBookmarkCategories | ActionTypes.getBookmarkCategoriesSuccess | ActionTypes.getBookmarkCategoriesError;
|
type:
|
||||||
|
| ActionTypes.getBookmarkCategories
|
||||||
|
| ActionTypes.getBookmarkCategoriesSuccess
|
||||||
|
| ActionTypes.getBookmarkCategoriesError;
|
||||||
payload: T;
|
payload: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getBookmarkCategories = () => async (dispatch: Dispatch) => {
|
export const getBookmarkCategories = () => async (dispatch: Dispatch) => {
|
||||||
dispatch<GetBookmarkCategoriesAction<undefined>>({
|
dispatch<GetBookmarkCategoriesAction<undefined>>({
|
||||||
type: ActionTypes.getBookmarkCategories,
|
type: ActionTypes.getBookmarkCategories,
|
||||||
payload: undefined
|
payload: undefined,
|
||||||
})
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get<ApiResponse<Category[]>>('/api/categories');
|
const res = await axios.get<ApiResponse<Category[]>>("/api/categories");
|
||||||
|
|
||||||
dispatch<GetBookmarkCategoriesAction<Category[]>>({
|
dispatch<GetBookmarkCategoriesAction<Category[]>>({
|
||||||
type: ActionTypes.getBookmarkCategoriesSuccess,
|
type: ActionTypes.getBookmarkCategoriesSuccess,
|
||||||
payload: res.data.data.filter((category: Category) => category.type === 'bookmarks'),
|
payload: res.data.data.filter(
|
||||||
})
|
(category: Category) => category.type === "bookmarks"
|
||||||
|
),
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADD CATEGORY
|
* ADD CATEGORY
|
||||||
*/
|
*/
|
||||||
export interface AddBookmarkCategoryAction {
|
export interface AddBookmarkCategoryAction {
|
||||||
type: ActionTypes.addBookmarkCategory,
|
type: ActionTypes.addBookmarkCategory;
|
||||||
payload: Category
|
payload: Category;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addBookmarkCategory = (formData: NewCategory) => async (dispatch: Dispatch) => {
|
export const addBookmarkCategory =
|
||||||
|
(formData: NewCategory) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.post<ApiResponse<Category>>('/api/categories', formData);
|
const res = await axios.post<ApiResponse<Category>>(
|
||||||
|
"/api/categories",
|
||||||
|
formData
|
||||||
|
);
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: "Success",
|
||||||
message: `Category ${formData.name} created`
|
message: `Category ${formData.name} created`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<AddBookmarkCategoryAction>({
|
dispatch<AddBookmarkCategoryAction>({
|
||||||
type: ActionTypes.addBookmarkCategory,
|
type: ActionTypes.addBookmarkCategory,
|
||||||
payload: res.data.data
|
payload: res.data.data,
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<any>(sortBookmarkCategories());
|
dispatch<any>(sortBookmarkCategories());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface PinBookmarkAction {
|
||||||
|
type: ActionTypes.pinBookmark;
|
||||||
|
payload: Bookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const pinBookmark =
|
||||||
|
(bookmark: Bookmark) => async (dispatch: Dispatch) => {
|
||||||
|
try {
|
||||||
|
const { id, isPinned, name } = bookmark;
|
||||||
|
const res = await axios.put<ApiResponse<Bookmark>>(
|
||||||
|
`/api/bookmarks/${id}`,
|
||||||
|
{
|
||||||
|
isPinned: !isPinned,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const status = isPinned
|
||||||
|
? "unpinned from Homescreen"
|
||||||
|
: "pinned to Homescreen";
|
||||||
|
|
||||||
|
dispatch<CreateNotificationAction>({
|
||||||
|
type: ActionTypes.createNotification,
|
||||||
|
payload: {
|
||||||
|
title: "Success",
|
||||||
|
message: `Bookmark ${name} ${status}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch<PinBookmarkAction>({
|
||||||
|
type: ActionTypes.pinBookmark,
|
||||||
|
payload: res.data.data,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADD BOOKMARK
|
* ADD BOOKMARK
|
||||||
*/
|
*/ export interface AddBookmarkAction {
|
||||||
export interface AddBookmarkAction {
|
type: ActionTypes.addBookmarkSuccess;
|
||||||
type: ActionTypes.addBookmark,
|
payload: Bookmark;
|
||||||
payload: Bookmark
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addBookmark = (formData: NewBookmark | FormData) => async (dispatch: Dispatch) => {
|
export const addBookmark = (formData: NewBookmark | FormData) => async (dispatch: Dispatch) => {
|
||||||
|
@ -78,175 +149,188 @@ export const addBookmark = (formData: NewBookmark | FormData) => async (dispatch
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
message: `Bookmark created`
|
message: `Bookmark ${res.data.data.name} created`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
dispatch<AddBookmarkAction>({
|
await dispatch<AddBookmarkAction>({
|
||||||
type: ActionTypes.addBookmark,
|
type: ActionTypes.addBookmarkSuccess,
|
||||||
payload: res.data.data
|
payload: res.data.data,
|
||||||
})
|
});
|
||||||
|
|
||||||
|
// Sort bookmarks
|
||||||
|
dispatch<any>(sortBookmarks());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PIN CATEGORY
|
* PIN CATEGORY
|
||||||
*/
|
*/
|
||||||
export interface PinBookmarkCategoryAction {
|
export interface PinBookmarkCategoryAction {
|
||||||
type: ActionTypes.pinBookmarkCategory,
|
type: ActionTypes.pinBookmarkCategory;
|
||||||
payload: Category
|
payload: Category;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pinBookmarkCategory = (category: Category) => async (dispatch: Dispatch) => {
|
export const pinBookmarkCategory =
|
||||||
|
(category: Category) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
const { id, isPinned, name } = category;
|
const { id, isPinned, name } = category;
|
||||||
const res = await axios.put<ApiResponse<Category>>(`/api/categories/${id}`, { isPinned: !isPinned });
|
const res = await axios.put<ApiResponse<Category>>(
|
||||||
|
`/api/categories/${id}`,
|
||||||
|
{ isPinned: !isPinned }
|
||||||
|
);
|
||||||
|
|
||||||
const status = isPinned ? 'unpinned from Homescreen' : 'pinned to Homescreen';
|
const status = isPinned
|
||||||
|
? "unpinned from Homescreen"
|
||||||
|
: "pinned to Homescreen";
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: "Success",
|
||||||
message: `Category ${name} ${status}`
|
message: `Category ${name} ${status}`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<PinBookmarkCategoryAction>({
|
dispatch<PinBookmarkCategoryAction>({
|
||||||
type: ActionTypes.pinBookmarkCategory,
|
type: ActionTypes.pinBookmarkCategory,
|
||||||
payload: res.data.data
|
payload: res.data.data,
|
||||||
})
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE CATEGORY
|
* DELETE CATEGORY
|
||||||
*/
|
*/
|
||||||
export interface DeleteBookmarkCategoryAction {
|
export interface DeleteBookmarkCategoryAction {
|
||||||
type: ActionTypes.deleteBookmarkCategory,
|
type: ActionTypes.deleteBookmarkCategory;
|
||||||
payload: number
|
payload: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteBookmarkCategory = (id: number) => async (dispatch: Dispatch) => {
|
export const deleteBookmarkCategory =
|
||||||
|
(id: number) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete<ApiResponse<{}>>(`/api/categories/${id}`);
|
await axios.delete<ApiResponse<{}>>(`/api/categories/${id}`);
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: "Success",
|
||||||
message: `Category deleted`
|
message: `Category deleted`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<DeleteBookmarkCategoryAction>({
|
dispatch<DeleteBookmarkCategoryAction>({
|
||||||
type: ActionTypes.deleteBookmarkCategory,
|
type: ActionTypes.deleteBookmarkCategory,
|
||||||
payload: id
|
payload: id,
|
||||||
})
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UPDATE CATEGORY
|
* UPDATE CATEGORY
|
||||||
*/
|
*/
|
||||||
export interface UpdateBookmarkCategoryAction {
|
export interface UpdateBookmarkCategoryAction {
|
||||||
type: ActionTypes.updateBookmarkCategory,
|
type: ActionTypes.updateBookmarkCategory;
|
||||||
payload: Category
|
payload: Category;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateBookmarkCategory = (id: number, formData: NewCategory) => async (dispatch: Dispatch) => {
|
export const updateBookmarkCategory =
|
||||||
|
(id: number, formData: NewCategory) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.put<ApiResponse<Category>>(`/api/categories/${id}`, formData);
|
const res = await axios.put<ApiResponse<Category>>(
|
||||||
|
`/api/categories/${id}`,
|
||||||
|
formData
|
||||||
|
);
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: "Success",
|
||||||
message: `Category ${formData.name} updated`
|
message: `Category ${formData.name} updated`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<UpdateBookmarkCategoryAction>({
|
dispatch<UpdateBookmarkCategoryAction>({
|
||||||
type: ActionTypes.updateBookmarkCategory,
|
type: ActionTypes.updateBookmarkCategory,
|
||||||
payload: res.data.data
|
payload: res.data.data,
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<any>(sortBookmarkCategories());
|
dispatch<any>(sortBookmarkCategories());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE BOOKMARK
|
* DELETE BOOKMARK
|
||||||
*/
|
*/
|
||||||
export interface DeleteBookmarkAction {
|
export interface DeleteBookmarkAction {
|
||||||
type: ActionTypes.deleteBookmark,
|
type: ActionTypes.deleteBookmark;
|
||||||
payload: {
|
payload: {
|
||||||
bookmarkId: number,
|
bookmarkId: number;
|
||||||
categoryId: number
|
categoryId: number;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteBookmark = (bookmarkId: number, categoryId: number) => async (dispatch: Dispatch) => {
|
export const deleteBookmark =
|
||||||
|
(bookmarkId: number, categoryId: number) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete<ApiResponse<{}>>(`/api/bookmarks/${bookmarkId}`);
|
await axios.delete<ApiResponse<{}>>(`/api/bookmarks/${bookmarkId}`);
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: "Success",
|
||||||
message: 'Bookmark deleted'
|
message: "Bookmark deleted",
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
dispatch<DeleteBookmarkAction>({
|
dispatch<DeleteBookmarkAction>({
|
||||||
type: ActionTypes.deleteBookmark,
|
type: ActionTypes.deleteBookmark,
|
||||||
payload: {
|
payload: {
|
||||||
bookmarkId,
|
bookmarkId,
|
||||||
categoryId
|
categoryId,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UPDATE BOOKMARK
|
* UPDATE BOOKMARK
|
||||||
*/
|
*/
|
||||||
export interface UpdateBookmarkAction {
|
export interface UpdateBookmarkAction {
|
||||||
type: ActionTypes.updateBookmark,
|
type: ActionTypes.updateBookmark;
|
||||||
payload: Bookmark
|
payload: Bookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateBookmark = (
|
export const updateBookmark =
|
||||||
bookmarkId: number,
|
(bookmarkId: number, formData: NewBookmark | FormData, previousCategoryId: number) =>
|
||||||
formData: NewBookmark | FormData,
|
async (dispatch: Dispatch) => {
|
||||||
category: {
|
|
||||||
prev: number,
|
|
||||||
curr: number
|
|
||||||
}
|
|
||||||
) => async (dispatch: Dispatch) => {
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.put<ApiResponse<Bookmark>>(`/api/bookmarks/${bookmarkId}`, formData);
|
const res = await axios.put<ApiResponse<Bookmark>>(
|
||||||
|
`/api/bookmarks/${bookmarkId}`,
|
||||||
|
formData
|
||||||
|
);
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: 'Success',
|
title: "Success",
|
||||||
message: `Bookmark updated`
|
message: `Bookmark ${res.data.data.name} updated`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
// Check if category was changed
|
// Check if category was changed
|
||||||
const categoryWasChanged = category.curr !== category.prev;
|
const categoryWasChanged = res.data.data.categoryId !== previousCategoryId;
|
||||||
|
|
||||||
if (categoryWasChanged) {
|
if (categoryWasChanged) {
|
||||||
// Delete bookmark from old category
|
// Delete bookmark from old category
|
||||||
|
@ -254,27 +338,81 @@ export const updateBookmark = (
|
||||||
type: ActionTypes.deleteBookmark,
|
type: ActionTypes.deleteBookmark,
|
||||||
payload: {
|
payload: {
|
||||||
bookmarkId,
|
bookmarkId,
|
||||||
categoryId: category.prev
|
categoryId: previousCategoryId,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
// Add bookmark to the new category
|
// Add bookmark to the new category
|
||||||
dispatch<AddBookmarkAction>({
|
dispatch<AddBookmarkAction>({
|
||||||
type: ActionTypes.addBookmark,
|
type: ActionTypes.addBookmarkSuccess,
|
||||||
payload: res.data.data
|
payload: res.data.data,
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
// Else update only name/url/icon
|
// Else update only name/url
|
||||||
dispatch<UpdateBookmarkAction>({
|
dispatch<UpdateBookmarkAction>({
|
||||||
type: ActionTypes.updateBookmark,
|
type: ActionTypes.updateBookmark,
|
||||||
payload: res.data.data
|
payload: res.data.data,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface ReorderBookmarksAction {
|
||||||
|
type: ActionTypes.reorderBookmarks;
|
||||||
|
payload: Bookmark[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ReorderBookmarksQuery {
|
||||||
|
bookmarks: {
|
||||||
|
id: number;
|
||||||
|
orderId: number;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const reorderBookmarks =
|
||||||
|
(bookmarks: Bookmark[]) => async (dispatch: Dispatch) => {
|
||||||
|
try {
|
||||||
|
const updateQuery: ReorderBookmarksQuery = { bookmarks: [] };
|
||||||
|
|
||||||
|
bookmarks.forEach((bookmark, index) => {
|
||||||
|
updateQuery.bookmarks.push({
|
||||||
|
id: bookmark.id,
|
||||||
|
orderId: index + 1,
|
||||||
|
});
|
||||||
|
bookmark.orderId = index + 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
await axios.put<ApiResponse<{}>>("/api/bookmarks/0/reorder", updateQuery);
|
||||||
|
|
||||||
|
dispatch<ReorderBookmarksAction>({
|
||||||
|
type: ActionTypes.reorderBookmarks,
|
||||||
|
payload: bookmarks,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface SortBookmarksAction {
|
||||||
|
type: ActionTypes.sortBookmarks;
|
||||||
|
payload: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const sortBookmarks = () => async (dispatch: Dispatch) => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get<ApiResponse<Config>>("/api/config/useOrdering");
|
||||||
|
|
||||||
|
dispatch<SortBookmarksAction>({
|
||||||
|
type: ActionTypes.sortBookmarks,
|
||||||
|
payload: res.data.data.value,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SORT CATEGORIES
|
* SORT CATEGORIES
|
||||||
*/
|
*/
|
||||||
|
@ -285,16 +423,16 @@ export interface SortBookmarkCategoriesAction {
|
||||||
|
|
||||||
export const sortBookmarkCategories = () => async (dispatch: Dispatch) => {
|
export const sortBookmarkCategories = () => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get<ApiResponse<Config>>('/api/config/useOrdering');
|
const res = await axios.get<ApiResponse<Config>>("/api/config/useOrdering");
|
||||||
|
|
||||||
dispatch<SortBookmarkCategoriesAction>({
|
dispatch<SortBookmarkCategoriesAction>({
|
||||||
type: ActionTypes.sortBookmarkCategories,
|
type: ActionTypes.sortBookmarkCategories,
|
||||||
payload: res.data.data.value
|
payload: res.data.data.value,
|
||||||
})
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REORDER CATEGORIES
|
* REORDER CATEGORIES
|
||||||
|
@ -304,29 +442,35 @@ export interface ReorderBookmarkCategoriesAction {
|
||||||
payload: Category[];
|
payload: Category[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReorderQuery {
|
interface ReorderReorderCategoriesQueryuery {
|
||||||
categories: {
|
categories: {
|
||||||
id: number;
|
id: number;
|
||||||
orderId: number;
|
orderId: number;
|
||||||
}[]
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reorderBookmarkCategories = (categories: Category[]) => async (dispatch: Dispatch) => {
|
export const reorderBookmarkCategories =
|
||||||
|
(categories: Category[]) => async (dispatch: Dispatch) => {
|
||||||
try {
|
try {
|
||||||
const updateQuery: ReorderQuery = { categories: [] }
|
const updateQuery: ReorderReorderCategoriesQueryuery = { categories: [] };
|
||||||
|
|
||||||
categories.forEach((category, index) => updateQuery.categories.push({
|
categories.forEach((category, index) =>
|
||||||
|
updateQuery.categories.push({
|
||||||
id: category.id,
|
id: category.id,
|
||||||
orderId: index + 1
|
orderId: index + 1,
|
||||||
}))
|
})
|
||||||
|
);
|
||||||
|
|
||||||
await axios.put<ApiResponse<{}>>('/api/categories/0/reorder', updateQuery);
|
await axios.put<ApiResponse<{}>>(
|
||||||
|
"/api/categories/0/reorder",
|
||||||
|
updateQuery
|
||||||
|
);
|
||||||
|
|
||||||
dispatch<ReorderBookmarkCategoriesAction>({
|
dispatch<ReorderBookmarkCategoriesAction>({
|
||||||
type: ActionTypes.reorderBookmarkCategories,
|
type: ActionTypes.reorderBookmarkCategories,
|
||||||
payload: categories
|
payload: categories,
|
||||||
})
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -88,7 +88,9 @@ const pinCategory = (state: State, action: Action): State => {
|
||||||
|
|
||||||
const pinApp = (state: State, action: Action): State => {
|
const pinApp = (state: State, action: Action): State => {
|
||||||
const tmpApps = [...state.apps];
|
const tmpApps = [...state.apps];
|
||||||
const changedApp = tmpApps.find((app: App) => app.id === action.payload.id);
|
const changedApp = tmpApps.find(
|
||||||
|
(app: App) => app.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
if (changedApp) {
|
if (changedApp) {
|
||||||
changedApp.isPinned = action.payload.isPinned;
|
changedApp.isPinned = action.payload.isPinned;
|
||||||
|
@ -101,8 +103,25 @@ const pinApp = (state: State, action: Action): State => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const addAppSuccess = (state: State, action: Action): State => {
|
const addAppSuccess = (state: State, action: Action): State => {
|
||||||
|
const categoryIndex = state.categories.findIndex(
|
||||||
|
(category: Category) => category.id === action.payload.categoryId
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
categories: [
|
||||||
|
...state.categories.slice(0, categoryIndex),
|
||||||
|
{
|
||||||
|
...state.categories[categoryIndex],
|
||||||
|
apps: [
|
||||||
|
...state.categories[categoryIndex].apps,
|
||||||
|
{
|
||||||
|
...action.payload,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
...state.categories.slice(categoryIndex + 1),
|
||||||
|
],
|
||||||
apps: [...state.apps, action.payload],
|
apps: [...state.apps, action.payload],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -139,18 +158,33 @@ const updateCategory = (state: State, action: Action): State => {
|
||||||
|
|
||||||
const deleteApp = (state: State, action: Action): State => {
|
const deleteApp = (state: State, action: Action): State => {
|
||||||
const tmpApps = [...state.apps].filter(
|
const tmpApps = [...state.apps].filter(
|
||||||
(app: App) => app.id !== action.payload
|
(app: App) => app.id !== action.payload.appId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const tmpCategories = [...state.categories];
|
||||||
|
const categoryInUpdate = tmpCategories.find(
|
||||||
|
(category: Category) => category.id === action.payload.categoryId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (categoryInUpdate) {
|
||||||
|
categoryInUpdate.apps = categoryInUpdate.apps.filter(
|
||||||
|
(app: App) => app.id !== action.payload.appId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
categories: tmpCategories,
|
||||||
apps: tmpApps,
|
apps: tmpApps,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateApp = (state: State, action: Action): State => {
|
const updateApp = (state: State, action: Action): State => {
|
||||||
|
// Update global apps collection
|
||||||
const tmpApps = [...state.apps];
|
const tmpApps = [...state.apps];
|
||||||
const appInUpdate = tmpApps.find((app: App) => app.id === action.payload.id);
|
const appInUpdate = tmpApps.find(
|
||||||
|
(app: App) => app.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
if (appInUpdate) {
|
if (appInUpdate) {
|
||||||
appInUpdate.name = action.payload.name;
|
appInUpdate.name = action.payload.name;
|
||||||
|
@ -159,8 +193,30 @@ const updateApp = (state: State, action: Action): State => {
|
||||||
appInUpdate.categoryId = action.payload.categoryId;
|
appInUpdate.categoryId = action.payload.categoryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update category apps collection
|
||||||
|
let categoryIndex = state.categories.findIndex(
|
||||||
|
(category: Category) => category.id === action.payload.categoryId
|
||||||
|
);
|
||||||
|
let appIndex = state.categories[categoryIndex].apps.findIndex(
|
||||||
|
(app: App) => app.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
categories: [
|
||||||
|
...state.categories.slice(0, categoryIndex),
|
||||||
|
{
|
||||||
|
...state.categories[categoryIndex],
|
||||||
|
apps: [
|
||||||
|
...state.categories[categoryIndex].apps.slice(0, appIndex),
|
||||||
|
{
|
||||||
|
...action.payload,
|
||||||
|
},
|
||||||
|
...state.categories[categoryIndex].apps.slice(appIndex + 1),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
...state.categories.slice(categoryIndex + 1),
|
||||||
|
],
|
||||||
apps: tmpApps,
|
apps: tmpApps,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -189,16 +245,6 @@ const reorderApps = (state: State, action: Action): State => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortApps = (state: State, action: Action): State => {
|
const sortApps = (state: State, action: Action): State => {
|
||||||
// const tmpCategories = [...state.categories];
|
|
||||||
|
|
||||||
// tmpCategories.forEach((category: Category) => {
|
|
||||||
// category.apps = sortData<App>(category.apps, action.payload);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// return {
|
|
||||||
// ...state,
|
|
||||||
// categories: tmpCategories,
|
|
||||||
// };
|
|
||||||
const sortedApps = sortData<App>(state.apps, action.payload);
|
const sortedApps = sortData<App>(state.apps, action.payload);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -6,29 +6,55 @@ export interface State {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
errors: string | undefined;
|
errors: string | undefined;
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
|
bookmarks: Bookmark[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: State = {
|
const initialState: State = {
|
||||||
loading: true,
|
loading: true,
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
categories: []
|
categories: [],
|
||||||
}
|
bookmarks: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const getBookmarks = (state: State, action: Action): State => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: true,
|
||||||
|
errors: undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getBookmarksSuccess = (state: State, action: Action): State => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: false,
|
||||||
|
bookmarks: action.payload,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getBookmarksError = (state: State, action: Action): State => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: false,
|
||||||
|
errors: action.payload,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const getCategories = (state: State, action: Action): State => {
|
const getCategories = (state: State, action: Action): State => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
loading: true,
|
loading: true,
|
||||||
errors: undefined
|
errors: undefined,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const getCategoriesSuccess = (state: State, action: Action): State => {
|
const getCategoriesSuccess = (state: State, action: Action): State => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
loading: false,
|
loading: false,
|
||||||
categories: action.payload
|
categories: action.payload,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const addCategory = (state: State, action: Action): State => {
|
const addCategory = (state: State, action: Action): State => {
|
||||||
return {
|
return {
|
||||||
|
@ -37,15 +63,49 @@ const addCategory = (state: State, action: Action): State => {
|
||||||
...state.categories,
|
...state.categories,
|
||||||
{
|
{
|
||||||
...action.payload,
|
...action.payload,
|
||||||
type: 'bookmarks',
|
type: "bookmarks",
|
||||||
bookmarks: []
|
bookmarks: [],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const addBookmark = (state: State, action: Action): State => {
|
const pinCategory = (state: State, action: Action): State => {
|
||||||
const categoryIndex = state.categories.findIndex((category: Category) => category.id === action.payload.categoryId);
|
const tmpCategories = [...state.categories];
|
||||||
|
const changedCategory = tmpCategories.find(
|
||||||
|
(category: Category) => category.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changedCategory) {
|
||||||
|
changedCategory.isPinned = action.payload.isPinned;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
categories: tmpCategories,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const pinBookmark = (state: State, action: Action): State => {
|
||||||
|
const tmpBookmarks = [...state.bookmarks];
|
||||||
|
const changedBookmark = tmpBookmarks.find(
|
||||||
|
(bookmark: Bookmark) => bookmark.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changedBookmark) {
|
||||||
|
changedBookmark.isPinned = action.payload.isPinned;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
bookmarks: tmpBookmarks,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const addBookmarkSuccess = (state: State, action: Action): State => {
|
||||||
|
const categoryIndex = state.categories.findIndex(
|
||||||
|
(category: Category) => category.id === action.payload.categoryId
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -56,44 +116,35 @@ const addBookmark = (state: State, action: Action): State => {
|
||||||
bookmarks: [
|
bookmarks: [
|
||||||
...state.categories[categoryIndex].bookmarks,
|
...state.categories[categoryIndex].bookmarks,
|
||||||
{
|
{
|
||||||
...action.payload
|
...action.payload,
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
...state.categories.slice(categoryIndex + 1)
|
],
|
||||||
]
|
},
|
||||||
}
|
...state.categories.slice(categoryIndex + 1),
|
||||||
}
|
],
|
||||||
|
bookmarks: [...state.bookmarks, action.payload],
|
||||||
const pinCategory = (state: State, action: Action): State => {
|
};
|
||||||
const tmpCategories = [...state.categories];
|
};
|
||||||
const changedCategory = tmpCategories.find((category: Category) => category.id === action.payload.id);
|
|
||||||
|
|
||||||
if (changedCategory) {
|
|
||||||
changedCategory.isPinned = action.payload.isPinned;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
categories: tmpCategories
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const deleteCategory = (state: State, action: Action): State => {
|
const deleteCategory = (state: State, action: Action): State => {
|
||||||
const categoryIndex = state.categories.findIndex((category: Category) => category.id === action.payload);
|
const categoryIndex = state.categories.findIndex(
|
||||||
|
(category: Category) => category.id === action.payload
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
categories: [
|
categories: [
|
||||||
...state.categories.slice(0, categoryIndex),
|
...state.categories.slice(0, categoryIndex),
|
||||||
...state.categories.slice(categoryIndex + 1)
|
...state.categories.slice(categoryIndex + 1),
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const updateCategory = (state: State, action: Action): State => {
|
const updateCategory = (state: State, action: Action): State => {
|
||||||
const tmpCategories = [...state.categories];
|
const tmpCategories = [...state.categories];
|
||||||
const categoryInUpdate = tmpCategories.find((category: Category) => category.id === action.payload.id);
|
const categoryInUpdate = tmpCategories.find(
|
||||||
|
(category: Category) => category.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
if (categoryInUpdate) {
|
if (categoryInUpdate) {
|
||||||
categoryInUpdate.name = action.payload.name;
|
categoryInUpdate.name = action.payload.name;
|
||||||
|
@ -101,28 +152,54 @@ const updateCategory = (state: State, action: Action): State => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
categories: tmpCategories
|
categories: tmpCategories,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const deleteBookmark = (state: State, action: Action): State => {
|
const deleteBookmark = (state: State, action: Action): State => {
|
||||||
|
const tmpBookmarks = [...state.bookmarks].filter(
|
||||||
|
(bookmark: Bookmark) => bookmark.id !== action.payload.bookmarkId
|
||||||
|
);
|
||||||
|
|
||||||
const tmpCategories = [...state.categories];
|
const tmpCategories = [...state.categories];
|
||||||
const categoryInUpdate = tmpCategories.find((category: Category) => category.id === action.payload.categoryId);
|
const categoryInUpdate = tmpCategories.find(
|
||||||
|
(category: Category) => category.id === action.payload.categoryId
|
||||||
|
);
|
||||||
|
|
||||||
if (categoryInUpdate) {
|
if (categoryInUpdate) {
|
||||||
categoryInUpdate.bookmarks = categoryInUpdate.bookmarks.filter((bookmark: Bookmark) => bookmark.id !== action.payload.bookmarkId);
|
categoryInUpdate.bookmarks = categoryInUpdate.bookmarks.filter(
|
||||||
|
(bookmark: Bookmark) => bookmark.id !== action.payload.bookmarkId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
categories: tmpCategories
|
categories: tmpCategories,
|
||||||
}
|
bookmarks: tmpBookmarks,
|
||||||
}
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const updateBookmark = (state: State, action: Action): State => {
|
const updateBookmark = (state: State, action: Action): State => {
|
||||||
let categoryIndex = state.categories.findIndex((category: Category) => category.id === action.payload.categoryId);
|
// Update global bookmarks collection
|
||||||
let bookmarkIndex = state.categories[categoryIndex].bookmarks.findIndex((bookmark: Bookmark) => bookmark.id === action.payload.id);
|
const tmpBookmarks = [...state.bookmarks];
|
||||||
|
const bookmarkInUpdate = tmpBookmarks.find(
|
||||||
|
(bookmark: Bookmark) => bookmark.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (bookmarkInUpdate) {
|
||||||
|
bookmarkInUpdate.name = action.payload.name;
|
||||||
|
bookmarkInUpdate.url = action.payload.url;
|
||||||
|
bookmarkInUpdate.icon = action.payload.icon;
|
||||||
|
bookmarkInUpdate.categoryId = action.payload.categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
//update category bookmarks collection
|
||||||
|
let categoryIndex = state.categories.findIndex(
|
||||||
|
(category: Category) => category.id === action.payload.categoryId
|
||||||
|
);
|
||||||
|
let bookmarkIndex = state.categories[categoryIndex].bookmarks.findIndex(
|
||||||
|
(bookmark: Bookmark) => bookmark.id === action.payload.id
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -133,47 +210,88 @@ const updateBookmark = (state: State, action: Action): State => {
|
||||||
bookmarks: [
|
bookmarks: [
|
||||||
...state.categories[categoryIndex].bookmarks.slice(0, bookmarkIndex),
|
...state.categories[categoryIndex].bookmarks.slice(0, bookmarkIndex),
|
||||||
{
|
{
|
||||||
...action.payload
|
...action.payload,
|
||||||
},
|
},
|
||||||
...state.categories[categoryIndex].bookmarks.slice(bookmarkIndex + 1)
|
...state.categories[categoryIndex].bookmarks.slice(bookmarkIndex + 1),
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
...state.categories.slice(categoryIndex + 1)
|
...state.categories.slice(categoryIndex + 1),
|
||||||
]
|
],
|
||||||
}
|
bookmarks: tmpBookmarks,
|
||||||
}
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const sortBookmarkCategories = (state: State, action: Action): State => {
|
const sortBookmarkCategories = (state: State, action: Action): State => {
|
||||||
const sortedCategories = sortData<Category>(state.categories, action.payload);
|
const sortedCategories = sortData<Category>(state.categories, action.payload);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
categories: sortedCategories
|
categories: sortedCategories,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const reorderCategories = (state: State, action: Action): State => {
|
const reorderCategories = (state: State, action: Action): State => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
categories: action.payload
|
categories: action.payload,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const reorderBookmarks = (state: State, action: Action): State => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
bookmarks: action.payload,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortBookmarks = (state: State, action: Action): State => {
|
||||||
|
const sortedBookmarks = sortData<Bookmark>(state.bookmarks, action.payload);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
bookmarks: sortedBookmarks,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const bookmarkReducer = (state = initialState, action: Action) => {
|
const bookmarkReducer = (state = initialState, action: Action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.getBookmarkCategories: return getCategories(state, action);
|
case ActionTypes.getBookmarkCategories:
|
||||||
case ActionTypes.getBookmarkCategoriesSuccess: return getCategoriesSuccess(state, action);
|
return getCategories(state, action);
|
||||||
case ActionTypes.addBookmarkCategory: return addCategory(state, action);
|
case ActionTypes.getBookmarkCategoriesSuccess:
|
||||||
case ActionTypes.addBookmark: return addBookmark(state, action);
|
return getCategoriesSuccess(state, action);
|
||||||
case ActionTypes.pinBookmarkCategory: return pinCategory(state, action);
|
case ActionTypes.getBookmarks:
|
||||||
case ActionTypes.deleteBookmarkCategory: return deleteCategory(state, action);
|
return getBookmarks(state, action);
|
||||||
case ActionTypes.updateBookmarkCategory: return updateCategory(state, action);
|
case ActionTypes.getBookmarksSuccess:
|
||||||
case ActionTypes.deleteBookmark: return deleteBookmark(state, action);
|
return getBookmarksSuccess(state, action);
|
||||||
case ActionTypes.updateBookmark: return updateBookmark(state, action);
|
case ActionTypes.getBookmarksError:
|
||||||
case ActionTypes.sortBookmarkCategories: return sortBookmarkCategories(state, action);
|
return getBookmarksError(state, action);
|
||||||
case ActionTypes.reorderBookmarkCategories: return reorderCategories(state, action);
|
case ActionTypes.addBookmarkCategory:
|
||||||
default: return state;
|
return addCategory(state, action);
|
||||||
|
case ActionTypes.addBookmarkSuccess:
|
||||||
|
return addBookmarkSuccess(state, action);
|
||||||
|
case ActionTypes.pinBookmarkCategory:
|
||||||
|
return pinCategory(state, action);
|
||||||
|
case ActionTypes.pinBookmark:
|
||||||
|
return pinBookmark(state, action);
|
||||||
|
case ActionTypes.deleteBookmarkCategory:
|
||||||
|
return deleteCategory(state, action);
|
||||||
|
case ActionTypes.updateBookmarkCategory:
|
||||||
|
return updateCategory(state, action);
|
||||||
|
case ActionTypes.deleteBookmark:
|
||||||
|
return deleteBookmark(state, action);
|
||||||
|
case ActionTypes.updateBookmark:
|
||||||
|
return updateBookmark(state, action);
|
||||||
|
case ActionTypes.sortBookmarkCategories:
|
||||||
|
return sortBookmarkCategories(state, action);
|
||||||
|
case ActionTypes.reorderBookmarkCategories:
|
||||||
|
return reorderCategories(state, action);
|
||||||
|
case ActionTypes.sortBookmarks:
|
||||||
|
return sortBookmarks(state, action);
|
||||||
|
case ActionTypes.reorderBookmarks:
|
||||||
|
return reorderBookmarks(state, action);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export default bookmarkReducer;
|
export default bookmarkReducer;
|
|
@ -1,17 +1,23 @@
|
||||||
const asyncWrapper = require('../middleware/asyncWrapper');
|
const asyncWrapper = require('../middleware/asyncWrapper');
|
||||||
const ErrorResponse = require('../utils/ErrorResponse');
|
const ErrorResponse = require('../utils/ErrorResponse');
|
||||||
const Bookmark = require('../models/Bookmark');
|
const Bookmark = require('../models/Bookmark');
|
||||||
|
const Config = require('../models/Config');
|
||||||
const { Sequelize } = require('sequelize');
|
const { Sequelize } = require('sequelize');
|
||||||
|
|
||||||
// @desc Create new bookmark
|
// @desc Create new bookmark
|
||||||
// @route POST /api/bookmarks
|
// @route POST /api/bookmarks
|
||||||
// @access Public
|
// @access Public
|
||||||
exports.createBookmark = asyncWrapper(async (req, res, next) => {
|
exports.createBookmark = asyncWrapper(async (req, res, next) => {
|
||||||
|
const pinBookmarks = await Config.findOne({
|
||||||
|
where: { key: 'pinBookmarksByDefault' }
|
||||||
|
});
|
||||||
|
|
||||||
let bookmark;
|
let bookmark;
|
||||||
|
|
||||||
let _body = {
|
let _body = {
|
||||||
...req.body,
|
...req.body,
|
||||||
categoryId: parseInt(req.body.categoryId),
|
categoryId: parseInt(req.body.categoryId),
|
||||||
|
isPinned = (pinBookmarks && parseInt(pinBookmarks.value)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
|
@ -30,10 +36,24 @@ exports.createBookmark = asyncWrapper(async (req, res, next) => {
|
||||||
// @route GET /api/bookmarks
|
// @route GET /api/bookmarks
|
||||||
// @access Public
|
// @access Public
|
||||||
exports.getBookmarks = asyncWrapper(async (req, res, next) => {
|
exports.getBookmarks = asyncWrapper(async (req, res, next) => {
|
||||||
const bookmarks = await Bookmark.findAll({
|
// Get config from database
|
||||||
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']],
|
const useOrdering = await Config.findOne({
|
||||||
|
where: { key: 'useOrdering' }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const orderType = useOrdering ? useOrdering.value : 'createdAt';
|
||||||
|
let bookmarks;
|
||||||
|
|
||||||
|
if (orderType == 'name') {
|
||||||
|
bookmarks = await Bookmark.findAll({
|
||||||
|
order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
bookmarks = await Bookmark.findAll({
|
||||||
|
order: [[ orderType, 'ASC' ]]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
data: bookmarks,
|
data: bookmarks,
|
||||||
|
@ -102,8 +122,24 @@ exports.updateBookmark = asyncWrapper(async (req, res, next) => {
|
||||||
// @access Public
|
// @access Public
|
||||||
exports.deleteBookmark = asyncWrapper(async (req, res, next) => {
|
exports.deleteBookmark = asyncWrapper(async (req, res, next) => {
|
||||||
await Bookmark.destroy({
|
await Bookmark.destroy({
|
||||||
where: { id: req.params.id },
|
where: { id: req.params.id }
|
||||||
});
|
})
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: {}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// @desc Reorder bookmarks
|
||||||
|
// @route PUT /api/bookmarks/0/reorder
|
||||||
|
// @access Public
|
||||||
|
exports.reorderBookmarks = asyncWrapper(async (req, res, next) => {
|
||||||
|
req.body.bookmarks.forEach(async ({ id, orderId }) => {
|
||||||
|
await Bookmark.update({ orderId }, {
|
||||||
|
where: { id }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
@ -17,6 +17,15 @@ const Bookmark = sequelize.define('Bookmark', {
|
||||||
icon: {
|
icon: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
defaultValue: ''
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
isPinned: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
orderId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: null
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
tableName: 'bookmarks'
|
tableName: 'bookmarks'
|
||||||
|
|
|
@ -7,7 +7,8 @@ const {
|
||||||
getBookmarks,
|
getBookmarks,
|
||||||
getBookmark,
|
getBookmark,
|
||||||
updateBookmark,
|
updateBookmark,
|
||||||
deleteBookmark
|
deleteBookmark,
|
||||||
|
reorderBookmarks
|
||||||
} = require('../controllers/bookmark');
|
} = require('../controllers/bookmark');
|
||||||
|
|
||||||
router
|
router
|
||||||
|
@ -21,4 +22,8 @@ router
|
||||||
.put(upload, updateBookmark)
|
.put(upload, updateBookmark)
|
||||||
.delete(deleteBookmark);
|
.delete(deleteBookmark);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route('/0/reorder')
|
||||||
|
.put(reorderBookmarks);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
|
@ -24,6 +24,10 @@
|
||||||
"key": "pinAppsByDefault",
|
"key": "pinAppsByDefault",
|
||||||
"value": true
|
"value": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "pinBookmarksByDefault",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "pinCategoriesByDefault",
|
"key": "pinCategoriesByDefault",
|
||||||
"value": true
|
"value": true
|
||||||
|
@ -53,7 +57,7 @@
|
||||||
"value": false
|
"value": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "hideCategories",
|
"key": "hideBookmarks",
|
||||||
"value": false
|
"value": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue