diff --git a/todolist-app-5-v2/src/App.vue b/todolist-app-5-v2/src/App.vue index 72ccdf2..637233b 100644 --- a/todolist-app-5-v2/src/App.vue +++ b/todolist-app-5-v2/src/App.vue @@ -8,14 +8,14 @@ diff --git a/todolist-app-5-v2/src/components/Navbar.vue b/todolist-app-5-v2/src/components/Navbar.vue index 14bb6a4..9be009d 100644 --- a/todolist-app-5-v2/src/components/Navbar.vue +++ b/todolist-app-5-v2/src/components/Navbar.vue @@ -1,23 +1,129 @@ \ No newline at end of file diff --git a/todolist-app-5-v2/src/components/Tasks.vue b/todolist-app-5-v2/src/components/Tasks.vue new file mode 100644 index 0000000..f45ae42 --- /dev/null +++ b/todolist-app-5-v2/src/components/Tasks.vue @@ -0,0 +1,271 @@ + + + + + \ No newline at end of file diff --git a/todolist-app-5-v2/src/directives/markdown.js b/todolist-app-5-v2/src/directives/markdown.js new file mode 100644 index 0000000..4bf21eb --- /dev/null +++ b/todolist-app-5-v2/src/directives/markdown.js @@ -0,0 +1,28 @@ +const rules = [ + [/^#{6}\s?(.*$)/gim, '
$1
'], // ###### ->
+ [/^#{5}\s?(.*$)/gim, '
$1
'], // ##### ->
+ [/^#{4}\s?(.*$)/gim, '

$1

'], // #### ->

+ [/^#{3}\s?(.*$)/gim, '

$1

'], // ### ->

+ [/^#{2}\s?(.*$)/gim, '

$1

'], // ## ->

+ [/^#{1}\s?(.*$)/gim, '

$1

'], // # ->

+ [/(\*\*|__)(.*)(\*\*|__)/gim, '$2'], // ** X ** | __ X __ -> + [/(\*|_)(.*)(\*|_)/gim, '$2'], // * X * | _ X _ -> + // [/((\n\d\..+)+)/g, '
    $1
'], + // [/((\n\*.+)+)/g, '
    $1
'], + // [/\n\d\.([^\n]+)/g, '
  • $1
  • '], + // [/^\*([^\n]+)/g, '
  • $1
  • '], + // [/^(\*|\+|-) .*$/g, '
  • $1
  • '], + [/!\[(.*?)\]\((.*?)\)/gim, "$1"], // ![]() -> + [/\[(.*?)\]\((.*?)\)/gim, "$1"], // []() -> + [/^\> (.*$)/gim, '
    $1
    '], // > X ->
    + //[/\n$/gim, '
    '], + [/([^\n]+\n)/g, '

    $1

    '], // \n ->

    +]; + +export default { + mounted(el) { + let html = el.textContent; + rules.forEach(([rule, template]) => html = html.replace(rule, template)) + el.innerHTML = html.trim(); + } +} \ No newline at end of file diff --git a/todolist-app-5-v2/src/main.js b/todolist-app-5-v2/src/main.js index 3bc5611..f7bb54d 100644 --- a/todolist-app-5-v2/src/main.js +++ b/todolist-app-5-v2/src/main.js @@ -2,7 +2,8 @@ import {createApp} from 'vue' import App from './App.vue' import router from './router' import store from './store' +import markdown from './directives/markdown.js' import 'materialize-css/dist/js/materialize.min' import './registerServiceWorker' -createApp(App).use(store).use(router).mount('#app') +createApp(App).use(store).use(router).directive('markdown', markdown).mount('#app') diff --git a/todolist-app-5-v2/src/router/index.js b/todolist-app-5-v2/src/router/index.js index 0d5116f..c2e3346 100644 --- a/todolist-app-5-v2/src/router/index.js +++ b/todolist-app-5-v2/src/router/index.js @@ -2,19 +2,24 @@ import { createRouter, createWebHashHistory } from 'vue-router' const routes = [ { - path: '/', - name: 'create', - component: () => import('@/views/Create.vue') + path: '/list/:id', + name: 'list', + component: () => import('@/views/List.vue') }, { - path: '/list', - name: 'list', + path: '/all-tasks/', + name: 'all-tasks', component: () => import('@/views/List.vue') }, + { + path: '/', + name: 'unselect', + component: () => import('@/views/ListNotSelected.vue') + }, { path: '/task/:id', name: 'task', - component: () => import('@/views/Task.vue') + component: () => import('@/views/EditTask.vue') } ] @@ -23,31 +28,4 @@ const router = createRouter({ routes }) -export default router - -// import Vue from 'vue' -// import Router from 'vue-router' - -// Vue.use(Router) - -// export default new Router({ -// mode: 'history', -// base: process.env.BASE_URL, -// routes: [ -// { -// path: '/', -// name: 'create', -// component: () => import('@/views/Create.vue') -// }, -// { -// path: '/list', -// name: 'list', -// component: () => import('@/views/List.vue') -// }, -// { -// path: '/task/:id', -// name: 'task', -// component: () => import('@/views/Task.vue') -// } -// ] -// }) +export default router \ No newline at end of file diff --git a/todolist-app-5-v2/src/store/index.js b/todolist-app-5-v2/src/store/index.js index ffa7ef9..e4eb9bd 100644 --- a/todolist-app-5-v2/src/store/index.js +++ b/todolist-app-5-v2/src/store/index.js @@ -3,51 +3,131 @@ import { createStore } from 'vuex' export default createStore({ state: { tasks: JSON.parse(localStorage.getItem('tasks') || '[]').map(task => { - if (new Date(task.date) < new Date()) { - task.status = 'outdated'; + if (task.status == "active" && new Date(task.date) < new Date()) { + task.status = "outdated"; } return task; - }) + }), + lists: JSON.parse(localStorage.getItem('lists') || '[]'), + + icons: ["fiber_new", "monetization_on", "work", "assignment", "favorite", "add_shopping_cart"], + + // lists: [ + // { id: 1, title: "List 1", icon: "fiber_new", tasks: [1617574933864]}, + // { id: 2, title: "Finance", icon: "monetization_on", tasks: [1618331961444]}, + // { id: 3, title: "Work", icon: "work", tasks: [1617575867688, 1617574935120, 1618320657442]}, + // { id: 4, title: "Projects", icon: "assignment", tasks: [1618320657442]}, + // { id: 5, title: "Health", icon: "favorite", tasks: [1617574935120]}, + // { id: 6, title: "Shopping", icon: "add_shopping_cart", tasks: [1618331838965]}, + // ] }, mutations: { - createTask(state, task) { + createTask(state, {listId, task}) { state.tasks.push(task); + state.lists.find(l => l.id == listId).tasks.push(task.id); localStorage.setItem('tasks', JSON.stringify(state.tasks)); + localStorage.setItem('lists', JSON.stringify(state.lists)); }, - updateTask(state, {id, desc, date}) { - const tasks = state.tasks.concat(); - const idx = tasks.findIndex(t => t.id === id); - const task = tasks[idx]; + deleteTask(state, taskId) { + let tid = state.tasks.findIndex(t => t.id == taskId); + if (tid == -1) return; - const status = new Date(date) > new Date() ? 'active' : 'outdated'; + state.tasks.splice(tid,1); + localStorage.setItem('tasks', JSON.stringify(state.tasks)); + + let list = state.lists.find(l => l.tasks.includes(taskId)); + if (!list) return; - tasks[idx] = {...task, date, desc, status }; + tid = list.tasks.findIndex(id => id == taskId); + if (tid == -1) return; + + list.tasks.splice(tid,1); + localStorage.setItem('lists', JSON.stringify(state.lists)); + }, + updateTask(state, {id, title, desc, notesMD, status, isCompleted, tags, date }) { + const tasks = state.tasks.concat(); + const idx = tasks.findIndex(t => t.id === id); + if (idx == -1) return; + + const task = tasks[idx]; + tasks[idx] = {...task, title, desc, notesMD, status, isCompleted, tags, date }; state.tasks = tasks; localStorage.setItem('tasks', JSON.stringify(state.tasks)); }, - completeTask(state, id) { + + createList(state, list) { + list.icon = state.icons[Math.trunc(Math.random()*6)]; + state.lists.push(list); + localStorage.setItem('lists', JSON.stringify(state.lists)); + }, + + renameList(state, {id, title}) { + const idx = state.lists.findIndex(l => l.id == id); + if (idx == -1 || title.trim() === "") return; + + state.lists.find(l => l.id == id).title = title; + localStorage.setItem('lists', JSON.stringify(state.lists)); + }, + + deleteList(state, id) { + const idx = state.lists.findIndex(l => l.id == id); + if (idx == -1) return; + + state.lists.splice(idx,1); + localStorage.setItem('lists', JSON.stringify(state.lists)); + }, + + toggleCompleteStatus(state, id) { const idx = state.tasks.findIndex(t => t.id === id); + if (idx == -1) return; + + if (state.tasks[idx].status == "completed") { + state.tasks[idx].status = (new Date(state.tasks[idx].date) < new Date()) ? "outdated" : "active"; + } else { + state.tasks[idx].status = "completed"; + } - state.tasks[idx].status = 'completed'; + state.tasks[idx].isCompleted = !state.tasks[idx].isCompleted; localStorage.setItem('tasks', JSON.stringify(state.tasks)); } }, actions: { - createTask({commit}, task) { - commit('createTask', task); + createTask({commit}, {listId, task}) { + commit('createTask', {listId, task}); + }, + + deleteTask({commit}, taskId) { + commit('deleteTask', taskId); }, + updateTask({commit}, task) { commit('updateTask', task); }, - completeTask({commit}, id) { - commit('completeTask', id); + + createList({commit}, list) { + commit('createList', list); + }, + + renameList({commit}, {id, title}) { + commit('renameList', {id, title}); + }, + + deleteList({commit}, id) { + commit('deleteList', id); + }, + + toggleCompleteStatus({commit}, id) { + commit('toggleCompleteStatus', id); } }, getters: { tasks: s => s.tasks, - taskById: s=> id => s.tasks.find(t => t.id === id) + taskById: s => id => s.tasks.find(t => t.id == id), + tasksFromListId: (s, getters) => id => s.lists.find(l => l.id == id).tasks.map(i => getters.taskById(i)), + lists: s => s.lists, + listById: s => id => s.lists.find(l => l.id == id), } }) diff --git a/todolist-app-5-v2/src/views/Create.vue b/todolist-app-5-v2/src/views/Create.vue deleted file mode 100644 index 8083f40..0000000 --- a/todolist-app-5-v2/src/views/Create.vue +++ /dev/null @@ -1,76 +0,0 @@ - - - diff --git a/todolist-app-5-v2/src/views/EditTask.vue b/todolist-app-5-v2/src/views/EditTask.vue new file mode 100644 index 0000000..0377321 --- /dev/null +++ b/todolist-app-5-v2/src/views/EditTask.vue @@ -0,0 +1,164 @@ + + + + + \ No newline at end of file diff --git a/todolist-app-5-v2/src/views/List.vue b/todolist-app-5-v2/src/views/List.vue index 1fd1310..76f772e 100644 --- a/todolist-app-5-v2/src/views/List.vue +++ b/todolist-app-5-v2/src/views/List.vue @@ -1,82 +1,183 @@ \ No newline at end of file diff --git a/todolist-app-5-v2/src/views/ListNotSelected.vue b/todolist-app-5-v2/src/views/ListNotSelected.vue new file mode 100644 index 0000000..cc21886 --- /dev/null +++ b/todolist-app-5-v2/src/views/ListNotSelected.vue @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/todolist-app-5-v2/src/views/Task.vue b/todolist-app-5-v2/src/views/Task.vue deleted file mode 100644 index 482a651..0000000 --- a/todolist-app-5-v2/src/views/Task.vue +++ /dev/null @@ -1,83 +0,0 @@ - - - - - \ No newline at end of file diff --git a/todolist-app-5-v2/vue.config.js b/todolist-app-5-v2/vue.config.js deleted file mode 100644 index afcefef..0000000 --- a/todolist-app-5-v2/vue.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - publicPath: process.env.NODE_ENV === 'production' - ? './' - : 'http://localhost:8080/' -} \ No newline at end of file