mirror of
https://github.com/DCsunset/taskwarrior-webui.git
synced 2025-08-19 06:53:06 +02:00
feat(frontend): add vuex
This commit is contained in:
parent
2cae14a40c
commit
a3ab682575
2 changed files with 49 additions and 0 deletions
36
frontend/store/index.ts
Normal file
36
frontend/store/index.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { ActionTree, MutationTree } from 'vuex';
|
||||
import { Task } from 'taskwarrior-lib';
|
||||
import { getAccessorType } from 'typed-vuex';
|
||||
|
||||
export const state = () => ({
|
||||
tasks: [] as Task[]
|
||||
});
|
||||
|
||||
export type RootState = ReturnType<typeof state>;
|
||||
|
||||
export const mutations: MutationTree<RootState> = {
|
||||
setTasks(state, tasks: Task[]) {
|
||||
state.tasks = tasks;
|
||||
}
|
||||
};
|
||||
|
||||
export const actions: ActionTree<RootState, RootState> = {
|
||||
async fetchTasks(context) {
|
||||
const tasks: Task[] = await this.$axios.$get('/api/tasks');
|
||||
context.commit('setTasks', tasks);
|
||||
},
|
||||
|
||||
async deleteTasks(context, tasks: Task[]) {
|
||||
await this.$axios.$delete('/api/tasks', {
|
||||
params: { tasks: tasks.map(task => task.uuid) }
|
||||
});
|
||||
const newTasks = context.state.tasks.filter(task => tasks.findIndex(t => t.uuid === task.uuid) === -1);
|
||||
context.commit('setTasks', newTasks);
|
||||
}
|
||||
};
|
||||
|
||||
export const accessorType = getAccessorType({
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
});
|
13
frontend/types/index.d.ts
vendored
Normal file
13
frontend/types/index.d.ts
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { accessorType } from '~/store';
|
||||
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
$accessor: typeof accessorType
|
||||
}
|
||||
}
|
||||
|
||||
declare module '@nuxt/types' {
|
||||
interface NuxtAppOptions {
|
||||
$accessor: typeof accessorType
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue