fix(mobile): reset active-tab to home on ios/android when launched (#9245)

This commit is contained in:
CatsJuice
2024-12-24 03:39:56 +00:00
parent 3a8d90d861
commit 209c0889f8

View File

@@ -1,6 +1,6 @@
import { GlobalCacheService } from '@affine/core/modules/storage';
import { LiveData, useLiveData, useService } from '@toeverything/infra';
import { type PropsWithChildren, useCallback, useMemo } from 'react';
import { type PropsWithChildren, useCallback, useEffect, useMemo } from 'react';
import { tabItem } from './styles.css';
@@ -11,6 +11,7 @@ export interface TabItemProps extends PropsWithChildren {
}
const cacheKey = 'activeAppTabId';
let isInitialized = false;
export const TabItem = ({ id, label, children, onClick }: TabItemProps) => {
const globalCache = useService(GlobalCacheService).globalCache;
const activeTabId$ = useMemo(
@@ -26,6 +27,14 @@ export const TabItem = ({ id, label, children, onClick }: TabItemProps) => {
onClick?.(isActive);
}, [globalCache, id, isActive, onClick]);
useEffect(() => {
if (isInitialized) return;
isInitialized = true;
if (BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid) {
globalCache.set(cacheKey, 'home');
}
}, [globalCache]);
return (
<li
className={tabItem}