mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix(mobile): reset active-tab to home on ios/android when launched (#9245)
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user