From fce27471ab66572a5ce84e0505f5f710043f1192 Mon Sep 17 00:00:00 2001 From: yawhn Date: Fri, 24 Feb 2023 13:58:45 +0200 Subject: [PATCH] fix: multiple Ads' bugs. feat: Ads widget https://codeberg.org/calckey/calckey/issues/9138 https://codeberg.org/calckey/calckey/issues/9080 --- .../client/src/components/global/MkAd.vue | 15 ++++++----- .../client/src/pages/admin/promotions.vue | 26 +++++++++---------- packages/client/src/ui/classic.widgets.vue | 13 +++++----- .../client/src/ui/deck/widgets-column.vue | 16 ++++++------ packages/client/src/ui/universal.widgets.vue | 12 ++++----- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/packages/client/src/components/global/MkAd.vue b/packages/client/src/components/global/MkAd.vue index 0316a6bdf..7fa015266 100644 --- a/packages/client/src/components/global/MkAd.vue +++ b/packages/client/src/components/global/MkAd.vue @@ -56,10 +56,13 @@ const choseAd = (): Ad | null => { } const lowPriorityAds = ads.filter(ad => ad.ratio === 0); + const widgetAds = ads.filter(ad => ad.place === 'widget'); ads = ads.filter(ad => ad.ratio !== 0); - - if (ads.length === 0) { - if (lowPriorityAds.length !== 0) { + + if (widgetAds.length !== 0) { + return widgetAds; + } else if (ads.length === 0) { + if (lowPriorityAds.length !== 0) { return lowPriorityAds[Math.floor(Math.random() * lowPriorityAds.length)]; } else { return null; @@ -132,7 +135,7 @@ function reduceFrequency(): void { } } - &.square { + &.widget { > a , > a > img { max-width: min(300px, 100%); @@ -140,7 +143,7 @@ function reduceFrequency(): void { } } - &.horizontal { + &.inline { padding: 8px; > a , @@ -150,7 +153,7 @@ function reduceFrequency(): void { } } - &.horizontal-big { + &.inline-big { padding: 8px; > a , diff --git a/packages/client/src/pages/admin/promotions.vue b/packages/client/src/pages/admin/promotions.vue index 09b7bd542..d2e57586e 100644 --- a/packages/client/src/pages/admin/promotions.vue +++ b/packages/client/src/pages/admin/promotions.vue @@ -13,20 +13,12 @@ - - - + + + - - + @@ -56,23 +48,29 @@ import FormSplit from '@/components/form/split.vue'; import * as os from '@/os'; import { i18n } from '@/i18n'; import { definePageMetadata } from '@/scripts/page-metadata'; +import { formatDateTimeString } from '@/scripts/format-time-string'; let ads: any[] = $ref([]); os.api('admin/ad/list').then(adsResponse => { ads = adsResponse; + // The date format should be changed to yyyy-MM-dd in order to be properly displayed + for (let i in ads) { + ads[i].expiresAt = ads[i].expiresAt.substr(0, 10); + } }); function add() { + const tomorrow = formatDateTimeString(new Date(new Date().setDate(new Date().getDate() + 1)), 'yyyy-MM-dd'); ads.unshift({ id: null, memo: '', - place: 'square', + place: 'widget', priority: 'middle', ratio: 1, url: '', imageUrl: null, - expiresAt: null, + expiresAt: tomorrow, }); } diff --git a/packages/client/src/ui/classic.widgets.vue b/packages/client/src/ui/classic.widgets.vue index 04ca34b55..3ed838d9f 100644 --- a/packages/client/src/ui/classic.widgets.vue +++ b/packages/client/src/ui/classic.widgets.vue @@ -1,11 +1,10 @@