Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-tweak-favoriting-behavior.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Fixed tweak automatic favoriting behavior when entering/leaving the catalog.
1 change: 0 additions & 1 deletion src/app/components/url-preview/TweakPreviewUrlCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ export function TweakPreviewUrlCard({ url }: { url: string }) {
const nextEnabled = enabledTweakFullUrls.filter((u) => u !== url);
patchSettings({
themeRemoteEnabledTweakFullUrls: nextEnabled,
themeRemoteTweakFavorites: pruneTweakFavorites(tweakFavorites, nextEnabled),
});
}
},
Expand Down
52 changes: 46 additions & 6 deletions src/app/features/settings/cosmetics/ThemeCatalogSettings.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -1468,6 +1507,7 @@ export function ThemeCatalogSettings({
setTweakApplied(row.fullUrl, v, {
displayName: row.displayName,
basename: row.basename,
pruneUnpinnedFavoriteOnDisable: true,
})
}
/>
Expand Down
Loading