From 3ca6e58b7d80945520b32899708e9fdba9e92a0a Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 30 Nov 2018 16:34:05 +0100 Subject: [PATCH] Refact: Move date filtering into component --- src/store/modules/datas.js | 37 +++++----------------------- src/views/home.vue | 49 ++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/store/modules/datas.js b/src/store/modules/datas.js index d8cb0c6..5f193d7 100644 --- a/src/store/modules/datas.js +++ b/src/store/modules/datas.js @@ -3,16 +3,16 @@ import { readdir, readFile } from 'fs' import path from 'path' import Papa from 'papaparse' -var today = new Date() -var monthAgo = new Date() -monthAgo.setMonth(monthAgo.getMonth() - 1) - export default { namespaced: true, state: { csv_files: [], - rows: {}, - dates_boundaries: [monthAgo, today] + rows: { + data: [], + meta: { + fields: [] + } + }, }, getters: { csvs: (state) => { @@ -20,20 +20,7 @@ export default { }, rows: (state) => { return state.rows.data - }, - dates_boundaries: (state) => { - return state.dates_boundaries.map(x => x.toISOString().split('T')[0]) - }, - filter_rows: (state, getters) => { - if (state.rows.data) { - return state.rows.data.filter(x => { - return (new Date(x.Date) >= state.dates_boundaries[0]) & (new Date(x.Date) < state.dates_boundaries[1]) - }) - } else { - return [] - } } - }, mutations: { SET_CSV_FILES: (state, { csvs }) => { @@ -44,12 +31,6 @@ export default { }, APPEND_DATA: (state, { content }) => { state.rows.push(content) - }, - SET_START_DATE: (state, { start }) => { - Vue.set(state.dates_boundaries, 0, new Date(start)) - }, - SET_END_DATE: (state, { end }) => { - Vue.set(state.dates_boundaries, 1, new Date(end)) } }, actions: { @@ -84,12 +65,6 @@ export default { context.commit('SET_DATA', { data: parsed }) } }) - }, - set_start_date (context, start) { - context.commit('SET_START_DATE', { start }) - }, - set_end_date (context, end) { - context.commit('SET_END_DATE', { end }) } } } diff --git a/src/views/home.vue b/src/views/home.vue index d25d839..4d8d0e8 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -4,9 +4,9 @@ - + - + @@ -19,6 +19,10 @@