chore: custom event ribbon icon click

This commit is contained in:
Faisal Amir 2024-11-20 13:35:55 +07:00 committed by Louis
parent 9a8b76517c
commit dd503767a2

View File

@ -7,6 +7,7 @@ import {
SquareCodeIcon, SquareCodeIcon,
} from 'lucide-react' } from 'lucide-react'
import posthog from 'posthog-js'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import { MainViewState } from '@/constants/screens' import { MainViewState } from '@/constants/screens'
@ -34,11 +35,14 @@ export default function RibbonPanel() {
const threads = useAtomValue(threadsAtom) const threads = useAtomValue(threadsAtom)
const isDownloadALocalModel = useAtomValue(isDownloadALocalModelAtom) const isDownloadALocalModel = useAtomValue(isDownloadALocalModelAtom)
const onMenuClick = (state: MainViewState) => { const onMenuClick = (state: MainViewState, id: string) => {
if (mainViewState === state) return if (mainViewState === state) return
if (serverEnabled && state === MainViewState.Thread) return if (serverEnabled && state === MainViewState.Thread) return
if (state === MainViewState.Settings) setSelectedSetting('My Models') if (state === MainViewState.Settings) setSelectedSetting('My Models')
setMainViewState(state) setMainViewState(state)
posthog.capture('mainViewScreen', {
screen: id,
})
setEditMessage('') setEditMessage('')
} }
@ -55,21 +59,25 @@ export default function RibbonPanel() {
/> />
), ),
state: MainViewState.Thread, state: MainViewState.Thread,
id: 'thread_screen',
}, },
{ {
name: 'Hub', name: 'Hub',
icon: <LayoutGridIcon size={18} className="flex-shrink-0" />, icon: <LayoutGridIcon size={18} className="flex-shrink-0" />,
state: MainViewState.Hub, state: MainViewState.Hub,
id: 'hub_screen',
}, },
{ {
name: 'Local API Server', name: 'Local API Server',
icon: <SquareCodeIcon size={18} className="flex-shrink-0" />, icon: <SquareCodeIcon size={18} className="flex-shrink-0" />,
state: MainViewState.LocalServer, state: MainViewState.LocalServer,
id: 'local_api_server_screen',
}, },
{ {
name: 'Settings', name: 'Settings',
icon: <SettingsIcon size={18} className="flex-shrink-0" />, icon: <SettingsIcon size={18} className="flex-shrink-0" />,
state: MainViewState.Settings, state: MainViewState.Settings,
id: 'setting',
}, },
] ]
@ -98,7 +106,7 @@ export default function RibbonPanel() {
i === 1 && 'mb-auto' i === 1 && 'mb-auto'
)} )}
key={i} key={i}
onClick={() => onMenuClick(menu.state)} onClick={() => onMenuClick(menu.state, menu.id)}
> >
<Tooltip <Tooltip
side="right" side="right"