This commit is contained in:
2026-05-23 03:50:54 +09:00
parent 7b6b24b9c5
commit 7fcfc8b8aa
10 changed files with 55 additions and 23 deletions
+10 -7
View File
@@ -12,21 +12,24 @@ import { msToTime } from '@/lib/utils'
import type { FC, FormEvent } from 'react'
import type { Post, Tag } from '@/types'
import type { Post, TagWithSections } from '@/types'
const tagsToStr = (tags: Tag[]): string => {
const result: Tag[] = []
const tagsToStr = (tags: TagWithSections[]): string => {
const result: Omit<TagWithSections, 'children'>[] = []
const walk = (tag: Tag) => {
const walk = (tag: TagWithSections) => {
const { children, ...rest } = tag
result.push (rest)
children?.forEach (walk)
children.forEach (walk)
}
tags.filter (t => t.category !== 'nico').forEach (walk)
return [...(new Set (result.map (t => `${ t.name }${ t.sections.map (s => `[${ msToTime (s.beginMs) }-${ msToTime (s.endMs) }]`).join ('') }`)))].join (' ')
return [...(new Set (result.map (t =>
`${ t.name }${ t.sections
.map (s => `[${ msToTime (s.beginMs) }-${ msToTime (s.endMs) }]`)
.join ('') }`)))].join (' ')
}
@@ -118,7 +121,7 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
}
useEffect (() => {
setTags(tagsToStr (post.tags))
setTags (tagsToStr (post.tags))
}, [post])
return (
+8 -8
View File
@@ -26,13 +26,13 @@ import { dateString, originalCreatedAtString } from '@/lib/utils'
import type { DragEndEvent } from '@dnd-kit/core'
import type { FC, MutableRefObject, ReactNode } from 'react'
import type { Category, Post, Tag } from '@/types'
import type { Category, Post, TagWithSections } from '@/types'
type TagByCategory = { [key in Category]: Tag[] }
type TagByCategory = { [key in Category]: TagWithSections[] }
const renderTagTree = (
tag: Tag,
tag: TagWithSections,
nestLevel: number,
path: string,
suppressClickRef: MutableRefObject<boolean>,
@@ -63,7 +63,7 @@ const renderTagTree = (
const isDescendant = (
root: Tag,
root: TagWithSections,
targetId: number,
): boolean => {
if (!(root.children))
@@ -84,8 +84,8 @@ const isDescendant = (
const findTag = (
byCat: TagByCategory,
id: number,
): Tag | undefined => {
const walk = (nodes: Tag[]): Tag | undefined => {
): TagWithSections | undefined => {
const walk = (nodes: TagWithSections[]): TagWithSections | undefined => {
for (const t of nodes)
{
if (t.id === id)
@@ -167,7 +167,7 @@ const TagDetailSidebar: FC<Props> = ({ post, sp }) => {
}
for (const cat of Object.keys (tagsTmp) as (keyof typeof tagsTmp)[])
tagsTmp[cat].sort ((tagA: Tag, tagB: Tag) => tagA.name < tagB.name ? -1 : 1)
tagsTmp[cat].sort ((tagA: TagWithSections, tagB: TagWithSections) => tagA.name < tagB.name ? -1 : 1)
return tagsTmp
}, [post])
@@ -378,4 +378,4 @@ const TagDetailSidebar: FC<Props> = ({ post, sp }) => {
</SidebarComponent>)
}
export default TagDetailSidebar
export default TagDetailSidebar
+1 -1
View File
@@ -77,7 +77,7 @@ export const msToTime = (ms: number): string => {
const totalS = Math.trunc (ms / 1_000)
const s = String (totalS % 60)
const min = String (Math.trunc (totalS / 60) % 60)
const h = String (Math.trunc (totalS / 3_600))
const h = Math.trunc (totalS / 3_600)
return (h > 0
? `${ h }:${ min.padStart (2, '0') }:${ s.padStart (2, '0') }`
+1 -1
View File
@@ -157,4 +157,4 @@ const TagDetailPage: FC = () => {
</MainArea>)
}
export default TagDetailPage
export default TagDetailPage
+4 -2
View File
@@ -1,6 +1,6 @@
import type { Material, Post, Tag, User, WikiPage } from '@/types'
import type { Material, Post, TagWithSections, User, WikiPage } from '@/types'
export const buildTag = (overrides: Partial<Tag> = {}): Tag => ({
export const buildTag = (overrides: Partial<TagWithSections> = {}): TagWithSections => ({
id: 1,
name: 'テストタグ',
category: 'general',
@@ -13,6 +13,8 @@ export const buildTag = (overrides: Partial<Tag> = {}): Tag => ({
materialId: null,
hasDeerjikists: false,
matchedAlias: null,
sections: [],
children: [],
...overrides,
})