Skip to content

Commit

Permalink
feat: add open date for table
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKazarinov committed Jun 19, 2024
1 parent df7712f commit 066fdca
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/dashboard/dashboard.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const toHTML = (key: string) => {
return /* html */ `
<li class="dashboard__record">
<a href="#excel/${id}" class="dashboard__link"> ${model.title} </a>
<strong class="dashboard__create-date">12.06.2023</strong>
<strong class="dashboard__create-date">
${new Date(model.dateTable).toLocaleDateString()} ${new Date(model.dateTable).toLocaleTimeString()}
</strong>
</li>
`;
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/excel/Excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IExcelComponent } from '@src/core/excelComponent/ExcelComponent';
import Observer from '@src/core/observer/Observer';
import StoreSubscriber from '@src/core/storeSubscriber/StoreSubscriber';
import { TActions } from '@src/store/action.types';
import { updateDate } from '@src/store/actions';
import { IReturnCreateStore, IRootState } from '@src/store/store.types';

interface IExcelOptions<T> {
Expand Down Expand Up @@ -49,6 +50,7 @@ class Excel<T extends IExcelComponent> {
}

init() {
this.store.dispatch(updateDate());
this.subscriber.subscribeComponents(this.objectComponents);
this.objectComponents.forEach((component) => {
component.init();
Expand Down
5 changes: 5 additions & 0 deletions src/store/action.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ export interface IChangeTitle {
payload: string;
}

export interface IUpdateDate {
readonly type: 'UPDATE_DATE';
}

export type TTableActions =
| ITableResizeActionCreator
| IChangeTextActionCreator
| IApplyStyle
| ICurrentStyles
| IChangeTitle
| IUpdateDate
| { type: '__INIT__'; payload: any };

export type TActions = TTableActions;
5 changes: 5 additions & 0 deletions src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IChangeTitle,
ICurrentStyles,
ITableResizeActionCreator,
IUpdateDate,
} from './action.types';

export const tableResizeActionCreator = (data: ITableResize): ITableResizeActionCreator => ({
Expand All @@ -32,3 +33,7 @@ export const changeTitle = (data: string): IChangeTitle => ({
type: 'CHANGE_TITLE',
payload: data,
});

export const updateDate = (): IUpdateDate => ({
type: 'UPDATE_DATE',
});
1 change: 1 addition & 0 deletions src/store/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const defaultState: IRootState = {
currentText: '',
currentStyles: initialToolbarState,
title: DEFAULT_TITLE,
dateTable: new Date().toJSON(),
};

const localStorageState = localStorageFn<IRootState>(EXCEL_STATE);
Expand Down
3 changes: 3 additions & 0 deletions src/store/rootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const rootReducer = (state: IRootState, action: TActions): IRootState => {
case 'CHANGE_TITLE':
return { ...state, title: action.payload };

case 'UPDATE_DATE':
return { ...state, dateTable: new Date().toJSON() };

default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions src/store/store.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface IRootState {
currentText: string;
currentStyles: IToolbarState;
title: string;
dateTable: string;
}

0 comments on commit 066fdca

Please sign in to comment.