Commit 28b793f7 authored by Joel's avatar Joel

fix: update conversation flash

parent 998f819b
...@@ -67,6 +67,8 @@ const Main: FC<IMainProps> = ({ ...@@ -67,6 +67,8 @@ const Main: FC<IMainProps> = ({
* conversation info * conversation info
*/ */
const [allConversationList, setAllConversationList] = useState<ConversationItem[]>([]) const [allConversationList, setAllConversationList] = useState<ConversationItem[]>([])
const [isClearConversationList, { setTrue: clearConversationListTrue, setFalse: clearConversationListFalse }] = useBoolean(false)
const [isClearPinnedConversationList, { setTrue: clearPinnedConversationListTrue, setFalse: clearPinnedConversationListFalse }] = useBoolean(false)
const { const {
conversationList, conversationList,
setConversationList, setConversationList,
...@@ -89,18 +91,32 @@ const Main: FC<IMainProps> = ({ ...@@ -89,18 +91,32 @@ const Main: FC<IMainProps> = ({
const [hasPinnedMore, setHasPinnedMore] = useState<boolean>(true) const [hasPinnedMore, setHasPinnedMore] = useState<boolean>(true)
const onMoreLoaded = ({ data: conversations, has_more }: any) => { const onMoreLoaded = ({ data: conversations, has_more }: any) => {
setHasMore(has_more) setHasMore(has_more)
if (isClearConversationList) {
setConversationList(conversations)
clearConversationListFalse()
}
else {
setConversationList([...conversationList, ...conversations]) setConversationList([...conversationList, ...conversations])
} }
}
const onPinnedMoreLoaded = ({ data: conversations, has_more }: any) => { const onPinnedMoreLoaded = ({ data: conversations, has_more }: any) => {
setHasPinnedMore(has_more) setHasPinnedMore(has_more)
if (isClearPinnedConversationList) {
setPinnedConversationList(conversations)
clearPinnedConversationListFalse()
}
else {
setPinnedConversationList([...pinnedConversationList, ...conversations]) setPinnedConversationList([...pinnedConversationList, ...conversations])
} }
}
const [controlUpdateConversationList, setControlUpdateConversationList] = useState(0) const [controlUpdateConversationList, setControlUpdateConversationList] = useState(0)
const noticeUpdateList = () => { const noticeUpdateList = () => {
setConversationList([])
setHasMore(true) setHasMore(true)
setPinnedConversationList([]) clearConversationListTrue()
setHasPinnedMore(true) setHasPinnedMore(true)
clearPinnedConversationListTrue()
setControlUpdateConversationList(Date.now()) setControlUpdateConversationList(Date.now())
} }
const handlePin = async (id: string) => { const handlePin = async (id: string) => {
...@@ -496,7 +512,9 @@ const Main: FC<IMainProps> = ({ ...@@ -496,7 +512,9 @@ const Main: FC<IMainProps> = ({
return ( return (
<Sidebar <Sidebar
list={conversationList} list={conversationList}
isClearConversationList={isClearConversationList}
pinnedList={pinnedConversationList} pinnedList={pinnedConversationList}
isClearPinnedConversationList={isClearPinnedConversationList}
onMoreLoaded={onMoreLoaded} onMoreLoaded={onMoreLoaded}
onPinnedMoreLoaded={onPinnedMoreLoaded} onPinnedMoreLoaded={onPinnedMoreLoaded}
isNoMore={!hasMore} isNoMore={!hasMore}
......
...@@ -17,7 +17,9 @@ export type ISidebarProps = { ...@@ -17,7 +17,9 @@ export type ISidebarProps = {
currentId: string currentId: string
onCurrentIdChange: (id: string) => void onCurrentIdChange: (id: string) => void
list: ConversationItem[] list: ConversationItem[]
isClearConversationList: boolean
pinnedList: ConversationItem[] pinnedList: ConversationItem[]
isClearPinnedConversationList: boolean
isInstalledApp: boolean isInstalledApp: boolean
installedAppId?: string installedAppId?: string
siteInfo: SiteInfo siteInfo: SiteInfo
...@@ -36,7 +38,9 @@ const Sidebar: FC<ISidebarProps> = ({ ...@@ -36,7 +38,9 @@ const Sidebar: FC<ISidebarProps> = ({
currentId, currentId,
onCurrentIdChange, onCurrentIdChange,
list, list,
isClearConversationList,
pinnedList, pinnedList,
isClearPinnedConversationList,
isInstalledApp, isInstalledApp,
installedAppId, installedAppId,
siteInfo, siteInfo,
...@@ -102,6 +106,7 @@ const Sidebar: FC<ISidebarProps> = ({ ...@@ -102,6 +106,7 @@ const Sidebar: FC<ISidebarProps> = ({
currentId={currentId} currentId={currentId}
onCurrentIdChange={onCurrentIdChange} onCurrentIdChange={onCurrentIdChange}
list={pinnedList} list={pinnedList}
isClearConversationList={isClearPinnedConversationList}
isInstalledApp={isInstalledApp} isInstalledApp={isInstalledApp}
installedAppId={installedAppId} installedAppId={installedAppId}
onMoreLoaded={onPinnedMoreLoaded} onMoreLoaded={onPinnedMoreLoaded}
...@@ -123,6 +128,7 @@ const Sidebar: FC<ISidebarProps> = ({ ...@@ -123,6 +128,7 @@ const Sidebar: FC<ISidebarProps> = ({
currentId={currentId} currentId={currentId}
onCurrentIdChange={onCurrentIdChange} onCurrentIdChange={onCurrentIdChange}
list={list} list={list}
isClearConversationList={isClearConversationList}
isInstalledApp={isInstalledApp} isInstalledApp={isInstalledApp}
installedAppId={installedAppId} installedAppId={installedAppId}
onMoreLoaded={onMoreLoaded} onMoreLoaded={onMoreLoaded}
......
...@@ -17,6 +17,7 @@ export type IListProps = { ...@@ -17,6 +17,7 @@ export type IListProps = {
currentId: string currentId: string
onCurrentIdChange: (id: string) => void onCurrentIdChange: (id: string) => void
list: ConversationItem[] list: ConversationItem[]
isClearConversationList: boolean
isInstalledApp: boolean isInstalledApp: boolean
installedAppId?: string installedAppId?: string
onMoreLoaded: (res: { data: ConversationItem[]; has_more: boolean }) => void onMoreLoaded: (res: { data: ConversationItem[]; has_more: boolean }) => void
...@@ -32,6 +33,7 @@ const List: FC<IListProps> = ({ ...@@ -32,6 +33,7 @@ const List: FC<IListProps> = ({
currentId, currentId,
onCurrentIdChange, onCurrentIdChange,
list, list,
isClearConversationList,
isInstalledApp, isInstalledApp,
installedAppId, installedAppId,
onMoreLoaded, onMoreLoaded,
...@@ -46,7 +48,7 @@ const List: FC<IListProps> = ({ ...@@ -46,7 +48,7 @@ const List: FC<IListProps> = ({
useInfiniteScroll( useInfiniteScroll(
async () => { async () => {
if (!isNoMore) { if (!isNoMore) {
const lastId = list[list.length - 1]?.id const lastId = !isClearConversationList ? list[list.length - 1]?.id : undefined
const { data: conversations, has_more }: any = await fetchConversations(isInstalledApp, installedAppId, lastId, isPinned) const { data: conversations, has_more }: any = await fetchConversations(isInstalledApp, installedAppId, lastId, isPinned)
onMoreLoaded({ data: conversations, has_more }) onMoreLoaded({ data: conversations, has_more })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment