Browse Source

#28

pull/244/head
みてるぞ 2 weeks ago
parent
commit
9a4fef21a6
4 changed files with 18 additions and 9 deletions
  1. +7
    -0
      frontend/src/components/TagLink.tsx
  2. +2
    -1
      frontend/src/components/TagSearch.tsx
  3. +2
    -2
      frontend/src/components/TagSearchBox.tsx
  4. +7
    -6
      frontend/src/types.ts

+ 7
- 0
frontend/src/components/TagLink.tsx View File

@@ -91,6 +91,13 @@ export default (({ tag,
style={{ paddingLeft: `${ (nestLevel - 1) }rem` }}>
</span>)}
{tag.matchedAlias != null && (
<>
<span className={spanClass} {...props}>
{tag.matchedAlias}
</span>
<> → </>
</>)}
{linkFlg
? (
<Link to={`/posts?${ (new URLSearchParams ({ tags: tag.name })).toString () }`}


+ 2
- 1
frontend/src/components/TagSearch.tsx View File

@@ -1,4 +1,5 @@
import axios from 'axios'
import toCamel from 'camelcase-keys'
import React, { useEffect, useState } from 'react'
import { useNavigate, useLocation } from 'react-router-dom'

@@ -31,7 +32,7 @@ export default (() => {
}

const res = await axios.get (`${ API_BASE_URL }/tags/autocomplete`, { params: { q } })
const data = res.data as Tag[]
const data = toCamel (res.data, { deep: true }) as Tag[]
setSuggestions (data)
if (suggestions.length > 0)
setSuggestionsVsbl (true)


+ 2
- 2
frontend/src/components/TagSearchBox.tsx View File

@@ -1,3 +1,4 @@
import TagLink from '@/components/TagLink'
import { cn } from '@/lib/utils'

import type { FC } from 'react'
@@ -22,8 +23,7 @@ export default (({ suggestions, activeIndex, onSelect }: Props) => {
className={cn ('px-3 py-2 cursor-pointer hover:bg-gray-300 dark:hover:bg-gray-700',
i === activeIndex && 'bg-gray-300 dark:bg-gray-700')}
onMouseDown={() => onSelect (tag)}>
{tag.name}
{<span className="ml-2 text-sm text-gray-400">{tag.postCount}</span>}
<TagLink tag={tag} linkFlg={false} withWiki={false}/>
</li>))}
</ul>)
}) satisfies FC<Props>

+ 7
- 6
frontend/src/types.ts View File

@@ -44,12 +44,13 @@ export type SubMenuItem =
visible?: boolean }

export type Tag = {
id: number
name: string
category: Category
postCount: number
hasWiki: boolean
children?: Tag[] }
id: number
name: string
category: Category
postCount: number
hasWiki: boolean
children?: Tag[]
matchedAlias?: string | null }

export type User = {
id: number


Loading…
Cancel
Save