mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 08:29:07 +08:00
refactor(home-tabs): improve tab view logic readability
Extract topic view check into separate variable for clarity Rename canShowSettingsTab to shouldShowSettingsTab for better semantics
This commit is contained in:
parent
b28fadd02f
commit
77351b7691
@ -47,6 +47,7 @@ const HomeTabs: FC<Props> = ({
|
||||
const { chat } = useRuntime()
|
||||
const { activeTopicOrSession } = chat
|
||||
const isSessionView = activeTopicOrSession === 'session'
|
||||
const isTopicView = activeTopicOrSession === 'topic'
|
||||
|
||||
const [tab, setTab] = useState<Tab>(position === 'left' ? _tab || 'assistants' : 'topic')
|
||||
const borderStyle = '0.5px solid var(--color-border)'
|
||||
@ -60,7 +61,7 @@ const HomeTabs: FC<Props> = ({
|
||||
}
|
||||
|
||||
const showTab = position === 'left' && topicPosition === 'left'
|
||||
const canShowSettingsTab = !isSessionView
|
||||
const shouldShowSettingsTab = !isSessionView
|
||||
|
||||
const onCreateAssistant = async () => {
|
||||
const assistant = await AddAssistantPopup.show()
|
||||
@ -113,9 +114,9 @@ const HomeTabs: FC<Props> = ({
|
||||
{t('assistants.abbr')}
|
||||
</TabItem>
|
||||
<TabItem active={tab === 'topic'} onClick={() => setTab('topic')}>
|
||||
{activeTopicOrSession === 'topic' ? t('common.topics') : t('agent.session.label_other')}
|
||||
{isTopicView ? t('common.topics') : t('agent.session.label_other')}
|
||||
</TabItem>
|
||||
{canShowSettingsTab && (
|
||||
{shouldShowSettingsTab && (
|
||||
<TabItem active={tab === 'settings'} onClick={() => setTab('settings')}>
|
||||
{t('settings.title')}
|
||||
</TabItem>
|
||||
@ -126,9 +127,9 @@ const HomeTabs: FC<Props> = ({
|
||||
{position === 'right' && topicPosition === 'right' && (
|
||||
<CustomTabs>
|
||||
<TabItem active={tab === 'topic'} onClick={() => setTab('topic')}>
|
||||
{activeTopicOrSession === 'topic' ? t('common.topics') : t('agent.session.label_other')}
|
||||
{isTopicView ? t('common.topics') : t('agent.session.label_other')}
|
||||
</TabItem>
|
||||
{canShowSettingsTab && (
|
||||
{shouldShowSettingsTab && (
|
||||
<TabItem active={tab === 'settings'} onClick={() => setTab('settings')}>
|
||||
{t('settings.title')}
|
||||
</TabItem>
|
||||
@ -153,7 +154,7 @@ const HomeTabs: FC<Props> = ({
|
||||
position={position}
|
||||
/>
|
||||
)}
|
||||
{tab === 'settings' && canShowSettingsTab && <Settings assistant={activeAssistant} />}
|
||||
{tab === 'settings' && shouldShowSettingsTab && <Settings assistant={activeAssistant} />}
|
||||
</TabContent>
|
||||
</Container>
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user