This repository was archived by the owner on Feb 17, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 管理者からのお知らせ コンポーネントを実装した #77
Open
laminne
wants to merge
9
commits into
main
Choose a base branch
from
feat/76-announce
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−2
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c071a3
feat: impl relative-time component
laminne 132a519
feat: impl announce component
laminne a5a9ca3
feat: add i18n strings
laminne 0bd2dc6
chore: format code
laminne a92e90e
fix: icon size
laminne 4a64344
feat: remove fragments
laminne 7f01fd8
fix: export some component props interface
laminne 2d1aabb
Merge branch 'main' into feat/76-announce
laminne dc5626e
Merge branch 'main' into feat/76-announce
laminne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react"; | ||
|
|
||
| import { Announce } from "./Announce"; | ||
|
|
||
| const meta = { | ||
| component: Announce | ||
| } satisfies Meta<typeof Announce>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| announceType: "warn", | ||
| title: "定期メンテナンスのお知らせ", | ||
| body: "以下の日時に定期メンテナンスを行います", | ||
| updatedAt: new Date("2023-09-10T00:00:00Z") | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { IconButton, Text, ThickCheckIcon, Tooltip } from "@radix-ui/themes"; | ||
| import styles from "./announce.module.css"; | ||
| import { t } from "i18next"; | ||
| import { Time } from "~/components/Time"; | ||
| import { | ||
| ExclamationTriangleIcon, | ||
| InfoCircledIcon | ||
| } from "@radix-ui/react-icons"; | ||
|
|
||
| export interface AnnounceProps { | ||
| announceType: "warn" | "info"; | ||
| title: string; | ||
| body: string; | ||
| updatedAt: Date; | ||
| } | ||
|
|
||
| export const Announce = ({ | ||
| announceType, | ||
| title, | ||
| body, | ||
| updatedAt | ||
| }: AnnounceProps) => { | ||
| return ( | ||
| <div> | ||
| <div className={styles.announceTitleContainer}> | ||
| <div className={styles.announceTitle}> | ||
| <Tooltip | ||
| content={t( | ||
| announceType === "warn" ? "announce.warn" : "announce.info" | ||
| )} | ||
| > | ||
| {announceType === "warn" ? ( | ||
| <ExclamationTriangleIcon className={styles.announceIcon} /> | ||
| ) : ( | ||
| <InfoCircledIcon className={styles.announceIcon} /> | ||
| )} | ||
| </Tooltip> | ||
| <Text as="p" size="5" weight="medium"> | ||
| {title} | ||
| </Text> | ||
| </div> | ||
| <Tooltip content={t("notification.read")}> | ||
| <IconButton variant="outline"> | ||
| <ThickCheckIcon className={styles.readButtonIcon} /> | ||
| </IconButton> | ||
| </Tooltip> | ||
| </div> | ||
|
|
||
| <p>{body}</p> | ||
|
|
||
| <Text size="2" color="gray"> | ||
| <Time date={updatedAt} /> | ||
| </Text> | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react"; | ||
|
|
||
| import { Time } from "./Time"; | ||
|
|
||
| const meta = { | ||
| component: Time | ||
| } satisfies Meta<typeof Time>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| date: new Date() | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| export interface TimeProps { | ||
| date: Date; | ||
| } | ||
|
|
||
| const timeFormatter = new Intl.DateTimeFormat(); | ||
| const relativeTimeFormatter = new Intl.RelativeTimeFormat(undefined, { | ||
| style: "short" | ||
| }); | ||
|
|
||
| const Millisecond = 1 as const; | ||
| const SECOND = Millisecond * 1000; | ||
| const MINUTE = SECOND * 60; | ||
| const HOUR = MINUTE * 60; | ||
| const DAY = HOUR * 24; | ||
|
|
||
| const getRelativeTimeDiff = (date: Date, now = new Date()) => { | ||
| const diffMilliseconds = now.getTime() - date.getTime(); | ||
| const absDiff = Math.abs(diffMilliseconds); | ||
|
|
||
| if (absDiff < MINUTE) { | ||
| const diffSeconds = Math.floor(diffMilliseconds / SECOND); | ||
| return relativeTimeFormatter.format(-diffSeconds, "second"); | ||
| } else if (absDiff < HOUR) { | ||
| const diffMinutes = Math.floor(diffMilliseconds / MINUTE); | ||
| return relativeTimeFormatter.format(-diffMinutes, "minute"); | ||
| } else if (absDiff < DAY) { | ||
| const diffHours = Math.floor(diffMilliseconds / HOUR); | ||
| return relativeTimeFormatter.format(-diffHours, "hour"); | ||
| } | ||
|
|
||
| const diffDays = Math.floor(diffMilliseconds / DAY); | ||
| if (Math.abs(diffDays) < 30) { | ||
| return relativeTimeFormatter.format(-diffDays, "day"); | ||
| } | ||
|
|
||
| const diffMonths = Math.floor(diffDays / 30); | ||
| if (Math.abs(diffMonths) < 12) { | ||
| return relativeTimeFormatter.format(-diffMonths, "month"); | ||
| } | ||
|
|
||
| const diffYears = Math.floor(diffMonths / 12); | ||
| return relativeTimeFormatter.format(-diffYears, "year"); | ||
| }; | ||
|
|
||
| export const Time = ({ date }: TimeProps) => { | ||
| const formattedDate = timeFormatter.format(date); | ||
| const formattedRelativeDate = getRelativeTimeDiff(date); | ||
|
|
||
| return ( | ||
| <p> | ||
| {formattedDate} ({formattedRelativeDate}) | ||
| </p> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .announceTitleContainer { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
|
|
||
| .announceIcon { | ||
| width: 1.5rem; | ||
| height: 1.5rem; | ||
| margin-right: .5rem; | ||
| } | ||
|
|
||
| .readButtonIcon { | ||
| width: .8rem; | ||
| height: .8rem; | ||
| } | ||
|
|
||
| .announceTitle { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| } | ||
|
|
||
| margin-bottom: .5em; | ||
|
|
||
| p { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.