2018-09-06 19:46:38 +02:00
|
|
|
<template>
|
2018-09-09 16:22:02 +02:00
|
|
|
<div class="content has-text-centered">
|
2021-01-17 20:53:09 +01:00
|
|
|
<h2>
|
2021-07-06 17:13:13 +02:00
|
|
|
{{ $t(`home.welcome${welcome}`, {username: userInfo.name !== '' ? userInfo.name : userInfo.username}) }}!
|
2021-01-17 20:53:09 +01:00
|
|
|
</h2>
|
2021-07-17 23:21:46 +02:00
|
|
|
<add-task
|
|
|
|
:listId="defaultListId"
|
|
|
|
@taskAdded="updateTaskList"
|
|
|
|
class="is-max-width-desktop"
|
|
|
|
/>
|
2021-08-06 19:25:17 +02:00
|
|
|
<template v-if="!hasTasks && !loading">
|
|
|
|
<template v-if="defaultNamespaceId > 0">
|
|
|
|
<p class="mt-4">{{ $t('home.list.newText') }}</p>
|
|
|
|
<x-button
|
|
|
|
:to="{ name: 'list.create', params: { id: defaultNamespaceId } }"
|
|
|
|
:shadow="false"
|
|
|
|
class="ml-2"
|
|
|
|
>
|
|
|
|
{{ $t('home.list.new') }}
|
|
|
|
</x-button>
|
|
|
|
</template>
|
2021-01-17 20:53:09 +01:00
|
|
|
<p class="mt-4" v-if="migratorsEnabled">
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('home.list.importText') }}
|
2021-01-17 20:53:09 +01:00
|
|
|
</p>
|
2021-04-15 17:21:20 +02:00
|
|
|
<x-button
|
|
|
|
v-if="migratorsEnabled"
|
|
|
|
:to="{ name: 'migrate.start' }"
|
|
|
|
:shadow="false">
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('home.list.import') }}
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
2020-06-15 18:47:17 +02:00
|
|
|
</template>
|
2021-07-06 22:22:57 +02:00
|
|
|
<div v-if="listHistory.length > 0" class="is-max-width-desktop has-text-left">
|
|
|
|
<h3>{{ $t('home.lastViewed') }}</h3>
|
|
|
|
<div class="is-flex list-cards-wrapper-2-rows">
|
|
|
|
<list-card
|
|
|
|
v-for="(l, k) in listHistory"
|
|
|
|
:key="`l${k}`"
|
|
|
|
:list="l"
|
|
|
|
:background-resolver="() => null"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-17 23:21:46 +02:00
|
|
|
<ShowTasks :show-all="true" v-if="hasLists" :key="showTasksKey"/>
|
2018-09-06 19:46:38 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-06-24 01:24:57 +02:00
|
|
|
import {mapState} from 'vuex'
|
2021-07-25 15:27:15 +02:00
|
|
|
import ShowTasks from './tasks/ShowTasks.vue'
|
2021-07-19 20:20:49 +02:00
|
|
|
import {getHistory} from '../modules/listHistory'
|
2021-07-25 15:27:15 +02:00
|
|
|
import ListCard from '@/components/list/partials/list-card.vue'
|
|
|
|
import AddTask from '../components/tasks/add-task.vue'
|
2021-08-06 19:25:17 +02:00
|
|
|
import {LOADING, LOADING_MODULE} from '../store/mutation-types'
|
2018-09-06 19:46:38 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'Home',
|
|
|
|
components: {
|
2021-07-06 22:22:57 +02:00
|
|
|
ListCard,
|
2020-09-05 22:35:52 +02:00
|
|
|
ShowTasks,
|
2021-07-17 23:21:46 +02:00
|
|
|
AddTask,
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
currentDate: new Date(),
|
|
|
|
tasks: [],
|
2021-07-17 23:21:46 +02:00
|
|
|
showTasksKey: 0,
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
2021-07-06 17:13:13 +02:00
|
|
|
computed: {
|
|
|
|
welcome() {
|
|
|
|
const now = new Date()
|
|
|
|
|
|
|
|
if (now.getHours() < 5) {
|
|
|
|
return 'Night'
|
2021-01-17 20:53:09 +01:00
|
|
|
}
|
|
|
|
|
2021-07-06 22:22:57 +02:00
|
|
|
if (now.getHours() < 11) {
|
2021-07-06 17:13:13 +02:00
|
|
|
return 'Morning'
|
|
|
|
}
|
|
|
|
|
2021-07-06 22:22:57 +02:00
|
|
|
if (now.getHours() < 18) {
|
2021-07-06 17:13:13 +02:00
|
|
|
return 'Day'
|
2021-01-17 20:53:09 +01:00
|
|
|
}
|
|
|
|
|
2021-07-06 22:22:57 +02:00
|
|
|
if (now.getHours() < 23) {
|
2021-07-06 17:13:13 +02:00
|
|
|
return 'Evening'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Night'
|
2021-01-17 20:53:09 +01:00
|
|
|
},
|
2021-07-06 22:22:57 +02:00
|
|
|
listHistory() {
|
|
|
|
const history = getHistory()
|
|
|
|
return history.map(l => {
|
|
|
|
return this.$store.getters['lists/getListById'](l.id)
|
2021-07-20 18:03:38 +02:00
|
|
|
}).filter(l => l !== null)
|
2021-07-06 22:22:57 +02:00
|
|
|
},
|
2021-07-06 17:13:13 +02:00
|
|
|
...mapState({
|
2021-07-17 23:21:46 +02:00
|
|
|
migratorsEnabled: state =>
|
|
|
|
state.config.availableMigrators !== null &&
|
|
|
|
state.config.availableMigrators.length > 0,
|
2021-07-06 17:13:13 +02:00
|
|
|
authenticated: state => state.auth.authenticated,
|
|
|
|
userInfo: state => state.auth.info,
|
|
|
|
hasTasks: state => state.hasTasks,
|
2021-07-17 23:21:46 +02:00
|
|
|
defaultListId: state => state.auth.defaultListId,
|
2021-07-06 17:13:13 +02:00
|
|
|
defaultNamespaceId: state => {
|
|
|
|
if (state.namespaces.namespaces.length === 0) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return state.namespaces.namespaces[0].id
|
|
|
|
},
|
|
|
|
hasLists: state => {
|
|
|
|
if (state.namespaces.namespaces.length === 0) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return state.namespaces.namespaces[0].lists.length > 0
|
|
|
|
},
|
2021-08-06 19:25:17 +02:00
|
|
|
loading: state => state[LOADING] && state[LOADING_MODULE] === 'tasks',
|
2021-07-06 17:13:13 +02:00
|
|
|
}),
|
2021-07-17 23:21:46 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// This is to reload the tasks list after adding a new task through the global task add.
|
|
|
|
// FIXME: Should use vuex (somehow?)
|
|
|
|
updateTaskList() {
|
|
|
|
this.showTasksKey++
|
|
|
|
},
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
2018-09-06 19:46:38 +02:00
|
|
|
</script>
|