From e2ac132fb097798fc6bde8d988985c7d929d552b Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Thu, 26 Jun 2025 14:02:08 +0800 Subject: [PATCH] extract announcement card as component --- next-ui/.storybook/StoryWrapper.vue | 4 ++ next-ui/src/components.d.ts | 1 + .../components/announcement/Card.stories.ts | 66 +++++++++++++++++++ next-ui/src/components/announcement/Card.vue | 64 ++++++++++++++++++ next-ui/src/pages/server/announcements.vue | 56 ++-------------- 5 files changed, 140 insertions(+), 51 deletions(-) create mode 100644 next-ui/src/components/announcement/Card.stories.ts create mode 100644 next-ui/src/components/announcement/Card.vue diff --git a/next-ui/.storybook/StoryWrapper.vue b/next-ui/.storybook/StoryWrapper.vue index 2659d78c..9ece9c85 100644 --- a/next-ui/.storybook/StoryWrapper.vue +++ b/next-ui/.storybook/StoryWrapper.vue @@ -15,3 +15,7 @@ export default { }, } + + diff --git a/next-ui/src/components.d.ts b/next-ui/src/components.d.ts index e122b8c2..8d92a267 100644 --- a/next-ui/src/components.d.ts +++ b/next-ui/src/components.d.ts @@ -8,6 +8,7 @@ export {} /* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { + AnnouncementCard: typeof import('./components/announcement/Card.vue')['default'] AppFooter: typeof import('./components/AppFooter.vue')['default'] DialogConfirm: typeof import('./components/dialog/Confirm.vue')['default'] DialogConfirmEdit: typeof import('./components/dialog/ConfirmEdit.vue')['default'] diff --git a/next-ui/src/components/announcement/Card.stories.ts b/next-ui/src/components/announcement/Card.stories.ts new file mode 100644 index 00000000..5d206ee4 --- /dev/null +++ b/next-ui/src/components/announcement/Card.stories.ts @@ -0,0 +1,66 @@ +import type { Meta, StoryObj } from '@storybook/vue3-vite' + +import Card from './Card.vue' +import { expect, fn } from 'storybook/test' + +const meta = { + component: Card, + render: (args: object) => ({ + components: { Card }, + setup() { + return { args } + }, + template: '', + }), + parameters: { + // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout + }, + args: { + onMarkRead: fn(), + }, +} satisfies Meta + +export default meta +type Story = StoryObj + +export const Unread: Story = { + args: { + item: { + id: 'https://komga.org/blog/ebook-drop2', + url: 'https://komga.org/blog/ebook-drop2', + title: 'eBook drop 2', + summary: 'Version 1.9.0 contains the second feature drop for Ebooks support.', + content_html: + '

Version 1.9.0 contains the second feature drop for Ebooks support.

\n

It brings nice additions to the initial release, most notably the read progress will be kept when reading and restored, same as with other books.

\n

The analysis process of EPUB files was also revamped, and some EPUB files that were not analyzed before should be working fine now.

\n

While the first release forced all the EPUB files through the Epub Reader, this release brings back compatibility with the Divina Reader for pre-paginated EPUB files containing only images. This also restores support for the Pages API, and thus the compatibility with Tachiyomi, or any OPDS-PSE client.

\n

Head over to the Release Notes for more details on all the new features and fixes.

', + date_modified: new Date('2023-12-15T00:00:00Z'), + author: { + name: 'gotson', + url: 'https://github.com/gotson', + }, + tags: ['upgrade', 'komga'], + _komga: { + read: false, + }, + }, + }, + play: async ({ args, canvas, userEvent }) => { + await expect(canvas.getByRole('button')).toBeEnabled() + + await userEvent.click(canvas.getByRole('button')) + await expect(args.onMarkRead).toHaveBeenCalledWith(args.item.id) + }, +} + +export const Read: Story = { + args: { + item: { + ...Unread.args?.item, + _komga: { + read: true, + }, + }, + }, + play: async ({ canvas }) => { + await expect(canvas.getByRole('button')).toBeDisabled() + }, +} diff --git a/next-ui/src/components/announcement/Card.vue b/next-ui/src/components/announcement/Card.vue new file mode 100644 index 00000000..5357da86 --- /dev/null +++ b/next-ui/src/components/announcement/Card.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/next-ui/src/pages/server/announcements.vue b/next-ui/src/pages/server/announcements.vue index 6e9504cd..49a75e55 100644 --- a/next-ui/src/pages/server/announcements.vue +++ b/next-ui/src/pages/server/announcements.vue @@ -16,43 +16,11 @@ v-for="(item, index) in announcements.items" :key="index" > - - - - - - - - +
- - meta: requiresRole: ADMIN