コミットを比較
3
コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
c0f42ea0c0 | ||
|
|
f05d8a4b3a | ||
|
|
dbae864f24 |
@@ -1,6 +1,8 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
import { useLocale } from '@/lib/useLocale'
|
import { useLocale } from '@/lib/useLocale'
|
||||||
|
import PostList from '@/components/PostList'
|
||||||
import PostOriginalCreatedTimeField from '@/components/PostOriginalCreatedTimeField'
|
import PostOriginalCreatedTimeField from '@/components/PostOriginalCreatedTimeField'
|
||||||
import FieldError from '@/components/common/FieldError'
|
import FieldError from '@/components/common/FieldError'
|
||||||
import PostDurationField from '@/components/posts/PostDurationField'
|
import PostDurationField from '@/components/posts/PostDurationField'
|
||||||
@@ -10,14 +12,15 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { toast } from '@/components/ui/use-toast'
|
import { toast } from '@/components/ui/use-toast'
|
||||||
import { isApiError } from '@/lib/api'
|
import { isApiError } from '@/lib/api'
|
||||||
import useDialogue from '@/lib/dialogues/useDialogue'
|
import useDialogue from '@/lib/dialogues/useDialogue'
|
||||||
import { updatePost } from '@/lib/posts'
|
import { fetchPosts, updatePost } from '@/lib/posts'
|
||||||
|
import { postsKeys } from '@/lib/queryKeys'
|
||||||
import { msToTime } from '@/lib/utils'
|
import { msToTime } from '@/lib/utils'
|
||||||
import { useValidationErrors } from '@/lib/useValidationErrors'
|
import { useValidationErrors } from '@/lib/useValidationErrors'
|
||||||
import { useUITranslation } from '@/lib/useUITranslation'
|
import { useUITranslation } from '@/lib/useUITranslation'
|
||||||
|
|
||||||
import type { FC, FormEvent } from 'react'
|
import type { FC, FormEvent } from 'react'
|
||||||
|
|
||||||
import type { Post, TagWithSections } from '@/types'
|
import type { FetchPostsParams, Post, TagWithSections } from '@/types'
|
||||||
|
|
||||||
type PostFormField =
|
type PostFormField =
|
||||||
'parentPostIds' | 'tags' | 'videoMs'
|
'parentPostIds' | 'tags' | 'videoMs'
|
||||||
@@ -68,6 +71,33 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
|||||||
const [tags, setTags] = useState<string> (() => tagsToStr (post.tags))
|
const [tags, setTags] = useState<string> (() => tagsToStr (post.tags))
|
||||||
const [title, setTitle] = useState (post.title)
|
const [title, setTitle] = useState (post.title)
|
||||||
|
|
||||||
|
const [importVisible, setImportVisible] = useState (false)
|
||||||
|
const [sourceTitle, setSourceTitle] = useState ('')
|
||||||
|
const [sourcePage, setSourcePage] = useState (1)
|
||||||
|
const sourceParams: FetchPostsParams = {
|
||||||
|
title: sourceTitle, page: sourcePage, limit: 20,
|
||||||
|
url: '', tags: '', match: 'all', order: 'original_created_at:desc',
|
||||||
|
originalCreatedFrom: '', originalCreatedTo: '',
|
||||||
|
createdFrom: '', createdTo: '', updatedFrom: '', updatedTo: '' }
|
||||||
|
const { data: sources, isError: sourceError } = useQuery ({
|
||||||
|
queryKey: postsKeys.index (sourceParams, locale),
|
||||||
|
queryFn: () => fetchPosts (sourceParams, locale),
|
||||||
|
enabled: importVisible && !disabled })
|
||||||
|
|
||||||
|
const importTags = (source: Post) => {
|
||||||
|
if (disabled)
|
||||||
|
return
|
||||||
|
setTags (current => {
|
||||||
|
const existing = new Set (current.split (/\s+/))
|
||||||
|
const additions = tagsToStr (source.tags).split (/\s+/)
|
||||||
|
.filter (tag => tag !== '' && !existing.has (tag))
|
||||||
|
return additions.length > 0
|
||||||
|
? `${current}${current.trim () === '' ? '' : ' '}${additions.join (' ')}`
|
||||||
|
: current
|
||||||
|
})
|
||||||
|
setImportVisible (false)
|
||||||
|
}
|
||||||
|
|
||||||
const videoFlg =
|
const videoFlg =
|
||||||
useMemo (() => tags.split (/\s+/).some (tag => tag.replace (/\[.*\]$/, '') === '動画'),
|
useMemo (() => tags.split (/\s+/).some (tag => tag.replace (/\[.*\]$/, '') === '動画'),
|
||||||
[tags])
|
[tags])
|
||||||
@@ -192,6 +222,48 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
|||||||
setTags={setTags}
|
setTags={setTags}
|
||||||
errors={fieldErrors.tags}/>
|
errors={fieldErrors.tags}/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={disabled}
|
||||||
|
aria-expanded={importVisible}
|
||||||
|
onClick={() => setImportVisible (visible => !visible)}>
|
||||||
|
{label ('edit.import')}
|
||||||
|
</Button>
|
||||||
|
{importVisible && (
|
||||||
|
<div className="space-y-2" onKeyDown={event => {
|
||||||
|
if (event.key === 'Enter' && event.target instanceof HTMLInputElement)
|
||||||
|
event.preventDefault ()
|
||||||
|
}}>
|
||||||
|
<PostTextField
|
||||||
|
label={label ('shared:labels.title')}
|
||||||
|
type="search"
|
||||||
|
value={sourceTitle}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={value => {
|
||||||
|
setSourceTitle (value)
|
||||||
|
setSourcePage (1)
|
||||||
|
}}/>
|
||||||
|
<FieldError messages={sourceError ? [label ('common:fetchError')] : []}/>
|
||||||
|
{!disabled && <PostList posts={sources?.posts ?? []} onSelect={importTags}/>}
|
||||||
|
<div className="flex flex-col gap-2 md:flex-row">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={disabled || sourcePage <= 1}
|
||||||
|
onClick={() => setSourcePage (page => page - 1)}>
|
||||||
|
{label ('common:pagination.previous')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={disabled || sourcePage * 20 >= (sources?.count ?? 0)}
|
||||||
|
onClick={() => setSourcePage (page => page + 1)}>
|
||||||
|
{label ('common:pagination.next')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>)}
|
||||||
|
|
||||||
{/* オリジナルの作成日時 */}
|
{/* オリジナルの作成日時 */}
|
||||||
<PostOriginalCreatedTimeField
|
<PostOriginalCreatedTimeField
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useRef } from 'react'
|
|||||||
import { useLocation } from 'react-router-dom'
|
import { useLocation } from 'react-router-dom'
|
||||||
|
|
||||||
import PrefetchLink from '@/components/PrefetchLink'
|
import PrefetchLink from '@/components/PrefetchLink'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
import { useUITranslation } from '@/lib/useUITranslation'
|
import { useUITranslation } from '@/lib/useUITranslation'
|
||||||
import { useClientBehaviourSettings } from '@/lib/useClientBehaviourSettings'
|
import { useClientBehaviourSettings } from '@/lib/useClientBehaviourSettings'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
@@ -13,10 +14,11 @@ import type { FC, MouseEvent } from 'react'
|
|||||||
import type { Post } from '@/types'
|
import type { Post } from '@/types'
|
||||||
|
|
||||||
type Props = { posts: Post[]
|
type Props = { posts: Post[]
|
||||||
|
onSelect?: (post: Post) => void
|
||||||
onClick?: (event: MouseEvent<HTMLElement>) => void }
|
onClick?: (event: MouseEvent<HTMLElement>) => void }
|
||||||
|
|
||||||
|
|
||||||
const PostList: FC<Props> = ({ posts, onClick }) => {
|
const PostList: FC<Props> = ({ posts, onClick, onSelect }) => {
|
||||||
const { label } = useUITranslation ('shared')
|
const { label } = useUITranslation ('shared')
|
||||||
const location = useLocation ()
|
const location = useLocation ()
|
||||||
const behaviourSettings = useClientBehaviourSettings ()
|
const behaviourSettings = useClientBehaviourSettings ()
|
||||||
@@ -39,7 +41,63 @@ const PostList: FC<Props> = ({ posts, onClick }) => {
|
|||||||
const sharedId = `page-${ post.id }`
|
const sharedId = `page-${ post.id }`
|
||||||
const layoutId = sharedId
|
const layoutId = sharedId
|
||||||
|
|
||||||
return (
|
const card = (
|
||||||
|
<motion.div
|
||||||
|
ref={cardRef}
|
||||||
|
layout={animationMode === 'off' ? false : true}
|
||||||
|
layoutId={(onSelect || animationMode === 'off') ? undefined : layoutId}
|
||||||
|
className={cn ('w-full h-full overflow-hidden rounded-xl shadow',
|
||||||
|
'transform-gpu will-change-transform',
|
||||||
|
(post.childPosts ?? []).length > 0 && 'ring-4 ring-green-500',
|
||||||
|
(post.parentPosts ?? []).length > 0 && 'ring-4 ring-yellow-500')}
|
||||||
|
whileHover={{ scale: 1.02 }}
|
||||||
|
onLayoutAnimationStart={() => {
|
||||||
|
if (!(cardRef.current))
|
||||||
|
return
|
||||||
|
|
||||||
|
cardRef.current.style.position = 'relative'
|
||||||
|
cardRef.current.style.zIndex = '9999'
|
||||||
|
}}
|
||||||
|
onLayoutAnimationComplete={() => {
|
||||||
|
if (!(cardRef.current))
|
||||||
|
return
|
||||||
|
|
||||||
|
cardRef.current.style.zIndex = ''
|
||||||
|
cardRef.current.style.position = ''
|
||||||
|
}}
|
||||||
|
transition={{ layout: cardLayoutTransition }}>
|
||||||
|
{thumbnailMode === 'off'
|
||||||
|
? (
|
||||||
|
<div className="flex h-full w-full items-center justify-center
|
||||||
|
bg-muted text-center text-xs text-muted-foreground">
|
||||||
|
{label ('labels.noThumbnail')}
|
||||||
|
</div>)
|
||||||
|
: (
|
||||||
|
<img
|
||||||
|
src={post.thumbnail || post.thumbnailBase || undefined}
|
||||||
|
alt={post.title || post.url}
|
||||||
|
title={post.title || post.url || undefined}
|
||||||
|
loading={
|
||||||
|
thumbnailMode === 'light'
|
||||||
|
? 'lazy'
|
||||||
|
: (i < 12 ? 'eager' : 'lazy')
|
||||||
|
}
|
||||||
|
decoding="async"
|
||||||
|
className="object-cover w-full h-full"/>)}
|
||||||
|
</motion.div>)
|
||||||
|
|
||||||
|
return onSelect
|
||||||
|
? (
|
||||||
|
<Button
|
||||||
|
key={post.id}
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
className="w-40 h-40 p-0"
|
||||||
|
aria-label={post.title || post.url}
|
||||||
|
onClick={() => onSelect (post)}>
|
||||||
|
{card}
|
||||||
|
</Button>)
|
||||||
|
: (
|
||||||
<PrefetchLink
|
<PrefetchLink
|
||||||
to={`/posts/${ post.id }`}
|
to={`/posts/${ post.id }`}
|
||||||
key={post.id}
|
key={post.id}
|
||||||
@@ -49,51 +107,7 @@ const PostList: FC<Props> = ({ posts, onClick }) => {
|
|||||||
setForLocationKey (location.key, sharedId)
|
setForLocationKey (location.key, sharedId)
|
||||||
onClick?.(e)
|
onClick?.(e)
|
||||||
}}>
|
}}>
|
||||||
<motion.div
|
{card}
|
||||||
ref={cardRef}
|
|
||||||
layout={animationMode === 'off' ? false : true}
|
|
||||||
layoutId={animationMode === 'off' ? undefined : layoutId}
|
|
||||||
className={cn ('w-full h-full overflow-hidden rounded-xl shadow',
|
|
||||||
'transform-gpu will-change-transform',
|
|
||||||
(post.childPosts ?? []).length > 0 && 'ring-4 ring-green-500',
|
|
||||||
(post.parentPosts ?? []).length > 0 && 'ring-4 ring-yellow-500')}
|
|
||||||
whileHover={{ scale: 1.02 }}
|
|
||||||
onLayoutAnimationStart={() => {
|
|
||||||
if (!(cardRef.current))
|
|
||||||
return
|
|
||||||
|
|
||||||
cardRef.current.style.position = 'relative'
|
|
||||||
cardRef.current.style.zIndex = '9999'
|
|
||||||
}}
|
|
||||||
onLayoutAnimationComplete={() => {
|
|
||||||
if (!(cardRef.current))
|
|
||||||
return
|
|
||||||
|
|
||||||
cardRef.current.style.zIndex = ''
|
|
||||||
cardRef.current.style.position = ''
|
|
||||||
}}
|
|
||||||
transition={{ layout: cardLayoutTransition }}>
|
|
||||||
{thumbnailMode === 'off'
|
|
||||||
? (
|
|
||||||
<div className="flex h-full w-full items-center justify-center
|
|
||||||
bg-muted text-center text-xs text-muted-foreground">
|
|
||||||
{label ('labels.noThumbnail')}
|
|
||||||
</div>)
|
|
||||||
: (
|
|
||||||
<img
|
|
||||||
src={post.thumbnail || post.thumbnailBase || undefined}
|
|
||||||
alt={post.title || post.url}
|
|
||||||
title={post.title || post.url || undefined}
|
|
||||||
loading={
|
|
||||||
thumbnailMode === 'light'
|
|
||||||
? 'lazy'
|
|
||||||
: i < 12
|
|
||||||
? 'eager'
|
|
||||||
: 'lazy'
|
|
||||||
}
|
|
||||||
decoding="async"
|
|
||||||
className="object-cover w-full h-full"/>)}
|
|
||||||
</motion.div>
|
|
||||||
</PrefetchLink>)
|
</PrefetchLink>)
|
||||||
})}
|
})}
|
||||||
</div>)
|
</div>)
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import { fireEvent, screen } from '@testing-library/react'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
import { useLocation } from 'react-router-dom'
|
||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
|
import TagSearch from '@/components/TagSearch'
|
||||||
|
import * as api from '@/lib/api'
|
||||||
|
import { buildTag } from '@/test/factories'
|
||||||
|
import { renderWithProviders } from '@/test/render'
|
||||||
|
|
||||||
|
|
||||||
|
const LocationOutput = () => {
|
||||||
|
const location = useLocation ()
|
||||||
|
return <output data-testid="location">{location.pathname}{location.search}</output>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const renderSearch = () => renderWithProviders (
|
||||||
|
<>
|
||||||
|
<TagSearch/>
|
||||||
|
<LocationOutput/>
|
||||||
|
</>, { route: '/ja/posts?page=3' })
|
||||||
|
|
||||||
|
|
||||||
|
describe ('TagSearch', () => {
|
||||||
|
beforeEach (() => {
|
||||||
|
vi.spyOn (api, 'apiGet').mockResolvedValue ([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('searches through native submission without an Enter key event', () => {
|
||||||
|
renderSearch ()
|
||||||
|
const input = screen.getByRole<HTMLInputElement> ('textbox')
|
||||||
|
fireEvent.change (input, { target: { value: '虹夏 not:TEST type:or' } })
|
||||||
|
|
||||||
|
expect (input.form).toBeInstanceOf (HTMLFormElement)
|
||||||
|
fireEvent.submit (input.form!)
|
||||||
|
|
||||||
|
const query = new URLSearchParams ({ tags: '虹夏 not:test', match: 'any' })
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent (
|
||||||
|
`/ja/posts?${ query }`)
|
||||||
|
expect (input).toHaveValue ('虹夏 not:test type:or')
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('requests a search action from the software keyboard', () => {
|
||||||
|
renderSearch ()
|
||||||
|
|
||||||
|
expect (screen.getByRole ('textbox')).toHaveAttribute ('enterkeyhint', 'search')
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('searches through the form when Enter is pressed', async () => {
|
||||||
|
const user = userEvent.setup ()
|
||||||
|
renderSearch ()
|
||||||
|
|
||||||
|
await user.type (screen.getByRole ('textbox'), '虹夏{Enter}')
|
||||||
|
|
||||||
|
const query = new URLSearchParams ({ tags: '虹夏', match: 'all' })
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent (
|
||||||
|
`/ja/posts?${ query }`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it.each ([
|
||||||
|
{ label: 'composition flag', composing: true, keyCode: 13 },
|
||||||
|
{ label: 'legacy IME code', composing: false, keyCode: 229 }]) (
|
||||||
|
'cancels confirmation Enter with $label', ({ composing, keyCode }) => {
|
||||||
|
renderSearch ()
|
||||||
|
const input = screen.getByRole ('textbox')
|
||||||
|
fireEvent.change (input, { target: { value: '虹夏' } })
|
||||||
|
const uncancelled = fireEvent.keyDown (input, {
|
||||||
|
key: 'Enter', isComposing: composing, keyCode })
|
||||||
|
|
||||||
|
expect (uncancelled).toBe (false)
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
|
||||||
|
expect (input).toHaveValue ('虹夏')
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('cancels Enter throughout composition even without keyboard IME flags', () => {
|
||||||
|
renderSearch ()
|
||||||
|
const input = screen.getByRole ('textbox')
|
||||||
|
fireEvent.compositionStart (input)
|
||||||
|
fireEvent.change (input, { target: { value: '虹夏' } })
|
||||||
|
const uncancelled = fireEvent.keyDown (input, {
|
||||||
|
key: 'Enter', isComposing: false, keyCode: 13 })
|
||||||
|
|
||||||
|
expect (uncancelled).toBe (false)
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
|
||||||
|
expect (input).toHaveValue ('虹夏')
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('blocks direct submission during composition and allows it after confirmation', () => {
|
||||||
|
renderSearch ()
|
||||||
|
const input = screen.getByRole<HTMLInputElement> ('textbox')
|
||||||
|
fireEvent.compositionStart (input)
|
||||||
|
fireEvent.change (input, { target: { value: '虹夏' } })
|
||||||
|
fireEvent.submit (input.form!)
|
||||||
|
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
|
||||||
|
expect (input).toHaveValue ('虹夏')
|
||||||
|
|
||||||
|
fireEvent.compositionEnd (input)
|
||||||
|
fireEvent.submit (input.form!)
|
||||||
|
|
||||||
|
const query = new URLSearchParams ({ tags: '虹夏', match: 'all' })
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent (
|
||||||
|
`/ja/posts?${ query }`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('selects the active suggestion without submitting the form', async () => {
|
||||||
|
vi.mocked (api.apiGet).mockResolvedValue ([buildTag ({ name: '虹夏' })])
|
||||||
|
const user = userEvent.setup ()
|
||||||
|
renderSearch ()
|
||||||
|
|
||||||
|
await user.type (screen.getByRole ('textbox'), '虹')
|
||||||
|
await screen.findByText ('虹夏')
|
||||||
|
await user.keyboard ('{ArrowDown}{Enter}')
|
||||||
|
|
||||||
|
expect (screen.getByRole ('textbox')).toHaveValue ('虹夏 ')
|
||||||
|
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
|
||||||
|
expect (screen.queryByText ('虹夏')).not.toBeInTheDocument ()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// TODO: タグ入力系すべてに同様の処理あるため共通化する.
|
// TODO: タグ入力系すべてに同様の処理あるため共通化する.
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useLocation } from 'react-router-dom'
|
import { useLocation } from 'react-router-dom'
|
||||||
|
|
||||||
import { useLocale, useLocaleNavigate } from '@/lib/useLocale'
|
import { useLocale, useLocaleNavigate } from '@/lib/useLocale'
|
||||||
@@ -10,7 +10,7 @@ import { inputClass } from '@/lib/utils'
|
|||||||
|
|
||||||
import TagSearchBox from './TagSearchBox'
|
import TagSearchBox from './TagSearchBox'
|
||||||
|
|
||||||
import type { ChangeEvent, FC, KeyboardEvent } from 'react'
|
import type { ChangeEvent, FC, FormEvent, KeyboardEvent } from 'react'
|
||||||
|
|
||||||
import type { Tag } from '@/types'
|
import type { Tag } from '@/types'
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@ const TagSearch: FC = () => {
|
|||||||
const locale = useLocale ()
|
const locale = useLocale ()
|
||||||
const location = useLocation ()
|
const location = useLocation ()
|
||||||
const navigate = useLocaleNavigate ()
|
const navigate = useLocaleNavigate ()
|
||||||
|
const compositionFlgRef = useRef (false)
|
||||||
|
|
||||||
const [activeIndex, setActiveIndex] = useState (-1)
|
const [activeIndex, setActiveIndex] = useState (-1)
|
||||||
const [search, setSearch] = useState ('')
|
const [search, setSearch] = useState ('')
|
||||||
@@ -74,7 +75,34 @@ const TagSearch: FC = () => {
|
|||||||
setSuggestionsVsbl (false)
|
setSuggestionsVsbl (false)
|
||||||
}, [locale])
|
}, [locale])
|
||||||
|
|
||||||
|
const handleSubmit = (ev: FormEvent<HTMLFormElement>) => {
|
||||||
|
ev.preventDefault ()
|
||||||
|
if (compositionFlgRef.current)
|
||||||
|
return
|
||||||
|
|
||||||
|
const parts = search.split (' ')
|
||||||
|
const match =
|
||||||
|
parts.map (t => t.toLowerCase ()).includes ('type:or') ? 'any' : 'all'
|
||||||
|
navigate (`/posts?${
|
||||||
|
(new URLSearchParams ({
|
||||||
|
tags: parts.map (t => t.toLowerCase ())
|
||||||
|
.filter (t => t !== 'type:or')
|
||||||
|
.join (' '),
|
||||||
|
match })).toString () }`)
|
||||||
|
setSuggestionsVsbl (false)
|
||||||
|
setRequest ({ query: '' })
|
||||||
|
}
|
||||||
|
|
||||||
const handleKeyDown = (ev: KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (ev: KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (compositionFlgRef.current
|
||||||
|
|| ev.nativeEvent.isComposing
|
||||||
|
|| ev.nativeEvent.keyCode === 229)
|
||||||
|
{
|
||||||
|
if (ev.key === 'Enter')
|
||||||
|
ev.preventDefault ()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch (ev.key)
|
switch (ev.key)
|
||||||
{
|
{
|
||||||
case 'ArrowDown':
|
case 'ArrowDown':
|
||||||
@@ -90,13 +118,12 @@ const TagSearch: FC = () => {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case 'Enter':
|
case 'Enter':
|
||||||
if (activeIndex < 0)
|
|
||||||
break
|
|
||||||
ev.preventDefault ()
|
|
||||||
{
|
{
|
||||||
const selected = suggestions[activeIndex]
|
const selected = suggestionsVsbl ? suggestions[activeIndex] : null
|
||||||
if (selected)
|
if (selected == null)
|
||||||
handleTagSelect (selected)
|
break
|
||||||
|
ev.preventDefault ()
|
||||||
|
handleTagSelect (selected)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -105,20 +132,6 @@ const TagSearch: FC = () => {
|
|||||||
setSuggestionsVsbl (false)
|
setSuggestionsVsbl (false)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (ev.key === 'Enter' && (!(suggestionsVsbl) || activeIndex < 0))
|
|
||||||
{
|
|
||||||
const parts = search.split (' ')
|
|
||||||
const match = parts.map (t => t.toLowerCase ()).includes ('type:or') ? 'any' : 'all'
|
|
||||||
navigate (`/posts?${
|
|
||||||
(new URLSearchParams ({
|
|
||||||
tags: parts.map (t => t.toLowerCase ())
|
|
||||||
.filter (t => t !== 'type:or')
|
|
||||||
.join (' '),
|
|
||||||
match }))
|
|
||||||
.toString () }`)
|
|
||||||
setSuggestionsVsbl (false)
|
|
||||||
setRequest ({ query: '' })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleTagSelect = (tag: Tag) => {
|
const handleTagSelect = (tag: Tag) => {
|
||||||
@@ -144,8 +157,9 @@ const TagSearch: FC = () => {
|
|||||||
}, [location.search])
|
}, [location.search])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full">
|
<form onSubmit={handleSubmit} className="relative w-full">
|
||||||
<input type="text"
|
<input type="text"
|
||||||
|
enterKeyHint="search"
|
||||||
data-shortcut-focus-search="true"
|
data-shortcut-focus-search="true"
|
||||||
placeholder={message ('labels.tagSearch').text}
|
placeholder={message ('labels.tagSearch').text}
|
||||||
value={search}
|
value={search}
|
||||||
@@ -153,12 +167,18 @@ const TagSearch: FC = () => {
|
|||||||
onFocus={() => setSuggestionsVsbl (true)}
|
onFocus={() => setSuggestionsVsbl (true)}
|
||||||
onBlur={() => setSuggestionsVsbl (false)}
|
onBlur={() => setSuggestionsVsbl (false)}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
onCompositionStart={() => {
|
||||||
|
compositionFlgRef.current = true
|
||||||
|
}}
|
||||||
|
onCompositionEnd={() => {
|
||||||
|
compositionFlgRef.current = false
|
||||||
|
}}
|
||||||
className={inputClass (false,
|
className={inputClass (false,
|
||||||
'px-3 py-2 dark:border-gray-600 dark:bg-gray-800 dark:text-white')}/>
|
'px-3 py-2 dark:border-gray-600 dark:bg-gray-800 dark:text-white')}/>
|
||||||
<TagSearchBox suggestions={suggestionsVsbl && suggestions.length ? suggestions : [] as Tag[]}
|
<TagSearchBox suggestions={suggestionsVsbl && suggestions.length ? suggestions : [] as Tag[]}
|
||||||
activeIndex={activeIndex}
|
activeIndex={activeIndex}
|
||||||
onSelect={handleTagSelect}/>
|
onSelect={handleTagSelect}/>
|
||||||
</div>)
|
</form>)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TagSearch
|
export default TagSearch
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"_untranslated": ["edit.import"],
|
||||||
"list": {
|
"list": {
|
||||||
"tagline": "{{brand}}",
|
"tagline": "{{brand}}",
|
||||||
"empty": "ミンタㇻ タ ネン カ イサㇺ",
|
"empty": "ミンタㇻ タ ネン カ イサㇺ",
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
"showExternal": "ソイタㇰ ソㇱ アヌカレ"
|
"showExternal": "ソイタㇰ ソㇱ アヌカレ"
|
||||||
},
|
},
|
||||||
"edit": {
|
"edit": {
|
||||||
|
"import": "インポート",
|
||||||
"validationFailed": "アシㇼ カㇻ カ エアイカㇷ゚……",
|
"validationFailed": "アシㇼ カㇻ カ エアイカㇷ゚……",
|
||||||
"conflictTitle": "モㇱマ クㇽ アシㇼ カㇻ ワ アン!",
|
"conflictTitle": "モㇱマ クㇽ アシㇼ カㇻ ワ アン!",
|
||||||
"conflictDescription": "モㇱマ イカㇻ クㇽ エエトコ アシㇼ カㇻ ワ アン。",
|
"conflictDescription": "モㇱマ イカㇻ クㇽ エエトコ アシㇼ カㇻ ワ アン。",
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
"question": "表示しますか?", "showExternal": "外部ページを表示"
|
"question": "表示しますか?", "showExternal": "外部ページを表示"
|
||||||
},
|
},
|
||||||
"edit": {
|
"edit": {
|
||||||
|
"import": "インポート",
|
||||||
"validationFailed": "更新はできなかったよ……",
|
"validationFailed": "更新はできなかったよ……",
|
||||||
"conflictTitle": "競合が発生しました.",
|
"conflictTitle": "競合が発生しました.",
|
||||||
"conflictDescription": "ほかの耕作員が先に更新してゐます.",
|
"conflictDescription": "ほかの耕作員が先に更新してゐます.",
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする