mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
fix tweak favoriting behavior
This commit is contained in:
3 files changed
+51
-7
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fixed tweak automatic favoriting behavior when entering/leaving the catalog.
|
||||
@@ -198,7 +198,6 @@ export function TweakPreviewUrlCard({ url }: { url: string }) {
|
||||
const nextEnabled = enabledTweakFullUrls.filter((u) => u !== url);
|
||||
patchSettings({
|
||||
themeRemoteEnabledTweakFullUrls: nextEnabled,
|
||||
themeRemoteTweakFavorites: pruneTweakFavorites(tweakFavorites, nextEnabled),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type ChangeEventHandler, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { type ChangeEventHandler, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTimeoutToggle } from '$hooks/useTimeoutToggle';
|
||||
import { copyToClipboard, downloadTextFile } from '$utils/dom';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
@@ -214,6 +214,9 @@ export function ThemeCatalogSettings({
|
||||
const [browseOpen, setBrowseOpen] = useState(false);
|
||||
const [importModalOpen, setImportModalOpen] = useState(false);
|
||||
|
||||
const appearanceCatalogBrowseWasOpenRef = useRef(false);
|
||||
const tweakFavoritesSnapshotAtAppearanceCatalogOpenRef = useRef<Set<string>>(new Set());
|
||||
|
||||
useEffect(() => {
|
||||
if (isAppearanceMode) {
|
||||
onBrowseOpenChange?.(browseOpen);
|
||||
@@ -248,6 +251,19 @@ export function ThemeCatalogSettings({
|
||||
'themeChatAutoPreviewAnyUrl'
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAppearanceMode) {
|
||||
appearanceCatalogBrowseWasOpenRef.current = false;
|
||||
return;
|
||||
}
|
||||
if (browseOpen && !appearanceCatalogBrowseWasOpenRef.current) {
|
||||
tweakFavoritesSnapshotAtAppearanceCatalogOpenRef.current = new Set(
|
||||
tweakFavorites.map((f) => f.fullUrl.trim()).filter(Boolean)
|
||||
);
|
||||
}
|
||||
appearanceCatalogBrowseWasOpenRef.current = browseOpen;
|
||||
}, [browseOpen, isAppearanceMode, tweakFavorites]);
|
||||
|
||||
const [themeSearch, setThemeSearch] = useState('');
|
||||
const [tweakSearch, setTweakSearch] = useState('');
|
||||
const [kindFilter, setKindFilter] = useState<'all' | 'light' | 'dark'>('all');
|
||||
@@ -779,7 +795,15 @@ export function ThemeCatalogSettings({
|
||||
}, [patchSettings]);
|
||||
|
||||
const setTweakApplied = useCallback(
|
||||
async (fullUrl: string, apply: boolean, hint?: { displayName?: string; basename?: string }) => {
|
||||
async (
|
||||
fullUrl: string,
|
||||
apply: boolean,
|
||||
hint?: {
|
||||
displayName?: string;
|
||||
basename?: string;
|
||||
pruneUnpinnedFavoriteOnDisable?: boolean;
|
||||
}
|
||||
) => {
|
||||
const trimmed = fullUrl.trim();
|
||||
if (!trimmed) return;
|
||||
|
||||
@@ -811,10 +835,25 @@ export function ThemeCatalogSettings({
|
||||
});
|
||||
} else {
|
||||
const nextEnabled = enabledTweakFullUrls.filter((u) => u !== trimmed);
|
||||
patchSettings({
|
||||
themeRemoteEnabledTweakFullUrls: nextEnabled,
|
||||
themeRemoteTweakFavorites: pruneTweakFavorites(tweakFavorites, nextEnabled),
|
||||
});
|
||||
if (hint?.pruneUnpinnedFavoriteOnDisable) {
|
||||
const enabledSet = new Set(nextEnabled);
|
||||
const inLibraryBeforeThisCatalogVisit =
|
||||
tweakFavoritesSnapshotAtAppearanceCatalogOpenRef.current;
|
||||
const nextTweakFavs = tweakFavorites.filter(
|
||||
(f) =>
|
||||
f.pinned === true ||
|
||||
enabledSet.has(f.fullUrl) ||
|
||||
inLibraryBeforeThisCatalogVisit.has(f.fullUrl.trim())
|
||||
);
|
||||
patchSettings({
|
||||
themeRemoteEnabledTweakFullUrls: nextEnabled,
|
||||
themeRemoteTweakFavorites: nextTweakFavs,
|
||||
});
|
||||
} else {
|
||||
patchSettings({
|
||||
themeRemoteEnabledTweakFullUrls: nextEnabled,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
[enabledTweakFullUrls, patchSettings, prefetchFull, pruneTweakFavorites, tweakFavorites]
|
||||
@@ -1468,6 +1507,7 @@ export function ThemeCatalogSettings({
|
||||
setTweakApplied(row.fullUrl, v, {
|
||||
displayName: row.displayName,
|
||||
basename: row.basename,
|
||||
pruneUnpinnedFavoriteOnDisable: true,
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user