forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 style: fix scroll and expand (lobehub#2470)
* 💄 style: Fix scroll and expand * 💄 style: improve empty card --------- Co-authored-by: arvinxx <[email protected]>
- Loading branch information
1 parent
5f4523a
commit 8b1202a
Showing
20 changed files
with
240 additions
and
181 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/app/(main)/chat/(workspace)/@topic/_layout/Desktop.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import Header from '../features/Header'; | ||
|
||
const Layout = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<> | ||
<Header /> | ||
<Flexbox height={'100%'} style={{ overflow: 'hidden', position: 'relative' }} width={'100%'}> | ||
{children} | ||
</Flexbox> | ||
</> | ||
); | ||
}; | ||
|
||
export default Layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import TopicSearchBar from '../features/TopicSearchBar'; | ||
|
||
const Layout = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<Flexbox gap={8} height={'100%'} padding={'8px 8px 0'} style={{ overflow: 'hidden' }}> | ||
<TopicSearchBar /> | ||
<Flexbox | ||
height={'100%'} | ||
style={{ marginInline: -8, overflow: 'hidden', position: 'relative' }} | ||
width={'calc(100% + 16px)'} | ||
> | ||
{children} | ||
</Flexbox> | ||
</Flexbox> | ||
); | ||
}; | ||
|
||
export default Layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 0 additions & 101 deletions
101
src/app/(main)/chat/(workspace)/@topic/features/TopicListContent/Topic/index.tsx
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 95 additions & 13 deletions
108
src/app/(main)/chat/(workspace)/@topic/features/TopicListContent/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,100 @@ | ||
'use client'; | ||
|
||
import { EmptyCard } from '@lobehub/ui'; | ||
import { useThemeMode } from 'antd-style'; | ||
import isEqual from 'fast-deep-equal'; | ||
import React, { memo, useCallback, useRef } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
import { Virtuoso, VirtuosoHandle } from 'react-virtuoso'; | ||
|
||
import { imageUrl } from '@/const/url'; | ||
import { useChatStore } from '@/store/chat'; | ||
import { topicSelectors } from '@/store/chat/selectors'; | ||
import { useUserStore } from '@/store/user'; | ||
import { ChatTopic } from '@/types/topic'; | ||
|
||
import { Placeholder, SkeletonList } from './SkeletonList'; | ||
import TopicItem from './TopicItem'; | ||
|
||
const TopicListContent = memo(() => { | ||
const { t } = useTranslation('chat'); | ||
const virtuosoRef = useRef<VirtuosoHandle>(null); | ||
const { isDarkMode } = useThemeMode(); | ||
const [topicsInit, activeTopicId, topicLength] = useChatStore((s) => [ | ||
s.topicsInit, | ||
s.activeTopicId, | ||
topicSelectors.currentTopicLength(s), | ||
]); | ||
const [visible, updateGuideState] = useUserStore((s) => [ | ||
s.preference.guide?.topic, | ||
s.updateGuideState, | ||
]); | ||
|
||
const topics = useChatStore( | ||
(s) => [ | ||
{ | ||
favorite: false, | ||
id: 'default', | ||
title: t('topic.defaultTitle'), | ||
} as ChatTopic, | ||
...topicSelectors.displayTopics(s), | ||
], | ||
isEqual, | ||
); | ||
|
||
const itemContent = useCallback( | ||
(index: number, { id, favorite, title }: ChatTopic) => | ||
index === 0 ? ( | ||
<TopicItem active={!activeTopicId} fav={favorite} title={title} /> | ||
) : ( | ||
<TopicItem active={activeTopicId === id} fav={favorite} id={id} key={id} title={title} /> | ||
), | ||
[activeTopicId], | ||
); | ||
|
||
const activeIndex = topics.findIndex((topic) => topic.id === activeTopicId); | ||
|
||
import Header from './Header'; | ||
import { Topic } from './Topic'; | ||
import TopicSearchBar from './TopicSearchBar'; | ||
|
||
const TopicListContent = ({ mobile }: { mobile?: boolean }) => { | ||
return ( | ||
<Flexbox gap={mobile ? 8 : 0} height={'100%'} style={{ overflow: 'hidden' }}> | ||
{mobile ? <TopicSearchBar /> : <Header />} | ||
<Flexbox gap={16} height={'100%'} style={{ paddingTop: 6, position: 'relative' }}> | ||
<Topic mobile={mobile} /> | ||
</Flexbox> | ||
</Flexbox> | ||
return !topicsInit ? ( | ||
<SkeletonList /> | ||
) : ( | ||
<> | ||
{topicLength === 0 && visible && ( | ||
<Flexbox paddingInline={8}> | ||
<EmptyCard | ||
alt={t('topic.guide.desc')} | ||
cover={imageUrl(`empty_topic_${isDarkMode ? 'dark' : 'light'}.webp`)} | ||
desc={t('topic.guide.desc')} | ||
height={120} | ||
imageProps={{ | ||
priority: true, | ||
}} | ||
onVisibleChange={(visible) => { | ||
updateGuideState({ topic: visible }); | ||
}} | ||
style={{ flex: 'none', marginBottom: 12 }} | ||
title={t('topic.guide.title')} | ||
visible={visible} | ||
width={200} | ||
/> | ||
</Flexbox> | ||
)} | ||
<Virtuoso | ||
components={{ ScrollSeekPlaceholder: Placeholder }} | ||
computeItemKey={(_, item) => item.id} | ||
data={topics} | ||
fixedItemHeight={44} | ||
initialTopMostItemIndex={Math.max(activeIndex, 0)} | ||
itemContent={itemContent} | ||
overscan={44 * 10} | ||
ref={virtuosoRef} | ||
scrollSeekConfiguration={{ | ||
enter: (velocity) => Math.abs(velocity) > 350, | ||
exit: (velocity) => Math.abs(velocity) < 10, | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
}); | ||
|
||
export default TopicListContent; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.