Try moving utility functions to typescript
This commit is contained in:
parent
b812c422f9
commit
ef54485fdc
|
@ -54,6 +54,7 @@
|
||||||
"faker": "5.5.3",
|
"faker": "5.5.3",
|
||||||
"jest": "27.0.6",
|
"jest": "27.0.6",
|
||||||
"sass-loader": "10.2.0",
|
"sass-loader": "10.2.0",
|
||||||
|
"typescript": "^4.3.5",
|
||||||
"vue-flatpickr-component": "8.1.7",
|
"vue-flatpickr-component": "8.1.7",
|
||||||
"vue-notification": "1.3.20",
|
"vue-notification": "1.3.20",
|
||||||
"vue-router": "3.5.2",
|
"vue-router": "3.5.2",
|
||||||
|
@ -112,4 +113,4 @@
|
||||||
],
|
],
|
||||||
"testEnvironment": "jsdom"
|
"testEnvironment": "jsdom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ import {CURRENT_LIST, LOADING, LOADING_MODULE, QUICK_ACTIONS_ACTIVE} from '@/sto
|
||||||
import ListModel from '@/models/list'
|
import ListModel from '@/models/list'
|
||||||
import createTask from '@/components/tasks/mixins/createTask'
|
import createTask from '@/components/tasks/mixins/createTask'
|
||||||
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic'
|
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic'
|
||||||
import {getHistory} from '@/modules/listHistory'
|
import {getHistory} from '../../modules/listHistory'
|
||||||
|
|
||||||
const TYPE_LIST = 'list'
|
const TYPE_LIST = 'list'
|
||||||
const TYPE_TASK = 'task'
|
const TYPE_TASK = 'task'
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
interface ListHistory {
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHistory(): ListHistory[] {
|
||||||
|
const savedHistory = localStorage.getItem('listHistory')
|
||||||
|
if (savedHistory === null) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.parse(savedHistory)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveListToHistory(list: ListHistory) {
|
||||||
|
const history = getHistory()
|
||||||
|
|
||||||
|
// list.id = parseInt(list.id)
|
||||||
|
|
||||||
|
// Remove the element if it already exists in history, preventing duplicates and essentially moving it to the beginning
|
||||||
|
history.forEach((l, i) => {
|
||||||
|
if (l.id === list.id) {
|
||||||
|
history.splice(i, 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add the new list to the beginning of the list
|
||||||
|
history.unshift(list)
|
||||||
|
|
||||||
|
if (history.length > 5) {
|
||||||
|
history.pop()
|
||||||
|
}
|
||||||
|
localStorage.setItem('listHistory', JSON.stringify(history))
|
||||||
|
}
|
|
@ -46,7 +46,7 @@
|
||||||
<script>
|
<script>
|
||||||
import {mapState} from 'vuex'
|
import {mapState} from 'vuex'
|
||||||
import ShowTasks from './tasks/ShowTasks'
|
import ShowTasks from './tasks/ShowTasks'
|
||||||
import {getHistory} from '@/modules/listHistory'
|
import {getHistory} from '../modules/listHistory'
|
||||||
import ListCard from '@/components/list/partials/list-card'
|
import ListCard from '@/components/list/partials/list-card'
|
||||||
import AddTask from '../components/tasks/add-task'
|
import AddTask from '../components/tasks/add-task'
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ import ListModel from '../../models/list'
|
||||||
import ListService from '../../services/list'
|
import ListService from '../../services/list'
|
||||||
import {CURRENT_LIST} from '@/store/mutation-types'
|
import {CURRENT_LIST} from '@/store/mutation-types'
|
||||||
import {getListView} from '@/helpers/saveListView'
|
import {getListView} from '@/helpers/saveListView'
|
||||||
import {saveListToHistory} from '@/modules/listHistory'
|
import {saveListToHistory} from '../../modules/listHistory'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"strict": true,
|
||||||
|
"module": "es2015",
|
||||||
|
"moduleResolution": "node"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
|
}
|
|
@ -13152,6 +13152,11 @@ typedarray@^0.0.6:
|
||||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||||
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
||||||
|
|
||||||
|
typescript@^4.3.5:
|
||||||
|
version "4.3.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
|
||||||
|
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
|
||||||
|
|
||||||
typescript@~4.1.5:
|
typescript@~4.1.5:
|
||||||
version "4.1.5"
|
version "4.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.5.tgz#123a3b214aaff3be32926f0d8f1f6e704eb89a72"
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.5.tgz#123a3b214aaff3be32926f0d8f1f6e704eb89a72"
|
||||||
|
|
Reference in New Issue