vikunja-frontend/src/views/Home.vue

126 lines
3.8 KiB
Vue
Raw Normal View History

2018-09-06 17:46:38 +00:00
<template>
2018-09-09 14:22:02 +00:00
<div class="content has-text-centered">
2022-10-16 17:36:04 +00:00
<h2 v-if="salutation">{{ salutation }}</h2>
2021-12-12 11:00:24 +00:00
<message variant="danger" v-if="deletionScheduledAt !== null" class="mb-4">
{{
$t('user.deletion.scheduled', {
date: formatDateShort(deletionScheduledAt),
dateSince: formatDateSince(deletionScheduledAt),
})
}}
<router-link :to="{name: 'user.settings', hash: '#deletion'}">
{{ $t('user.deletion.scheduledCancel') }}
</router-link>
</message>
<add-task
@taskAdded="updateTaskList"
class="is-max-width-desktop"
/>
<template v-if="!hasTasks && !loading">
<template v-if="defaultNamespaceId > 0">
<p class="mt-4">{{ $t('home.list.newText') }}</p>
<x-button
2021-11-17 17:04:53 +00:00
:to="{ name: 'list.create', params: { namespaceId: defaultNamespaceId } }"
:shadow="false"
class="ml-2"
>
{{ $t('home.list.new') }}
</x-button>
</template>
<p class="mt-4" v-if="migratorsEnabled">
{{ $t('home.list.importText') }}
</p>
<x-button
v-if="migratorsEnabled"
:to="{ name: 'migrate.start' }"
:shadow="false">
{{ $t('home.list.import') }}
</x-button>
</template>
<div v-if="listHistory.length > 0" class="is-max-width-desktop has-text-left mt-4">
2021-07-06 20:22:57 +00:00
<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"
/>
</div>
</div>
<ShowTasks
v-if="hasLists"
class="mt-4"
:key="showTasksKey"
/>
2018-09-06 17:46:38 +00:00
</div>
</template>
<script lang="ts" setup>
import {ref, computed} from 'vue'
import Message from '@/components/misc/message.vue'
import ShowTasks from '@/views/tasks/ShowTasks.vue'
import ListCard from '@/components/list/partials/list-card.vue'
import AddTask from '@/components/tasks/add-task.vue'
import {getHistory} from '@/modules/listHistory'
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate'
import {useDaytimeSalutation} from '@/composables/useDaytimeSalutation'
2022-09-24 13:20:40 +00:00
import {useBaseStore} from '@/stores/base'
import {useListStore} from '@/stores/lists'
2022-09-21 00:21:22 +00:00
import {useConfigStore} from '@/stores/config'
2022-09-02 09:15:29 +00:00
import {useNamespaceStore} from '@/stores/namespaces'
2022-09-21 01:37:39 +00:00
import {useAuthStore} from '@/stores/auth'
2022-09-24 13:20:40 +00:00
import {useTaskStore} from '@/stores/tasks'
2022-10-17 11:14:07 +00:00
import type {IList} from '@/modelTypes/IList'
const salutation = useDaytimeSalutation()
2022-09-24 13:20:40 +00:00
const baseStore = useBaseStore()
2022-09-21 01:37:39 +00:00
const authStore = useAuthStore()
2022-09-21 00:21:22 +00:00
const configStore = useConfigStore()
2022-09-02 09:15:29 +00:00
const namespaceStore = useNamespaceStore()
const listStore = useListStore()
2022-09-24 13:20:40 +00:00
const taskStore = useTaskStore()
const listHistory = computed(() => {
// If we don't check this, it tries to load the list background right after logging out
2022-09-21 01:37:39 +00:00
if(!authStore.authenticated) {
return []
}
return getHistory()
.map(l => listStore.getListById(l.id))
2022-10-17 11:14:07 +00:00
.filter((l): l is IList => l !== null)
})
2022-09-21 00:21:22 +00:00
const migratorsEnabled = computed(() => configStore.availableMigrators?.length > 0)
2022-09-24 13:20:40 +00:00
const hasTasks = computed(() => baseStore.hasTasks)
2022-09-02 09:15:29 +00:00
const defaultNamespaceId = computed(() => namespaceStore.namespaces?.[0]?.id || 0)
const hasLists = computed(() => namespaceStore.namespaces?.[0]?.lists.length > 0)
2022-09-24 13:20:40 +00:00
const loading = computed(() => taskStore.isLoading)
2022-09-21 01:37:39 +00:00
const deletionScheduledAt = computed(() => parseDateOrNull(authStore.info?.deletionScheduledAt))
// This is to reload the tasks list after adding a new task through the global task add.
2022-09-24 13:20:40 +00:00
// FIXME: Should use pinia (somehow?)
const showTasksKey = ref(0)
function updateTaskList() {
showTasksKey.value++
}
2018-09-06 17:46:38 +00:00
</script>
<style lang="scss" scoped>
.list-cards-wrapper-2-rows {
flex-wrap: wrap;
max-height: calc(#{$list-height * 2} + #{$list-spacing * 2} - 4px);
overflow: hidden;
@media screen and (max-width: $mobile) {
max-height: calc(#{$list-height * 4} + #{$list-spacing * 4} - 4px);
}
}
</style>