fix: address code review issues in session sharing
- Add useCallback for loadShares in ShareSessionModal (React hook deps) - Use TreeStructure type instead of Record<string, unknown> for type safety - Fix login redirect format to match LoginPage's expected state shape Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
import { X, Copy, Check, Globe, Users, Clock, Trash2, Link2 } from 'lucide-react'
|
import { X, Copy, Check, Globe, Users, Clock, Trash2, Link2 } from 'lucide-react'
|
||||||
import type { SessionShare, SessionShareVisibility } from '@/types'
|
import type { SessionShare, SessionShareVisibility } from '@/types'
|
||||||
import { sessionsApi } from '@/api/sessions'
|
import { sessionsApi } from '@/api/sessions'
|
||||||
@@ -82,20 +82,7 @@ export function ShareSessionModal({ sessionId, sessionLabel, isOpen, onClose }:
|
|||||||
const [customDatetime, setCustomDatetime] = useState('')
|
const [customDatetime, setCustomDatetime] = useState('')
|
||||||
const [visibilityError, setVisibilityError] = useState<string | null>(null)
|
const [visibilityError, setVisibilityError] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
const loadShares = useCallback(async () => {
|
||||||
if (isOpen) {
|
|
||||||
loadShares()
|
|
||||||
// Reset form state
|
|
||||||
setVisibility('account')
|
|
||||||
setShareName('')
|
|
||||||
setExpirationPreset('never')
|
|
||||||
setCustomDatetime('')
|
|
||||||
setVisibilityError(null)
|
|
||||||
setCopiedShareId(null)
|
|
||||||
}
|
|
||||||
}, [isOpen, sessionId])
|
|
||||||
|
|
||||||
const loadShares = async () => {
|
|
||||||
setIsLoadingShares(true)
|
setIsLoadingShares(true)
|
||||||
try {
|
try {
|
||||||
const allShares = await sessionsApi.listMyShares()
|
const allShares = await sessionsApi.listMyShares()
|
||||||
@@ -108,7 +95,20 @@ export function ShareSessionModal({ sessionId, sessionLabel, isOpen, onClose }:
|
|||||||
} finally {
|
} finally {
|
||||||
setIsLoadingShares(false)
|
setIsLoadingShares(false)
|
||||||
}
|
}
|
||||||
}
|
}, [sessionId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
loadShares()
|
||||||
|
// Reset form state
|
||||||
|
setVisibility('account')
|
||||||
|
setShareName('')
|
||||||
|
setExpirationPreset('never')
|
||||||
|
setCustomDatetime('')
|
||||||
|
setVisibilityError(null)
|
||||||
|
setCopiedShareId(null)
|
||||||
|
}
|
||||||
|
}, [isOpen, sessionId, loadShares])
|
||||||
|
|
||||||
const handleGenerateLink = async () => {
|
const handleGenerateLink = async () => {
|
||||||
setIsGenerating(true)
|
setIsGenerating(true)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import type { TreeStructure } from '@/types'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
interface SharedSessionTreePreviewProps {
|
interface SharedSessionTreePreviewProps {
|
||||||
treeStructure: Record<string, unknown>
|
treeStructure: TreeStructure
|
||||||
pathTaken: string[]
|
pathTaken: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export function SharedSessionPage() {
|
|||||||
const status = err.response?.status
|
const status = err.response?.status
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
navigate('/login', {
|
navigate('/login', {
|
||||||
state: { from: `/share/${shareToken}` },
|
state: { from: { pathname: `/share/${shareToken}` } },
|
||||||
replace: true,
|
replace: true,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -232,7 +232,7 @@ export function SharedSessionPage() {
|
|||||||
<div className="lg:col-span-2">
|
<div className="lg:col-span-2">
|
||||||
<SessionTimeline
|
<SessionTimeline
|
||||||
decisions={data.decisions}
|
decisions={data.decisions}
|
||||||
treeType={data.tree_structure?.tree_type as string}
|
treeType={data.tree_structure?.tree_type}
|
||||||
startedAt={data.started_at}
|
startedAt={data.started_at}
|
||||||
completedAt={data.completed_at}
|
completedAt={data.completed_at}
|
||||||
showCopyButtons={false}
|
showCopyButtons={false}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export interface SharedSessionView {
|
|||||||
session_id: string
|
session_id: string
|
||||||
tree_name: string
|
tree_name: string
|
||||||
tree_description: string | null
|
tree_description: string | null
|
||||||
tree_structure: Record<string, unknown>
|
tree_structure: TreeStructure
|
||||||
path_taken: string[]
|
path_taken: string[]
|
||||||
decisions: DecisionRecord[]
|
decisions: DecisionRecord[]
|
||||||
custom_steps: CustomStep[]
|
custom_steps: CustomStep[]
|
||||||
|
|||||||
Reference in New Issue
Block a user