Skip to content

Commit

Permalink
refactor: move interfaces & types to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonamente committed Dec 20, 2021
1 parent b0de1f9 commit b600fc8
Show file tree
Hide file tree
Showing 25 changed files with 678 additions and 682 deletions.
43 changes: 5 additions & 38 deletions christmas-task-part1/src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,11 @@
import { IToy, Data, data } from './data';
import renderPage from './renders/page-render';
import toysData from './toysData.json';

import { IState } from './types';

import renderPage from './renders/page-render';
import createCountSLider from './sliders/count-slider';
import createYearSlider from './sliders/year-slider';

interface IValueFilters {
[key: string]: Record<string, boolean>;
}

export interface IState {
activePage: string;

searchInput: string;
uiState: {
searchedToys: Set<IToy[]>;
};

valueFilter: IValueFilters;

rangeFilters: {
countFilter: {
initMin: number;
initMax: number;
min: number;
max: number;
};
yearFilter: {
initMin: number;
initMax: number;
min: number;
max: number;
};
};

sortingType: string;
toys: Data;
filteredAndSortedToys: Set<IToy[]>;
favoritesIds: Set<number>;
}

export const favoritesMaxCount = 20;

export const app = () => {
Expand Down Expand Up @@ -92,7 +59,7 @@ export const app = () => {
},

sortingType: 'name-ascending',
toys: [...data],
toys: toysData,
filteredAndSortedToys: new Set(),
favoritesIds: new Set(),
};
Expand Down
4 changes: 2 additions & 2 deletions christmas-task-part1/src/app/builders/cards/card.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IToy } from '../../data';
import { IState, favoritesMaxCount } from '../../app';
import { IToy, IState } from '../../types';
import { favoritesMaxCount } from '../../app';
import setLocalStorage from '../../utils/set-local-storage';

const buildCard = (state: IState, toy: IToy): Node => {
Expand Down
3 changes: 2 additions & 1 deletion christmas-task-part1/src/app/builders/cards/cards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IState } from '../../app';
import { IState } from '../../types';

import buildCard from './card';
import getFilteredItems from '../../utils/filter';
import getSortedItems from '../../utils/sorter';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IState } from '../../app';
import { IState } from '../../types';

const buildRangeFilters = (state: IState): Node => {
const rangeSection = document.createElement('section');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IState } from '../../app';
import { IState } from '../../types';

import createCountSLider from '../../sliders/count-slider';
import createYearSlider from '../../sliders/year-slider';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IState } from '../../../app';
import { IState } from '../../../types';

const buildHtmlForFormElement = (state: IState): string => {
const { valueFilter } = state;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IState } from '../../../app';
import { IState } from '../../../types';
import setLocalStorage from '../../../utils/set-local-storage';
import buildHtmlForFormElement from './form';
import renderCards from '../../../renders/render-cards';
Expand Down
2 changes: 1 addition & 1 deletion christmas-task-part1/src/app/builders/header.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IState } from '../app';
import { IState } from '../types';
import getSearchedItems from '../utils/search-filter';
import renderSearchedCards from '../renders/render-searched-cards';

Expand Down
2 changes: 1 addition & 1 deletion christmas-task-part1/src/app/builders/page-content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IState } from '../app';
import { IState } from '../types';
import buildToysPageContent from '../pages/toys-page/toys-page';

const buildPageContent = (state: IState): Node => {
Expand Down
Loading

0 comments on commit b600fc8

Please sign in to comment.