Reviewed-on: #397 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #397 でマージされました.
このコミットが含まれているのは:
@@ -15,7 +15,16 @@ import { Button } from '@/components/ui/button'
|
||||
import { SITE_TITLE } from '@/config'
|
||||
import { CATEGORIES, CATEGORY_NAMES } from '@/consts'
|
||||
import { apiDelete, apiGet, apiPatch, apiPost, apiPut, isApiError } from '@/lib/api'
|
||||
import { clientAnimationTransition,
|
||||
clientScrollBehaviour } from '@/lib/clientAnimation'
|
||||
import { fetchPost } from '@/lib/posts'
|
||||
import {
|
||||
getClientTheatreLayoutMode,
|
||||
getClientTheatreTagFlow,
|
||||
setClientTheatreLayoutMode,
|
||||
setClientTheatreTagFlow,
|
||||
} from '@/lib/settings'
|
||||
import { useClientBehaviourSettings } from '@/lib/useClientBehaviourSettings'
|
||||
import { canEditContent } from '@/lib/users'
|
||||
import { cn, dateString, inputClass } from '@/lib/utils'
|
||||
import { useValidationErrors } from '@/lib/useValidationErrors'
|
||||
@@ -51,8 +60,6 @@ const INITIAL_THEATRE_INFO: TheatreInfo =
|
||||
const INITIAL_WEIGHTS: TheatrePostSelectionWeights =
|
||||
{ tagPenalties: [], lightestPosts: [], heaviestPosts: [] }
|
||||
|
||||
const LAYOUT_STORAGE_KEY = 'theatre-layout-mode'
|
||||
const TAG_FLOW_STORAGE_KEY = 'theatre-tag-flow'
|
||||
const MIN_MAIN_WIDTH = 360
|
||||
const SIDEBAR_GAP_WIDTH = 16
|
||||
|
||||
@@ -208,6 +215,12 @@ type Props = { user: User | null }
|
||||
|
||||
|
||||
const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
||||
const behaviourSettings = useClientBehaviourSettings ()
|
||||
const animationMode = behaviourSettings.animation ?? 'normal'
|
||||
const layoutTransition = clientAnimationTransition (
|
||||
animationMode,
|
||||
{ normal: { duration: .2, ease: 'easeOut' as const } },
|
||||
)
|
||||
const { id } = useParams ()
|
||||
const dialogue = useDialogue ()
|
||||
|
||||
@@ -236,32 +249,20 @@ const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
||||
const [post, setPost] = useState<Post | null> (null)
|
||||
const [videoLength, setVideoLength] = useState (0)
|
||||
const [weights, setWeights] = useState<TheatrePostSelectionWeights> (INITIAL_WEIGHTS)
|
||||
const [layoutMode, setLayoutMode] = useState<TheatreLayoutMode> (() => {
|
||||
const stored = localStorage.getItem (LAYOUT_STORAGE_KEY)
|
||||
return (
|
||||
((['threeColumns', 'tagsBottom', 'commentsBottom'] as TheatreLayoutMode[])
|
||||
.includes (stored as TheatreLayoutMode))
|
||||
? (stored as TheatreLayoutMode)
|
||||
: 'threeColumns')
|
||||
})
|
||||
const [tagFlow, setTagFlow] = useState<TagFlow> (() => {
|
||||
const stored = localStorage.getItem (TAG_FLOW_STORAGE_KEY)
|
||||
return (
|
||||
(['vertical', 'horizontal'] as TagFlow[]).includes (stored as TagFlow)
|
||||
? (stored as TagFlow)
|
||||
: 'vertical')
|
||||
})
|
||||
const [layoutMode, setLayoutMode] =
|
||||
useState<TheatreLayoutMode> (() => getClientTheatreLayoutMode ())
|
||||
const [tagFlow, setTagFlow] = useState<TagFlow> (() => getClientTheatreTagFlow ())
|
||||
const { fieldErrors, clearValidationErrors, applyValidationError } =
|
||||
useValidationErrors<TheatreCommentField> ()
|
||||
|
||||
const changeLayoutMode = (mode: TheatreLayoutMode) => {
|
||||
setLayoutMode (mode)
|
||||
localStorage.setItem (LAYOUT_STORAGE_KEY, mode)
|
||||
setClientTheatreLayoutMode (mode)
|
||||
}
|
||||
|
||||
const changeTagFlow = (flow: TagFlow) => {
|
||||
setTagFlow (flow)
|
||||
localStorage.setItem (TAG_FLOW_STORAGE_KEY, flow)
|
||||
setClientTheatreTagFlow (flow)
|
||||
}
|
||||
|
||||
const applyTheatreInfo = useCallback ((nextInfo: TheatreInfo) => {
|
||||
@@ -626,7 +627,9 @@ const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
||||
clearValidationErrors ()
|
||||
await apiPost (`/theatres/${ id }/comments`, { content })
|
||||
setContent ('')
|
||||
commentsRef.current?.scrollTo ({ top: 0, behavior: 'smooth' })
|
||||
commentsRef.current?.scrollTo ({
|
||||
top: 0,
|
||||
behavior: clientScrollBehaviour (animationMode) })
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
@@ -843,8 +846,8 @@ const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
layout="position"
|
||||
transition={{ layout: { duration: .2, ease: 'easeOut' } }}
|
||||
layout={animationMode === 'off' ? false : 'position'}
|
||||
transition={{ layout: layoutTransition }}
|
||||
className="min-h-0 flex-1 overflow-y-auto bg-zinc-50 text-zinc-950
|
||||
md:overflow-hidden dark:bg-zinc-950 dark:text-zinc-50">
|
||||
<Helmet>
|
||||
@@ -868,7 +871,7 @@ const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
||||
</SidebarComponent>)}
|
||||
|
||||
<motion.main
|
||||
layout="position"
|
||||
layout={animationMode === 'off' ? false : 'position'}
|
||||
className="order-1 min-w-0 flex-1 space-y-4 md:order-none
|
||||
md:min-w-[360px] md:overflow-y-auto">
|
||||
<div className="space-y-4">
|
||||
|
||||
新しい課題から参照
ユーザをブロックする