Skip to content

Commit 100ca82

Browse files
committed
refactor: ♻️ 统一 fab 显示逻辑
1 parent 515484e commit 100ca82

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/userscript/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export type CoreStore<T extends Record<string, any>> = {
7272
isStored: boolean;
7373
/** 当前是否还需要判断 autoShow */
7474
needAutoShow: boolean;
75+
/** 当前是否有对应的页面处理逻辑 */
76+
hasPageHandler: boolean;
7577
};
7678
};
7779

src/userscript/core/siteAdapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ export const setupSiteAdapter = async <
170170
const isMangePage = newPageCtx?.type === 'manga';
171171

172172
setState((state) => {
173-
state.fab.show = isMangePage ? undefined : false;
173+
state.flag.hasPageHandler =
174+
Boolean(newPageCtx?.type) && Reflect.has(handlers, newPageCtx!.type);
174175
state.manga.show = false;
175176
});
176177

src/userscript/core/useFab.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export const useFab = <T extends Record<string, any>>(
105105

106106
state.fab.progress = 1 + loadNum / totalNum;
107107
state.fab.tip = t('other.read_mode');
108-
state.fab.show = !options.hiddenFab && undefined;
109108
}),
110109
);
111110

src/userscript/core/useInit.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
t,
1313
useStore,
1414
} from 'helper';
15+
import { createEffect } from 'solid-js';
1516

1617
import { type CoreContext, type CoreStore, type SiteOptions } from '.';
1718
import { useFab } from './useFab';
@@ -67,6 +68,7 @@ export const useInit = async <T extends Record<string, unknown>>(
6768
flag: {
6869
isStored: saveOptions !== undefined,
6970
needAutoShow: true,
71+
hasPageHandler: false,
7072
},
7173
});
7274
setDefaultHotkeys((_hotkeys) => ({
@@ -131,7 +133,6 @@ export const useInit = async <T extends Record<string, unknown>>(
131133

132134
setState('fab', {
133135
onClick: () => void showComic(),
134-
show: !options.hiddenFab && undefined,
135136
});
136137

137138
if (autoShow && store.flag.needAutoShow && options.autoShow)
@@ -219,6 +220,18 @@ export const useInit = async <T extends Record<string, unknown>>(
219220
return comic.imgList.filter((_, i) => !comic.adList?.has(i));
220221
});
221222

223+
createEffect(() => {
224+
// 多选模式下悬浮按钮持续显示
225+
if (store.fab.multiSelectCount !== undefined)
226+
return setState('fab', 'show', true);
227+
228+
setState(
229+
'fab',
230+
'show',
231+
store.flag.hasPageHandler && !options.hiddenFab ? undefined : false,
232+
);
233+
});
234+
222235
createEffectOn(
223236
nowImgList,
224237
(list) => list && setState('manga', 'imgList', list),
@@ -235,7 +248,6 @@ export const useInit = async <T extends Record<string, unknown>>(
235248
options.hiddenFab ? t('other.fab_show') : t('other.fab_hidden'),
236249
() => {
237250
setOptions({ hiddenFab: !options.hiddenFab });
238-
setState('fab', 'show', !options.hiddenFab && undefined);
239251
return updateHideFabMenu();
240252
},
241253
);

src/userscript/multiSelect/useMultiSelectLoad.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type UseMultiSelectLoadOptions = {
3434
};
3535

3636
export const useMultiSelectLoad = <T extends Record<string, any>>(
37-
{ setState, showComic, options }: CoreContext<T>,
37+
{ setState, showComic }: CoreContext<T>,
3838
{ id: initListid, onStart, getImgList }: UseMultiSelectLoadOptions,
3939
) =>
4040
createRoot(async (dispose) => {
@@ -84,7 +84,6 @@ export const useMultiSelectLoad = <T extends Record<string, any>>(
8484
if (enabled) {
8585
state.fab.multiSelectCount = count;
8686
state.fab.onClick = multiSelectLoad;
87-
state.fab.show = true;
8887
state.fab.overrideSpeedDial = [
8988
{
9089
name: t('other.clear'),
@@ -95,7 +94,6 @@ export const useMultiSelectLoad = <T extends Record<string, any>>(
9594
} else {
9695
state.fab.multiSelectCount = undefined;
9796
state.fab.onClick = showComic;
98-
state.fab.show = !options.hiddenFab && undefined;
9997
state.fab.overrideSpeedDial = undefined;
10098
}
10199
});

0 commit comments

Comments
 (0)