余额
- {credits} 点
+ 点
);
}
diff --git a/frontend/src/components/credits-value.tsx b/frontend/src/components/credits-value.tsx
new file mode 100644
index 000000000..3e6bd2003
--- /dev/null
+++ b/frontend/src/components/credits-value.tsx
@@ -0,0 +1,28 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+
+/**
+ * BUG-2331: a points number that changed (a charge, a refund, a redeemed code) settles
+ * in from the side it moved toward — up when it grew, down when it fell — so the change
+ * reads as a change and not as a redraw. The first render just shows the number.
+ */
+export function CreditsValue({ value, className }: { readonly value: number; readonly className?: string }) {
+ const previous = useRef(value);
+ const [tick, setTick] = useState<{ key: number; direction: "up" | "down" } | null>(null);
+ useEffect(() => {
+ if (previous.current === value) return;
+ const direction = value > previous.current ? "up" : "down";
+ previous.current = value;
+ setTick((current) => ({ key: (current?.key ?? 0) + 1, direction }));
+ }, [value]);
+ return (
+
+ {value}
+
+ );
+}
diff --git a/frontend/src/components/shell-frame.tsx b/frontend/src/components/shell-frame.tsx
index ed290ba4f..1e512ee11 100644
--- a/frontend/src/components/shell-frame.tsx
+++ b/frontend/src/components/shell-frame.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, type ReactNode } from "react";
+import { useEffect, useRef, useState, type ReactNode } from "react";
import { Button } from "@/components/ui/button";
import { useSidebar } from "@/components/ui/sidebar";
@@ -12,6 +12,7 @@ import {
SIDEBAR_WIDTH_MIN,
SIDEBAR_WIDTH_TABLET,
} from "@/lib/sidebar-state";
+import { MOTION_MS } from "@/lib/motion/tokens";
import { useUiStore } from "@/stores/ui-store";
export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children: ReactNode }) {
@@ -30,6 +31,20 @@ export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children
hydrate();
}, [hydrate]);
+ // BUG-2331: the collapse/expand toggle glides the column between its two widths
+ // (standard step); a drag never sets this, so the edge stays under the pointer.
+ const [gliding, setGliding] = useState(false);
+ const lastOpen = useRef(open);
+ const dragging = useRef(false);
+ useEffect(() => {
+ if (lastOpen.current === open) return undefined;
+ lastOpen.current = open;
+ if (!desktop || dragging.current) return undefined;
+ setGliding(true);
+ const timer = window.setTimeout(() => setGliding(false), MOTION_MS.standard + 40);
+ return () => window.clearTimeout(timer);
+ }, [open, desktop]);
+
const resize = useDragWidth({
width: pixelWidth,
min: SIDEBAR_WIDTH_MIN,
@@ -49,6 +64,7 @@ export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children
// bundle runs) the slot is "pending": CSS sizes it by media query and the
// stored width, never by its content (the narrow cold-boot sidebar).
data-shell-resize={!ready ? "pending" : desktop ? "live" : "mobile"}
+ data-shell-gliding={gliding ? "true" : undefined}
style={desktop ? { ["--shell-sidebar-width" as string]: `${pixelWidth}px` } : undefined}
>
@@ -60,6 +76,17 @@ export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children
className="shell-resize-handle"
aria-label="调整侧栏宽度"
{...resize}
+ onPointerDown={(event) => {
+ dragging.current = true;
+ const release = () => {
+ dragging.current = false;
+ window.removeEventListener("pointerup", release);
+ window.removeEventListener("pointercancel", release);
+ };
+ window.addEventListener("pointerup", release);
+ window.addEventListener("pointercancel", release);
+ resize.onPointerDown(event);
+ }}
/>
) : null}
diff --git a/frontend/tests/motion-shell-2331.test.ts b/frontend/tests/motion-shell-2331.test.ts
new file mode 100644
index 000000000..4f193c4c2
--- /dev/null
+++ b/frontend/tests/motion-shell-2331.test.ts
@@ -0,0 +1,66 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+
+// BUG-2331: the app shell (sidebar, login, onboarding, account dialogs, points, admin) moves
+// on the BUG-2327 tokens only, never with a raw duration, never with overshoot.
+
+const css = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
+const read = (path: string) => readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8");
+const marker = "/* BUG-2331 motion — shell.";
+const block = css.slice(css.indexOf(marker));
+
+test("the shell block exists and uses only motion tokens", () => {
+ assert.ok(css.includes(marker), "the BUG-2331 block is appended to globals.css");
+ const durations = block.match(/\b\d+(?:\.\d+)?m?s\b/g) ?? [];
+ assert.deepEqual(durations, [], `no raw durations in the shell block: ${durations.join(", ")}`);
+ assert.doesNotMatch(block, /cubic-bezier\(/, "curves come from the --ease-* tokens");
+});
+
+test("the shell block animates only opacity and transform (plus the one sidebar column glide)", () => {
+ const props = [...block.matchAll(/transition(?:-property)?:\s*([^;]+);/g)].map((m) => m[1]);
+ for (const value of props) {
+ const named = value.split(",").map((part) => part.trim().split(/\s+/)[0]);
+ for (const name of named) {
+ assert.ok(
+ ["opacity", "transform", "background-color", "box-shadow", "color", "flex-basis", "width"].includes(name),
+ `unexpected transition property ${name}`,
+ );
+ }
+ }
+ assert.match(block, /\.shell-frame\[data-shell-gliding="true"\] > \.shell-sidebar-slot \{\s*transition: flex-basis var\(--motion-standard\)/);
+ assert.doesNotMatch(block.replace(/\.shell-frame\[data-shell-gliding="true"\] > \.shell-sidebar-slot \{[^}]*\}/, ""), /transition[^;]*\bwidth\b/);
+});
+
+test("the sidebar column glides only on toggle, never while the edge is dragged", () => {
+ const frame = read("components/shell-frame.tsx");
+ assert.match(frame, /data-shell-gliding=\{gliding \? "true" : undefined\}/);
+ assert.match(frame, /if \(!desktop \|\| dragging\.current\) return undefined;/);
+ assert.match(frame, /MOTION_MS\.standard/);
+});
+
+test("a dragged conversation row keeps no transform transition", () => {
+ const rule = block.match(/\.sidebar-session \{ transition-property: ([^;]+);/);
+ assert.ok(rule);
+ assert.doesNotMatch(rule[1], /transform/);
+});
+
+test("redeem success settles without overshoot", () => {
+ assert.match(block, /\.redeem-success-dialog \{ animation: redeem-success-pop var\(--motion-emphasis\) var\(--ease-out\) both; \}/);
+});
+
+test("a changed points number ticks from the side it moved; the first render does not", () => {
+ const source = read("components/credits-value.tsx");
+ assert.match(source, /if \(previous\.current === value\) return;/);
+ assert.match(source, /data-credits-tick=\{tick \? tick\.direction : undefined\}/);
+ assert.match(read("components/app-sidebar.tsx"), / {
+ const admin = read("components/admin/admin-app.tsx");
+ for (const token of ["motionDurationFast", "motionDurationMid", "motionDurationSlow", "motionEaseOut", "motionEaseOutBack"]) {
+ assert.match(admin, new RegExp(`${token}: `), token);
+ }
+ assert.match(admin, /motionEaseOutBack: `cubic-bezier\(\$\{MOTION_EASE\.out\.join/);
+});