|
@@ -1,5 +1,8 @@
|
|
import { ContentType } from '../Bookmarks';
|
|
import { ContentType } from '../Bookmarks';
|
|
import classes from './BookmarkTable.module.css';
|
|
import classes from './BookmarkTable.module.css';
|
|
|
|
+import { connect } from 'react-redux';
|
|
|
|
+import { pinCategory, deleteCategory } from '../../../store/actions';
|
|
|
|
+import { KeyboardEvent } from 'react';
|
|
|
|
|
|
import Table from '../../UI/Table/Table';
|
|
import Table from '../../UI/Table/Table';
|
|
import { Bookmark, Category } from '../../../interfaces';
|
|
import { Bookmark, Category } from '../../../interfaces';
|
|
@@ -8,9 +11,25 @@ import Icon from '../../UI/Icons/Icon/Icon';
|
|
interface ComponentProps {
|
|
interface ComponentProps {
|
|
contentType: ContentType;
|
|
contentType: ContentType;
|
|
categories: Category[];
|
|
categories: Category[];
|
|
|
|
+ pinCategory: (category: Category) => void;
|
|
|
|
+ deleteCategory: (id: number) => void;
|
|
}
|
|
}
|
|
|
|
|
|
const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
|
const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
|
|
|
+ const deleteCategoryHandler = (category: Category): void => {
|
|
|
|
+ const proceed = window.confirm(`Are you sure you want to delete ${category.name}? It will delete ALL assigned bookmarks`);
|
|
|
|
+
|
|
|
|
+ if (proceed) {
|
|
|
|
+ props.deleteCategory(category.id);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const keyboardActionHandler = (e: KeyboardEvent, category: Category, handler: Function) => {
|
|
|
|
+ if (e.key === 'Enter') {
|
|
|
|
+ handler(category);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (props.contentType === ContentType.category) {
|
|
if (props.contentType === ContentType.category) {
|
|
return (
|
|
return (
|
|
<Table headers={[
|
|
<Table headers={[
|
|
@@ -24,8 +43,8 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
|
<td className={classes.TableActions}>
|
|
<td className={classes.TableActions}>
|
|
<div
|
|
<div
|
|
className={classes.TableAction}
|
|
className={classes.TableAction}
|
|
- // onClick={() => deleteAppHandler(app)}
|
|
|
|
- // onKeyDown={(e) => keyboardActionHandler(e, app, deleteAppHandler)}
|
|
|
|
|
|
+ onClick={() => deleteCategoryHandler(category)}
|
|
|
|
+ onKeyDown={(e) => keyboardActionHandler(e, category, deleteCategoryHandler)}
|
|
tabIndex={0}>
|
|
tabIndex={0}>
|
|
<Icon icon='mdiDelete' />
|
|
<Icon icon='mdiDelete' />
|
|
</div>
|
|
</div>
|
|
@@ -38,8 +57,8 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
|
</div>
|
|
</div>
|
|
<div
|
|
<div
|
|
className={classes.TableAction}
|
|
className={classes.TableAction}
|
|
- // onClick={() => props.pinApp(app)}
|
|
|
|
- // onKeyDown={(e) => keyboardActionHandler(e, app, props.pinApp)}
|
|
|
|
|
|
+ onClick={() => props.pinCategory(category)}
|
|
|
|
+ onKeyDown={(e) => keyboardActionHandler(e, category, props.pinCategory)}
|
|
tabIndex={0}>
|
|
tabIndex={0}>
|
|
{category.isPinned
|
|
{category.isPinned
|
|
? <Icon icon='mdiPinOff' color='var(--color-accent)' />
|
|
? <Icon icon='mdiPinOff' color='var(--color-accent)' />
|
|
@@ -100,4 +119,4 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export default BookmarkTable;
|
|
|
|
|
|
+export default connect(null, { pinCategory, deleteCategory })(BookmarkTable);
|