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
13 changes: 13 additions & 0 deletions tests/memory-count.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, test } from "bun:test";
import { getDisplayedMemoryCount } from "../web/src/lib/memory-count";

describe("getDisplayedMemoryCount", () => {
test("shows matched results while search is active", () => {
expect(getDisplayedMemoryCount(true, 3, 120)).toBe(3);
expect(getDisplayedMemoryCount(true, 0, 120)).toBe(0);
});

test("restores the store total when search is cleared", () => {
expect(getDisplayedMemoryCount(false, 3, 120)).toBe(120);
});
});
11 changes: 10 additions & 1 deletion web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Label } from "$lib/components/ui/label";
import { Toaster } from "$lib/components/ui/sonner";
import { Textarea } from "$lib/components/ui/textarea";
import { cycleLanguage, getLanguage, useI18n } from "$lib/i18n";
import { getDisplayedMemoryCount } from "$lib/memory-count";
import { initRouter, navigate, ROUTES, useAppView } from "$lib/router";

const MEMORY_TYPES = [
Expand Down Expand Up @@ -142,7 +143,15 @@ export default function App() {
</h1>
{currentView === "project" ? (
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<span>{t("text-total", { count: explorer.statsTotal })}</span>
<span>
{t("text-total", {
count: getDisplayedMemoryCount(
explorer.isSearching,
explorer.totalItems,
explorer.statsTotal
),
})}
</span>
{explorer.refreshing ? <Loader className="size-3.5 animate-spin" /> : null}
</div>
) : null}
Expand Down
7 changes: 7 additions & 0 deletions web/src/lib/memory-count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function getDisplayedMemoryCount(
isSearching: boolean,
searchTotal: number,
storeTotal: number
): number {
return isSearching ? searchTotal : storeTotal;
}