mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +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 { GlobalCacheService } from '@affine/core/modules/storage';
|
||||||
import { LiveData, useLiveData, useService } from '@toeverything/infra';
|
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';
|
import { tabItem } from './styles.css';
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ export interface TabItemProps extends PropsWithChildren {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cacheKey = 'activeAppTabId';
|
const cacheKey = 'activeAppTabId';
|
||||||
|
let isInitialized = false;
|
||||||
export const TabItem = ({ id, label, children, onClick }: TabItemProps) => {
|
export const TabItem = ({ id, label, children, onClick }: TabItemProps) => {
|
||||||
const globalCache = useService(GlobalCacheService).globalCache;
|
const globalCache = useService(GlobalCacheService).globalCache;
|
||||||
const activeTabId$ = useMemo(
|
const activeTabId$ = useMemo(
|
||||||
@@ -26,6 +27,14 @@ export const TabItem = ({ id, label, children, onClick }: TabItemProps) => {
|
|||||||
onClick?.(isActive);
|
onClick?.(isActive);
|
||||||
}, [globalCache, id, isActive, onClick]);
|
}, [globalCache, id, isActive, onClick]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isInitialized) return;
|
||||||
|
isInitialized = true;
|
||||||
|
if (BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid) {
|
||||||
|
globalCache.set(cacheKey, 'home');
|
||||||
|
}
|
||||||
|
}, [globalCache]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
className={tabItem}
|
className={tabItem}
|
||||||
|
|||||||
Reference in New Issue
Block a user