diff --git a/src/components/dashboard/dashboard.functions.ts b/src/components/dashboard/dashboard.functions.ts index 43971ad..e794a2b 100644 --- a/src/components/dashboard/dashboard.functions.ts +++ b/src/components/dashboard/dashboard.functions.ts @@ -1,9 +1,21 @@ -export const toHTML = () => /* html */ ` +import localStorageFn from '@src/helpers/localStorage'; +import { IRootState } from '@src/store/store.types'; + +export const toHTML = (key: string) => { + const model = localStorageFn(key); + const id = key.split(':')[1]; + + if (!model) { + return ''; + } + + return /* html */ `
  • - Таблица №1 + ${model.title} 12.06.2023
  • `; +}; export const getAllKeys = () => { const keys = []; diff --git a/src/components/header/Header.ts b/src/components/header/Header.ts index a24ed53..d1baac2 100644 --- a/src/components/header/Header.ts +++ b/src/components/header/Header.ts @@ -1,10 +1,11 @@ import { DEFAULT_TITLE } from '@src/consts/consts'; import $, { Dom } from '@src/core/dom/dom'; import ExcelComponent from '@src/core/excelComponent/ExcelComponent'; +import ActiveRoute from '@src/core/routes/ActiveRoute'; import debounce from '@src/helpers/debounce'; import { changeTitle } from '@src/store/actions'; import { IComponentOptions } from '@src/types/components'; -import { IInputEvent } from '@src/types/general'; +import { IButtonEvent, IInputEvent } from '@src/types/general'; interface IHeader {} @@ -14,7 +15,7 @@ class Header extends ExcelComponent implements IHeader { constructor($root: Dom, options: IComponentOptions) { super($root, { name: 'Header', - listeners: ['input'], + listeners: ['input', 'click'], ...options, }); } @@ -30,11 +31,11 @@ class Header extends ExcelComponent implements IHeader {
    - -
    @@ -45,6 +46,24 @@ class Header extends ExcelComponent implements IHeader { const $target = $(event.target); this.$dispatch(changeTitle($target.text())); } + + onClick(event: IButtonEvent) { + const $target = $(event.target); + + if ($target.data?.button === 'remove') { + // eslint-disable-next-line + const decision = confirm('Вы действительно хотите удалить таблицу?'); + + if (decision) { + localStorage.removeItem(`excel:${ActiveRoute.param}`); + ActiveRoute.navigate(''); + } + } + + if ($target.data?.button === 'exit') { + ActiveRoute.navigate(''); + } + } } export default Header; diff --git a/src/core/routes/ActiveRoute.ts b/src/core/routes/ActiveRoute.ts index d470b1f..ef1953c 100644 --- a/src/core/routes/ActiveRoute.ts +++ b/src/core/routes/ActiveRoute.ts @@ -20,6 +20,10 @@ class ActiveRoute { static get param() { return ActiveRoute.path.split('/')[1]; } + + static navigate(path: string) { + window.location.hash = path; + } } export default ActiveRoute; diff --git a/src/types/general.ts b/src/types/general.ts index 2c02d17..8ae9619 100644 --- a/src/types/general.ts +++ b/src/types/general.ts @@ -4,6 +4,10 @@ export interface IDivClickEvent extends MouseEvent { target: HTMLDivElement; } -export interface IInputEvent extends InputEvent { +export interface IInputEvent extends MouseEvent { target: HTMLInputElement; } + +export interface IButtonEvent extends MouseEvent { + target: HTMLButtonElement; +}