Skip to content

Commit 688094d

Browse files
committed
Refactor the whole structure
1 parent d75f262 commit 688094d

17 files changed

+3887
-2730
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"lint": "vue-cli-service lint"
77
},
88
"devDependencies": {
9-
"@vue/cli-plugin-babel": "^3.0.4",
10-
"@vue/cli-plugin-eslint": "^3.0.4",
11-
"@vue/cli-service": "^3.0.4",
12-
"@vue/eslint-config-standard": "^3.0.4",
13-
"@vuex-orm/core": "^0.31.12",
14-
"normalize.css": "^8.0.0",
15-
"postcss-css-variables": "^0.10.0",
16-
"postcss-import": "^12.0.0",
17-
"postcss-nested": "^4.1.0",
18-
"vue": "^2.5.17",
19-
"vue-template-compiler": "^2.5.17",
9+
"@vue/cli-plugin-babel": "^3.9.2",
10+
"@vue/cli-plugin-eslint": "^3.9.2",
11+
"@vue/cli-service": "^3.9.3",
12+
"@vue/eslint-config-standard": "^4.0.0",
13+
"@vuex-orm/core": "^0.32.0",
14+
"normalize.css": "^8.0.1",
15+
"postcss-css-variables": "^0.13.0",
16+
"postcss-import": "^12.0.1",
17+
"postcss-nested": "^4.1.2",
18+
"vue": "^2.6.10",
19+
"vue-template-compiler": "^2.6.10",
2020
"vuex": "^3.1.1"
2121
}
2222
}

src/components/App.vue

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22
<div class="App">
33
<AppHeader />
44

5-
<Description />
5+
<AppDescription />
66

77
<div class="container">
8-
<div class="users"><Users /></div>
9-
<div class="todos"><Todos /></div>
8+
<div class="users"><UsersSection /></div>
9+
<div class="todos"><TodosSection /></div>
1010
</div>
1111

1212
<AppFooter />
1313
</div>
1414
</template>
1515

1616
<script>
17-
import data from '../data'
18-
import store from '../store'
17+
import data from '@/data'
18+
import store from '@/store'
19+
import Todo from '@/models/Todo'
1920
import AppHeader from './AppHeader'
20-
import Description from './Description'
21-
import Users from './Users'
22-
import Todos from './Todos'
21+
import AppDescription from './AppDescription'
22+
import UsersSection from './UsersSection'
23+
import TodosSection from './TodosSection'
2324
import AppFooter from './AppFooter'
2425
2526
export default {
2627
store,
2728
2829
components: {
2930
AppHeader,
30-
Description,
31-
Users,
32-
Todos,
31+
AppDescription,
32+
UsersSection,
33+
TodosSection,
3334
AppFooter
3435
},
3536
@@ -44,11 +45,7 @@ export default {
4445
// should be the response from the API Backend.
4546
const initialData = data
4647
47-
this.$store.dispatch('entities/todos/create', { data: initialData })
48-
},
49-
50-
mounted () {
51-
this.$store.dispatch('entities/users/test')
48+
Todo.insert({ data: initialData })
5249
}
5350
}
5451
</script>
File renamed without changes.

src/components/TodosList.vue renamed to src/components/TodoList.vue

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,55 @@
22
<div class="TodosList">
33
<div class="todo" :class="{ done: todo.done }" :key="todo.id" v-for="todo in todos">
44
<button class="icon" @click="toggle(todo)">
5-
<CheckCircle class="svg check" />
5+
<IconCheckCircle class="svg check" />
66
</button>
77

88
<input
99
class="input"
1010
:value="todo.title"
1111
placeholder="Type in the title of the task!"
12-
@input="e => { update(todo.id, e.target.value) }"
12+
@input="e => { update(todo, e.target.value) }"
1313
>
1414

15-
<Assignee :todoId="todo.id" />
15+
<TodoListAssignee :todoId="todo.id" />
1616

17-
<button class="icon" @click="destroy(todo.id)">
18-
<Trash class="svg" />
17+
<button class="icon" @click="destroy(todo)">
18+
<IconTrash class="svg" />
1919
</button>
2020
</div>
2121
</div>
2222
</template>
2323

2424
<script>
25-
import CheckCircle from './icons/CheckCircle'
26-
import Trash from './icons/Trash'
27-
import Assignee from './TodosAssignee'
25+
import Todo from '@/models/Todo'
26+
import IconCheckCircle from './icons/IconCheckCircle'
27+
import IconTrash from './icons/IconTrash'
28+
import TodoListAssignee from './TodoListAssignee'
2829
2930
export default {
3031
components: {
31-
CheckCircle,
32-
Trash,
33-
Assignee
32+
IconCheckCircle,
33+
IconTrash,
34+
TodoListAssignee
3435
},
3536
3637
computed: {
3738
todos () {
38-
return this.$store.getters['entities/todos/query']().orderBy('id', 'desc').get()
39+
return Todo.query().orderBy('id', 'desc').get()
3940
}
4041
},
4142
4243
methods: {
4344
toggle (todo) {
44-
this.$store.dispatch('entities/todos/update', { id: todo.id, done: !todo.done })
45+
todo.$update({ done: !todo.done })
4546
},
4647
47-
update (id, title) {
48-
this.$store.dispatch('entities/todos/update', { id, title })
48+
update (todo, title) {
49+
todo.$update({ title })
4950
},
5051
51-
destroy (id) {
52-
this.$store.dispatch('entities/todos/delete', id)
52+
destroy (todo) {
53+
todo.$delete()
5354
}
5455
}
5556
}

src/components/TodosAssignee.vue renamed to src/components/TodoListAssignee.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="TodosAssignee">
3-
<User class="user" />
3+
<IconUser class="user" />
44

55
<select class="select" :class="{ selected: !!todo.assignee }" @change="update">
66
<option class="option" value="">Choose assignee</option>
@@ -15,18 +15,20 @@
1515
</option>
1616
</select>
1717

18-
<ChevronDown class="down" />
18+
<IconChevronDown class="down" />
1919
</div>
2020
</template>
2121

2222
<script>
23-
import User from './icons/User'
24-
import ChevronDown from './icons/ChevronDown'
23+
import User from '@/models/User'
24+
import Todo from '@/models/Todo'
25+
import IconUser from './icons/IconUser'
26+
import IconChevronDown from './icons/IconChevronDown'
2527
2628
export default {
2729
components: {
28-
User,
29-
ChevronDown
30+
IconUser,
31+
IconChevronDown
3032
},
3133
3234
props: {
@@ -35,17 +37,17 @@ export default {
3537
3638
computed: {
3739
users () {
38-
return this.$store.getters['entities/users/query']().orderBy('name').get()
40+
return User.query().orderBy('name').get()
3941
},
4042
4143
todo () {
42-
return this.$store.getters['entities/todos/query']().with('assignee').find(this.todoId)
44+
return Todo.query().with('assignee').find(this.todoId)
4345
}
4446
},
4547
4648
methods: {
4749
update (e) {
48-
this.$store.dispatch('entities/todos/update', {
50+
Todo.update({
4951
id: this.todoId,
5052
user_id: e.target.value
5153
})

src/components/Todos.vue renamed to src/components/TodosSection.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
<button class="button" @click="add">ADD TODO</button>
77
</div>
88

9-
<TodosList />
9+
<TodoList />
1010
</div>
1111
</section>
1212
</template>
1313

1414
<script>
15-
import TodosList from './TodosList'
15+
import Todo from '@/models/Todo'
16+
import TodoList from './TodoList'
1617
1718
export default {
1819
components: {
19-
TodosList
20+
TodoList
2021
},
2122
2223
methods: {
2324
add () {
24-
this.$store.dispatch('entities/todos/insert', {
25+
Todo.insert({
2526
data: { title: '' }
2627
})
2728
}

src/components/UsersList.vue renamed to src/components/UserList.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,40 @@
55
class="input"
66
:value="user.name"
77
placeholder="Type in user's name!"
8-
@input="e => { update(user.id, e.target.value) }"
8+
@input="e => { update(user, e.target.value) }"
99
>
1010

1111
<p class="tasks">{{ user.todos.length }} Tasks</p>
1212

13-
<button class="icon" @click="destroy(user.id)">
14-
<Trash class="trash" />
13+
<button class="icon" @click="destroy(user)">
14+
<IconTrash class="trash" />
1515
</button>
1616
</div>
1717
</div>
1818
</template>
1919

2020
<script>
21-
import Trash from './icons/Trash'
21+
import User from '@/models/User'
22+
import IconTrash from './icons/IconTrash'
2223
2324
export default {
2425
components: {
25-
Trash
26+
IconTrash
2627
},
2728
2829
computed: {
2930
users () {
30-
return this.$store.getters['entities/users/query']().with('todos').orderBy('id', 'desc').get()
31+
return User.query().with('todos').orderBy('id', 'desc').get()
3132
}
3233
},
3334
3435
methods: {
35-
update (id, name) {
36-
this.$store.dispatch('entities/users/update', { id, name })
36+
update (user, name) {
37+
user.$update({ name })
3738
},
3839
39-
destroy (id) {
40-
this.$store.dispatch('entities/users/delete', id)
40+
destroy (user) {
41+
user.$delete()
4142
}
4243
}
4344
}

src/components/Users.vue renamed to src/components/UsersSection.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
<button class="button" @click="add">ADD USER</button>
77
</div>
88

9-
<UsersList />
9+
<UserList />
1010
</div>
1111
</section>
1212
</template>
1313

1414
<script>
15-
import UsersList from './UsersList'
15+
import User from '@/models/User'
16+
import UserList from './UserList'
1617
1718
export default {
1819
components: {
19-
UsersList
20+
UserList
2021
},
2122
2223
methods: {
2324
add () {
24-
this.$store.dispatch('entities/users/insert', {
25+
User.insert({
2526
data: { name: '' }
2627
})
2728
}
File renamed without changes.
File renamed without changes.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Database } from '@vuex-orm/core'
22
import User from '@/models/User'
33
import Todo from '@/models/Todo'
4-
import users from './modules/users'
5-
import todos from './modules/todos'
64

75
const database = new Database()
86

9-
database.register(User, users)
10-
database.register(Todo, todos)
7+
database.register(User)
8+
database.register(Todo)
119

1210
export default database

src/store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33
import VuexORM from '@vuex-orm/core'
4-
import database from './database'
4+
import database from '@/database'
55

66
Vue.use(Vuex)
77

src/store/modules/todos.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/store/modules/users.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)