Fix the order:hot default: seed the toggle and clear stale defaults
Two bugs made the toggle look broken even though the preference was stored correctly (JakeBreathild had online_hot_default false): - The Account card never seeded online_hot_default into its form state, so the checkbox always rendered checked via the '?? true' fallback. It now starts from the saved value. - Turning the toggle off did not change Online when the URL still carried tags=order:hot (e.g. Ctrl+Shift+R reloading the old URL). order:hot on its own is the default, not a deliberate search, so it is now removed when the account has the toggle off; 'order:hot canine' or any other search is still left untouched. The decision moved into hotDefault.ts (set-hot / clear-hot / keep) with the matrix verified in Node.
This commit is contained in:
@@ -25,6 +25,7 @@ export function PreferencesCard() {
|
|||||||
ordering: user?.preferences?.ordering ?? "-created_at",
|
ordering: user?.preferences?.ordering ?? "-created_at",
|
||||||
per_page: user?.preferences?.per_page ?? 48,
|
per_page: user?.preferences?.per_page ?? 48,
|
||||||
zoom: user?.preferences?.zoom ?? 190,
|
zoom: user?.preferences?.zoom ?? 190,
|
||||||
|
online_hot_default: user?.preferences?.online_hot_default ?? true,
|
||||||
});
|
});
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
postIsBlacklisted,
|
postIsBlacklisted,
|
||||||
type E621Post,
|
type E621Post,
|
||||||
} from "@/lib/e621";
|
} from "@/lib/e621";
|
||||||
|
import { hotDefaultAction, HOT_ORDER } from "@/features/online/hotDefault";
|
||||||
import { useE621 } from "@/store/e621";
|
import { useE621 } from "@/store/e621";
|
||||||
import { useAuth } from "@/store/auth";
|
import { useAuth } from "@/store/auth";
|
||||||
import { useUi } from "@/store/ui";
|
import { useUi } from "@/store/ui";
|
||||||
@@ -44,14 +45,21 @@ export default function OnlinePage() {
|
|||||||
const zoom = useUi((state) => state.zoom);
|
const zoom = useUi((state) => state.zoom);
|
||||||
const appliedHotDefault = useRef(false);
|
const appliedHotDefault = useRef(false);
|
||||||
|
|
||||||
// Landing on Online without a search uses the order:hot default (on unless
|
// Landing on Online follows the account's order:hot default: applied when
|
||||||
// the account turns it off). Existing searches are left alone.
|
// there is no search, removed when the saved URL only carries the default
|
||||||
|
// and the toggle was turned off. Deliberate searches are left alone.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!authReady || appliedHotDefault.current) return;
|
if (!authReady || appliedHotDefault.current) return;
|
||||||
appliedHotDefault.current = true;
|
appliedHotDefault.current = true;
|
||||||
if (tags) return;
|
const action = hotDefaultAction(
|
||||||
if (user?.preferences?.online_hot_default === false) return;
|
tags,
|
||||||
setSearchParams(buildParams("order:hot", 1), { replace: true });
|
user?.preferences?.online_hot_default !== false,
|
||||||
|
);
|
||||||
|
if (action === "set-hot") {
|
||||||
|
setSearchParams(buildParams(HOT_ORDER, 1), { replace: true });
|
||||||
|
} else if (action === "clear-hot") {
|
||||||
|
setSearchParams(buildParams("", 1), { replace: true });
|
||||||
|
}
|
||||||
}, [authReady, tags, user, setSearchParams]);
|
}, [authReady, tags, user, setSearchParams]);
|
||||||
|
|
||||||
const blacklistMutation = useMutation({
|
const blacklistMutation = useMutation({
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/** The metatag the Online page opens with when the account toggle is on. */
|
||||||
|
export const HOT_ORDER = "order:hot";
|
||||||
|
|
||||||
|
export type HotDefaultAction = "set-hot" | "clear-hot" | "keep";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decide what the Online default should do for a given search.
|
||||||
|
*
|
||||||
|
* `order:hot` on its own is the default, not a deliberate search: it is
|
||||||
|
* applied when the toggle is on and removed when the account turns it off
|
||||||
|
* (so a reload of an old URL follows the new setting). Any other search is
|
||||||
|
* left untouched.
|
||||||
|
*/
|
||||||
|
export function hotDefaultAction(
|
||||||
|
tags: string,
|
||||||
|
hotDefaultOn: boolean,
|
||||||
|
): HotDefaultAction {
|
||||||
|
const trimmed = tags.trim();
|
||||||
|
if (trimmed === HOT_ORDER) return hotDefaultOn ? "keep" : "clear-hot";
|
||||||
|
if (!trimmed) return hotDefaultOn ? "set-hot" : "keep";
|
||||||
|
return "keep";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user