コミットを比較
3 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| d7c51258a4 | |||
| 6c3316c3df | |||
| e2eca8adfe |
@@ -25,8 +25,8 @@ const getTokenAt = (value: string, pos: number) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const replaceToken = (value: string, start: number, end: number, text: string) => (
|
const replaceToken = (value: string, start: number, end: number, text: string) =>
|
||||||
`${ value.slice (0, start) }${ text }${ value.slice (end) }`)
|
`${ value.slice (0, start) }${ text }${ value.slice (end) }`
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -44,10 +44,10 @@ export default (({ tags, setTags }: Props) => {
|
|||||||
const handleTagSelect = (tag: Tag) => {
|
const handleTagSelect = (tag: Tag) => {
|
||||||
setSuggestionsVsbl (false)
|
setSuggestionsVsbl (false)
|
||||||
const textarea = ref.current!
|
const textarea = ref.current!
|
||||||
const newValue = replaceToken (tags, bounds.start, bounds.end, tag.name)
|
const newValue = replaceToken (tags, bounds.start, bounds.end, tag.name + ' ')
|
||||||
setTags (newValue)
|
setTags (newValue)
|
||||||
requestAnimationFrame (async () => {
|
requestAnimationFrame (async () => {
|
||||||
const p = bounds.start + tag.name.length
|
const p = bounds.start + tag.name.length + 1
|
||||||
textarea.selectionStart = textarea.selectionEnd = p
|
textarea.selectionStart = textarea.selectionEnd = p
|
||||||
textarea.focus ()
|
textarea.focus ()
|
||||||
await recompute (p, newValue)
|
await recompute (p, newValue)
|
||||||
@@ -56,8 +56,15 @@ export default (({ tags, setTags }: Props) => {
|
|||||||
|
|
||||||
const recompute = async (pos: number, v: string = tags) => {
|
const recompute = async (pos: number, v: string = tags) => {
|
||||||
const { start, end, token } = getTokenAt (v, pos)
|
const { start, end, token } = getTokenAt (v, pos)
|
||||||
|
if (!(token.trim ()))
|
||||||
|
{
|
||||||
|
setSuggestionsVsbl (false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setBounds ({ start, end })
|
setBounds ({ start, end })
|
||||||
const data = await apiGet<Tag[]> ('/tags/autocomplete', { params: { q: token } })
|
|
||||||
|
const data = await apiGet<Tag[]> ('/tags/autocomplete', { params: { q: token, nico: '0' } })
|
||||||
setSuggestions (data.filter (t => t.postCount > 0))
|
setSuggestions (data.filter (t => t.postCount > 0))
|
||||||
setSuggestionsVsbl (suggestions.length > 0)
|
setSuggestionsVsbl (suggestions.length > 0)
|
||||||
}
|
}
|
||||||
@@ -72,8 +79,10 @@ export default (({ tags, setTags }: Props) => {
|
|||||||
onSelect={async (ev: SyntheticEvent<HTMLTextAreaElement>) => {
|
onSelect={async (ev: SyntheticEvent<HTMLTextAreaElement>) => {
|
||||||
const pos = (ev.target as HTMLTextAreaElement).selectionStart
|
const pos = (ev.target as HTMLTextAreaElement).selectionStart
|
||||||
await recompute (pos)
|
await recompute (pos)
|
||||||
}}/>
|
}}
|
||||||
<TagSearchBox suggestions={suggestionsVsbl && suggestions.length
|
onBlur={() => setSuggestionsVsbl (false)}/>
|
||||||
|
<TagSearchBox
|
||||||
|
suggestions={suggestionsVsbl && suggestions.length > 0
|
||||||
? suggestions
|
? suggestions
|
||||||
: [] as Tag[]}
|
: [] as Tag[]}
|
||||||
activeIndex={-1}
|
activeIndex={-1}
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする