diff --git a/src/favicon.ico b/src/assets/favicon.ico similarity index 100% rename from src/favicon.ico rename to src/assets/favicon.ico diff --git a/src/components/excel/Excel.ts b/src/components/excel/Excel.ts index 6f070e8..414ef5f 100644 --- a/src/components/excel/Excel.ts +++ b/src/components/excel/Excel.ts @@ -1,8 +1,9 @@ import { Store } from 'core/createStore'; -import { $, Dom } from 'core/dom'; +import { $ } from 'core/dom'; import { Emitter } from 'core/Emitter'; import { ExcelComponent } from 'core/ExcelComponent'; import { StoreSubscriber } from 'core/StoreSubscriber'; +import { updateOpenDate } from 'redux/actions'; interface ExcelOptionsType { components: any[], @@ -10,7 +11,6 @@ interface ExcelOptionsType { } export class Excel { - $el: HTMLElement | Dom; components: any[]; emitter: Emitter; store: Store; @@ -47,6 +47,8 @@ export class Excel { init() { this.subscriber.subscribeComponents(this.components); this.components.forEach(component => component.init()); + + this.store.dispatch(updateOpenDate(Date.now().toString())); } destroy() { diff --git a/src/components/header/Header.ts b/src/components/header/Header.ts index 77e46cc..2f31819 100644 --- a/src/components/header/Header.ts +++ b/src/components/header/Header.ts @@ -1,5 +1,6 @@ import { $, Dom } from 'core/dom'; import { ExcelStateComponent } from 'core/ExcelStateComponent'; +import { ActiveRoute } from 'core/routes/ActiveRoute'; import { deleteTable } from 'redux/actions'; import * as actions from 'redux/actions'; @@ -48,14 +49,12 @@ export class Header extends ExcelStateComponent { switch (btnEvent) { case 'exit': { - window.location.hash = ''; + ActiveRoute.navigateTo = ''; break; } case 'delete-table': { - this.$dispatch(deleteTable(this.store.getState().id)); - console.log('THIS', this); - this.destroy(); + confirm('Действительно хочешь удалить ?') && this.$dispatch(deleteTable(this.store.getState().id)); break; } diff --git a/src/constants.ts b/src/constants.ts index d9824b3..5d0b15e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -19,5 +19,6 @@ export function getNormalizeInitialState(params: string): StateType { ...storage(`excel:${params}`), currentStyles: { ...storage(`excel:${params}`)?.stylesState?.['0:0'] }, id: params, + openDate: Date.now(), }; } diff --git a/src/core/ExcelComponent.ts b/src/core/ExcelComponent.ts index f18f304..747ab2c 100644 --- a/src/core/ExcelComponent.ts +++ b/src/core/ExcelComponent.ts @@ -1,4 +1,4 @@ -import { ActionType, SubscribeType } from 'redux/types'; +import { ActionType } from 'redux/types'; import { Store } from './createStore'; import { Dom } from './dom'; import { DomListener } from './DomListener'; @@ -22,7 +22,6 @@ export abstract class ExcelComponent extends DomListener implements ExcelCompone name: string; emitter: Emitter; store: Store; - storeSub: SubscribeType; subscribe: string[]; private unsubscribers: ((args?: any) => any)[]; diff --git a/src/core/StoreSubscriber.ts b/src/core/StoreSubscriber.ts index a866ef6..d4096aa 100644 --- a/src/core/StoreSubscriber.ts +++ b/src/core/StoreSubscriber.ts @@ -15,6 +15,8 @@ export class StoreSubscriber { this.prevState = this.store.getState(); this.sub = this.store.subscribe((state: StateType) => { + if (!state) return; + Object.keys(state).forEach(key => { if (!isEqual(this.prevState[key], state[key])) { components.forEach(component => { diff --git a/src/core/routes/ActiveRoute.ts b/src/core/routes/ActiveRoute.ts index e477fdb..493be24 100644 --- a/src/core/routes/ActiveRoute.ts +++ b/src/core/routes/ActiveRoute.ts @@ -6,4 +6,8 @@ export class ActiveRoute { static get param() { return window.location.hash.split('/'); } + + static set navigateTo(path: string) { + window.location.hash = path; + } } diff --git a/src/index.html b/src/index.html index c070220..c3a0fe8 100644 --- a/src/index.html +++ b/src/index.html @@ -5,7 +5,7 @@ - +