From 42e9f306e84120ba51d9b527c7868148730bf892 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Tue, 15 Nov 2022 17:25:52 +0100 Subject: [PATCH] feat: grid for list cards --- cypress/e2e/list/list-history.spec.ts | 2 +- src/components/list/partials/ListCard.vue | 176 ++++++++++++++ src/components/list/partials/ListCardGrid.vue | 77 ++++++ src/components/list/partials/list-card.vue | 226 ------------------ .../list/partials/useListBackground.ts | 55 +++++ src/services/list.ts | 6 +- src/styles/common-imports.scss | 6 +- src/views/Home.vue | 24 +- src/views/namespaces/ListNamespaces.vue | 53 ++-- 9 files changed, 340 insertions(+), 285 deletions(-) create mode 100644 src/components/list/partials/ListCard.vue create mode 100644 src/components/list/partials/ListCardGrid.vue delete mode 100644 src/components/list/partials/list-card.vue create mode 100644 src/components/list/partials/useListBackground.ts diff --git a/cypress/e2e/list/list-history.spec.ts b/cypress/e2e/list/list-history.spec.ts index b7633cbda..4f614ea01 100644 --- a/cypress/e2e/list/list-history.spec.ts +++ b/cypress/e2e/list/list-history.spec.ts @@ -45,7 +45,7 @@ describe('List History', () => { cy.get('body') .should('contain', 'Last viewed') - cy.get('.list-cards-wrapper-2-rows') + cy.get('[data-cy="listCardGrid"]') .should('not.contain', lists[0].title) .should('contain', lists[1].title) .should('contain', lists[2].title) diff --git a/src/components/list/partials/ListCard.vue b/src/components/list/partials/ListCard.vue new file mode 100644 index 000000000..ca7484b3d --- /dev/null +++ b/src/components/list/partials/ListCard.vue @@ -0,0 +1,176 @@ + + + + + \ No newline at end of file diff --git a/src/components/list/partials/ListCardGrid.vue b/src/components/list/partials/ListCardGrid.vue new file mode 100644 index 000000000..9f357dc59 --- /dev/null +++ b/src/components/list/partials/ListCardGrid.vue @@ -0,0 +1,77 @@ + + + + + \ No newline at end of file diff --git a/src/components/list/partials/list-card.vue b/src/components/list/partials/list-card.vue deleted file mode 100644 index 27f68c442..000000000 --- a/src/components/list/partials/list-card.vue +++ /dev/null @@ -1,226 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/components/list/partials/useListBackground.ts b/src/components/list/partials/useListBackground.ts new file mode 100644 index 000000000..24375d628 --- /dev/null +++ b/src/components/list/partials/useListBackground.ts @@ -0,0 +1,55 @@ +import {ref, watch, type Ref} from 'vue' +import ListService from '@/services/list' +import type {IList} from '@/modelTypes/IList' +import {getBlobFromBlurHash} from '@/helpers/getBlobFromBlurHash' + +export function useListBackground(list: Ref) { + const background = ref(null) + const backgroundLoading = ref(false) + const blurHashUrl = ref('') + + watch( + () => [list.value.id, list.value.backgroundBlurHash] as [IList['id'], IList['backgroundBlurHash']], + async ([listId, blurHash], oldValue) => { + if ( + list.value === null || + !list.value.backgroundInformation || + backgroundLoading.value + ) { + return + } + + const [oldListId, oldBlurHash] = oldValue || [] + if ( + oldValue !== undefined && + listId === oldListId && blurHash === oldBlurHash + ) { + // list hasn't changed + return + } + + backgroundLoading.value = true + + try { + const blurHashPromise = getBlobFromBlurHash(blurHash).then((blurHash) => { + blurHashUrl.value = blurHash ? window.URL.createObjectURL(blurHash) : '' + }) + + const listService = new ListService() + const backgroundPromise = listService.background(list.value).then((result) => { + background.value = result + }) + await Promise.all([blurHashPromise, backgroundPromise]) + } finally { + backgroundLoading.value = false + } + }, + { immediate: true }, + ) + + return { + background, + blurHashUrl, + backgroundLoading, + } +} \ No newline at end of file diff --git a/src/services/list.ts b/src/services/list.ts index f14272fbf..1d353de76 100644 --- a/src/services/list.ts +++ b/src/services/list.ts @@ -39,8 +39,8 @@ export default class ListService extends AbstractService { return list } - async background(list) { - if (list.background === null) { + async background(list: Pick) { + if (list.backgroundInformation === null) { return '' } @@ -52,7 +52,7 @@ export default class ListService extends AbstractService { return window.URL.createObjectURL(new Blob([response.data])) } - async removeBackground(list) { + async removeBackground(list: Pick) { const cancel = this.setLoading() try { diff --git a/src/styles/common-imports.scss b/src/styles/common-imports.scss index 002745792..02f824c45 100644 --- a/src/styles/common-imports.scss +++ b/src/styles/common-imports.scss @@ -32,8 +32,4 @@ $switch-view-height: 2.69rem; $navbar-height: 4rem; $navbar-width: 300px; -$navbar-icon-width: 40px; - -$lists-per-row: 5; -$list-height: 150px; -$list-spacing: 1rem; \ No newline at end of file +$navbar-icon-width: 40px; \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index b55952c2a..72377fd29 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -40,17 +40,11 @@

{{ $t('home.lastViewed') }}

-
- -
+
@@ -61,7 +55,7 @@ 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 ListCardGrid from '@/components/list/partials/ListCardGrid.vue' import AddTask from '@/components/tasks/add-task.vue' import {getHistory} from '@/modules/listHistory' @@ -113,14 +107,8 @@ function updateTaskList() { } - \ No newline at end of file diff --git a/src/views/namespaces/ListNamespaces.vue b/src/views/namespaces/ListNamespaces.vue index 046a9de44..fb5e1a454 100644 --- a/src/views/namespaces/ListNamespaces.vue +++ b/src/views/namespaces/ListNamespaces.vue @@ -15,28 +15,28 @@ -

+

{{ $t('namespace.noneAvailable') }} - + {{ $t('namespace.create.title') }}. - +

{{ $t('list.create.header') }} {{ $t('namespace.unarchive') }} @@ -44,26 +44,22 @@

{{ getNamespaceTitle(n) }} - + {{ $t('namespace.archived') }}

-

+

{{ $t('namespace.noLists') }} - + {{ $t('namespace.createList') }} - +

-
- -
+
@@ -72,8 +68,9 @@ import {computed} from 'vue' import {useI18n} from 'vue-i18n' +import BaseButton from '@/components/base/BaseButton.vue' import Fancycheckbox from '@/components/input/fancycheckbox.vue' -import ListCard from '@/components/list/partials/list-card.vue' +import ListCardGrid from '@/components/list/partials/ListCardGrid.vue' import {getNamespaceTitle} from '@/helpers/getNamespaceTitle' import {useTitle} from '@/composables/useTitle' @@ -89,11 +86,10 @@ const showArchived = useStorage('showArchived', false) const loading = computed(() => namespaceStore.isLoading) const namespaces = computed(() => { - return namespaceStore.namespaces.filter(n => showArchived.value ? true : !n.isArchived) - // return namespaceStore.namespaces.filter(n => showArchived.value ? true : !n.isArchived).map(n => { - // n.lists = n.lists.filter(l => !l.isArchived) - // return n - // }) + return namespaceStore.namespaces.filter(namespace => showArchived.value + ? true + : !namespace.isArchived, + ) }) @@ -121,10 +117,8 @@ const namespaces = computed(() => { } } -.namespace { - & + & { - margin-top: 1rem; - } +.namespace:not(:first-child) { + margin-top: 1rem; } .namespace-title { @@ -142,9 +136,4 @@ const namespaces = computed(() => { background: var(--white-translucent); margin-left: .5rem; } - -.lists { - display: flex; - flex-flow: row wrap; -} \ No newline at end of file