MCPcopy
hub / github.com/wandb/openui / Chat

Function Chat

frontend/src/components/Chat.tsx:42–326  ·  view source on GitHub ↗
({ isShared = false }: { isShared: boolean })

Source from the content-addressed store, hash-verified

40import { Button } from './ui/button'
41
42export default function Chat({ isShared = false }: { isShared: boolean }) {
43 const params = useParams()
44 const id = params.id ?? 'new'
45 const [isEditing, setIsEditing] = useState(false)
46 const imageUploadRef = useRef<HTMLInputElement>(null)
47 const contentRef = useRef<HTMLDivElement>(null)
48 const [sidebarState, setSidebarState] = useAtom(historySidebarStateAtom)
49 const [rawItem, setRawItem] = useAtom(historyAtomFamily({ id }))
50 const [historyIds, setHistoryIds] = useAtom(historyIdsAtom)
51 const framework = useAtomValue(selectedFrameworkAtom)
52 const modelSupportsImages = useAtomValue(modelSupportsImagesAtom)
53 const setScreenshot = useSetAtom(screenshotAtom)
54 const setDragging = useSetAtom(draggingAtom)
55 const item = useMemo(
56 () => new ItemWrapper(rawItem, setRawItem),
57 [rawItem, setRawItem]
58 )
59
60 const { t } = useTranslation()
61 const [uiState, setUiState] = useAtom(uiStateAtom)
62 const uiTheme = useAtomValue(uiThemeAtom)
63 const theme = themes.find(th => th.name === uiTheme)
64 const [versionIdx] = useVersion(item)
65 const deleteImage = useSetAtom(imageDB.delete)
66 const newImage = useAtomValue(imageDB.item(`image-new-0`))
67 const [image, setImage] = useAtom(imageDB.item(`image-${id}-${versionIdx}`))
68 const lastRender = useAtomValue(
69 imageDB.item(`screenshot-${id}-${versionIdx - 1}`)
70 )
71
72 // Load shared item
73 useEffect(() => {
74 if (isShared) {
75 ;(async () => {
76 const sharedItem = await getShare(id)
77 setUiState(ui => ({
78 ...ui,
79 pureHTML: sharedItem.html ?? '',
80 error: undefined
81 }))
82 sharedItem.markdown = `---\nname: ${sharedItem.name}\nemoji: ${sharedItem.emoji}\n---\n\n${sharedItem.html}`
83 setRawItem(sharedItem)
84 if (!historyIds.includes(id)) {
85 setHistoryIds([id, ...historyIds])
86 }
87 // SetItem(sharedItem)
88 })().catch((error: unknown) => {
89 console.error(error)
90 setUiState(ui => ({
91 ...ui,
92 error: (error as Error).toString()
93 }))
94 })
95 }
96 }, [isShared, id, setUiState, setRawItem, setHistoryIds, historyIds])
97
98 useEffect(() => {
99 setIsEditing(id !== 'new')

Callers

nothing calls this directly

Calls 9

useVersionFunction · 0.90
getShareFunction · 0.90
resizeImageFunction · 0.90
cnFunction · 0.90
mimeTypeAndExtensionFunction · 0.90
downloadStringAsFileFunction · 0.90
wrappedCodeFunction · 0.90
versionMethod · 0.80
pureHTMLMethod · 0.80

Tested by

no test coverage detected