このコミットが含まれているのは:
@@ -49,7 +49,6 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
const [url, setURL] = useState ('')
|
const [url, setURL] = useState ('')
|
||||||
|
|
||||||
const thumbnailPreviewRef = useRef ('')
|
const thumbnailPreviewRef = useRef ('')
|
||||||
const urlRef = useRef ('')
|
|
||||||
const videoFlg =
|
const videoFlg =
|
||||||
useMemo (() => tags.split (/\s+/).some (tag => tag.replace (/\[.*\]$/, '') === '動画'),
|
useMemo (() => tags.split (/\s+/).some (tag => tag.replace (/\[.*\]$/, '') === '動画'),
|
||||||
[tags])
|
[tags])
|
||||||
@@ -85,13 +84,11 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fetchTitle = useCallback (async () => {
|
const fetchTitle = useCallback (async () => {
|
||||||
const requestedURL = url
|
|
||||||
setTitleLoading (true)
|
setTitleLoading (true)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const data = await apiGet<{ title: string }> ('/preview/title', { params: { url } })
|
const data = await apiGet<{ title: string }> ('/preview/title', { params: { url } })
|
||||||
if (requestedURL === urlRef.current)
|
setTitle (data.title || '')
|
||||||
setTitle (current => current || data.title || '')
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -100,7 +97,6 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
}, [url])
|
}, [url])
|
||||||
|
|
||||||
const fetchThumbnail = useCallback (async () => {
|
const fetchThumbnail = useCallback (async () => {
|
||||||
const requestedURL = url
|
|
||||||
setThumbnailPreview ('')
|
setThumbnailPreview ('')
|
||||||
setThumbnailFile (null)
|
setThumbnailFile (null)
|
||||||
setThumbnailLoading (true)
|
setThumbnailLoading (true)
|
||||||
@@ -111,14 +107,11 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
const data = await apiGet<Blob> ('/preview/thumbnail',
|
const data = await apiGet<Blob> ('/preview/thumbnail',
|
||||||
{ params: { url }, responseType: 'blob' })
|
{ params: { url }, responseType: 'blob' })
|
||||||
const imageURL = URL.createObjectURL (data)
|
const imageURL = URL.createObjectURL (data)
|
||||||
if (requestedURL === urlRef.current)
|
setThumbnailPreview (imageURL)
|
||||||
{
|
setThumbnailFile (new File ([data],
|
||||||
setThumbnailPreview (current => current || imageURL)
|
|
||||||
setThumbnailFile (current => current || new File ([data],
|
|
||||||
'thumbnail.png',
|
'thumbnail.png',
|
||||||
{ type: data.type || 'image/png' }))
|
{ type: data.type || 'image/png' }))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
setThumbnailLoading (false)
|
setThumbnailLoading (false)
|
||||||
@@ -129,20 +122,6 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
thumbnailPreviewRef.current = thumbnailPreview
|
thumbnailPreviewRef.current = thumbnailPreview
|
||||||
}, [thumbnailPreview])
|
}, [thumbnailPreview])
|
||||||
|
|
||||||
useEffect (() => {
|
|
||||||
urlRef.current = url
|
|
||||||
}, [url])
|
|
||||||
|
|
||||||
useEffect (() => {
|
|
||||||
if (!(url))
|
|
||||||
return
|
|
||||||
const timer = window.setTimeout (() => {
|
|
||||||
fetchTitle ().catch (() => undefined)
|
|
||||||
fetchThumbnail ().catch (() => undefined)
|
|
||||||
}, 500)
|
|
||||||
return () => window.clearTimeout (timer)
|
|
||||||
}, [fetchThumbnail, fetchTitle, url])
|
|
||||||
|
|
||||||
if (!(editable))
|
if (!(editable))
|
||||||
return <Forbidden/>
|
return <Forbidden/>
|
||||||
|
|
||||||
@@ -180,7 +159,7 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
onChange={ev => setTitle (ev.target.value)}
|
onChange={ev => setTitle (ev.target.value)}
|
||||||
disabled={titleLoading}/>
|
disabled={titleLoading}/>
|
||||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||||
<span>URL 入力後に自動取得します.</span>
|
<span>必要なタイミングで URL から取得できます.</span>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -197,7 +176,7 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
|||||||
{({ describedBy, invalid }) => (
|
{({ describedBy, invalid }) => (
|
||||||
<>
|
<>
|
||||||
<div className="mb-2 flex flex-wrap items-center gap-2 text-sm">
|
<div className="mb-2 flex flex-wrap items-center gap-2 text-sm">
|
||||||
<span>URL 入力後に自動取得します.</span>
|
<span>必要なタイミングで URL から取得できます.</span>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする