Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@react-pdf/types": "^2.11.1",
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^24.0.0",
"@types/qrcode": "^1.5.6",
Expand Down
11 changes: 9 additions & 2 deletions apps/api/src/infrastructure/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { sqliteTable, text, integer, index, uniqueIndex } from 'drizzle-orm/sqlite-core';
import {
sqliteTable,
text,
integer,
index,
uniqueIndex,
type AnySQLiteColumn,
} from 'drizzle-orm/sqlite-core';

export const user = sqliteTable('User', {
id: text('id').primaryKey(),
Expand Down Expand Up @@ -422,7 +429,7 @@ export const document = sqliteTable(
storageKey: text('storageKey').notNull().unique(),
documentType: text('documentType').notNull().default('other'),
version: text('version'),
sourceDraftId: text('sourceDraftId').references((): any => documentDraft.id, {
sourceDraftId: text('sourceDraftId').references((): AnySQLiteColumn => documentDraft.id, {
onDelete: 'set null',
}),
createdAt: integer('createdAt', { mode: 'timestamp_ms' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IPdfRenderer, PdfRenderData } from '#src/use-cases/ports/IPdfRenderer.js';
import type { JSONContent } from '@tiptap/core';
import type { Style } from '@react-pdf/types';

function extractTextFromNode(node: JSONContent): string {
if (node.text) return node.text;
Expand Down Expand Up @@ -133,8 +134,7 @@ export class ReactPdfDocumentRenderer implements IPdfRenderer {
}

if (node.type === 'text') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let textStyle: any = {};
let textStyle: Style = {};
if (node.marks) {
for (const mark of node.marks) {
if (mark.type === 'bold') textStyle = { ...textStyle, fontFamily: 'Helvetica-Bold' };
Expand Down
2 changes: 1 addition & 1 deletion apps/web/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default tseslint.config(
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-explicit-any': ['warn', { ignoreRestArgs: true }],
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
},
},
Expand Down
25 changes: 25 additions & 0 deletions apps/web/src/__tests__/components/ApplicationsPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,31 @@ describe('ApplicationsPage', () => {
});
expect(screen.queryByText('2 selected')).not.toBeInTheDocument();
});

it('optimistically removes deleted applications from the list', async () => {
render(<ApplicationsPage />, { wrapper: Wrapper });
await waitFor(() => expect(screen.getByText('Stripe')).toBeInTheDocument());

fireEvent.click(screen.getByLabelText('Select all'));
mockMutationResult({ deleteApplication: true });

fireEvent.click(screen.getByRole('button', { name: 'Delete selected' }));

// The optimistic update writes directly into the query-cache entry the
// list renders from. mockMutationResult's refetch mock deliberately
// keeps returning the unfiltered list, so only a correctly-keyed
// optimistic write — not the eventual refetch — can make these rows
// disappear here; a wrong cache key would leave them visible.
expect(screen.queryByText('Stripe')).not.toBeInTheDocument();
expect(screen.queryByText('Vercel')).not.toBeInTheDocument();

await waitFor(() => {
expect(mockGqlRequest).toHaveBeenCalledWith(expect.stringContaining('deleteApplication'), {
id: '1',
});
});
});

it('does not delete when undo is clicked', async () => {
// Override mock to NOT execute immediately
const { showUndoToast } = await import('#/lib/undoToast');
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ expect.extend(toHaveNoViolations);
// useState initializers, which run during render before any effect.
if (typeof localStorage === 'undefined') {
const store: Record<string, string> = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).localStorage = {
globalThis.localStorage = {
getItem(key: string) {
return store[key] ?? null;
},
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/hooks/useDebouncedCallback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useRef } from 'react';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useDebouncedCallback<T extends (...args: any[]) => void>(
callback: T,
delay: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,16 @@ export function ApplicationDetailPage() {
</button>
<button
onClick={() => {
const snapshot = qc.getQueryData(['notes', applicationId]);
qc.setQueryData(['notes', applicationId], (prev: any) => ({
notes: (prev?.notes ?? []).filter((n: any) => n.id !== note.id),
}));
const snapshot = qc.getQueryData<{ notes: Note[] }>([
'notes',
applicationId,
]);
qc.setQueryData<{ notes: Note[] }>(
['notes', applicationId],
(prev) => ({
notes: (prev?.notes ?? []).filter((n) => n.id !== note.id),
}),
);
Comment on lines +484 to +493

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '=== diff stat ==='
git diff --stat

printf '%s\n' '=== changed files ==='
git diff --name-only

printf '%s\n' '=== candidate test files ==='
git ls-files | rg '(^|/)(__tests__/|.*\.(test|spec)\.(ts|tsx)$)' | rg 'ApplicationDetailPage|ContactsTab|DocumentsTab|InterviewsTab|ApplicationsPage|applications'

printf '%s\n' '=== relevant symbols and test references ==='
rg -n --glob '*.ts' --glob '*.tsx' \
  'ApplicationDetailPage|ContactsTab|DocumentsTab|InterviewsTab|ApplicationsPage|optimistic|undo|restore|setQueryData|getQueryData' \
  apps/web/src/routes/_authenticated/applications

Repository: mankatcheung/job-finder

Length of output: 15552


🏁 Script executed:

#!/bin/bash
set -eu

for f in \
  apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx \
  apps/web/src/__tests__/components/ApplicationsPage.test.tsx \
  apps/web/src/__tests__/components/ContactsTab.test.tsx \
  apps/web/src/__tests__/components/DocumentsTab.test.tsx \
  apps/web/src/__tests__/components/InterviewsTab.test.tsx
do
  printf '\n=== %s ===\n' "$f"
  wc -l "$f"
  ast-grep outline "$f" || true
  printf '%s\n' '--- targeted references ---'
  rg -n -C 5 \
    'delete|remove|undo|showUndoToast|onUndo|notes|contacts|documentDrafts|documents|interviewRounds|applications|infinite|page' \
    "$f" || true
done

Repository: mankatcheung/job-finder

Length of output: 36398


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '=== ApplicationDetailPage handler and test ==='
sed -n '470,505p' \
  apps/web/src/routes/_authenticated/applications/\$applicationId/-components/ApplicationDetailPage.tsx
sed -n '475,510p' \
  apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx

printf '%s\n' '=== ContactsTab handler and test ==='
sed -n '340,370p' \
  apps/web/src/routes/_authenticated/applications/\$applicationId/-components/ContactsTab.tsx
sed -n '120,151p' \
  apps/web/src/__tests__/components/ContactsTab.test.tsx

printf '%s\n' '=== DocumentsTab handlers and test ==='
sed -n '232,265p;386,418p' \
  apps/web/src/routes/_authenticated/applications/\$applicationId/-components/DocumentsTab.tsx
sed -n '108,138p' \
  apps/web/src/__tests__/components/DocumentsTab.test.tsx

printf '%s\n' '=== InterviewsTab handler and test ==='
sed -n '415,450p' \
  apps/web/src/routes/_authenticated/applications/\$applicationId/-components/InterviewsTab.tsx
sed -n '100,128p' \
  apps/web/src/__tests__/components/InterviewsTab.test.tsx

printf '%s\n' '=== ApplicationsPage handler and tests ==='
sed -n '295,340p' \
  apps/web/src/routes/_authenticated/applications/-components/ApplicationsPage.tsx
sed -n '430,485p' \
  apps/web/src/__tests__/components/ApplicationsPage.test.tsx

Repository: mankatcheung/job-finder

Length of output: 16323


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

sites = [
    (
        "ApplicationDetailPage",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/ApplicationDetailPage.tsx"),
        Path("apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx"),
        "notes",
        "deletes a note",
    ),
    (
        "ContactsTab",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/ContactsTab.tsx"),
        Path("apps/web/src/__tests__/components/ContactsTab.test.tsx"),
        "contacts",
        "deletes a contact",
    ),
    (
        "DocumentsTab draft",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx"),
        Path("apps/web/src/__tests__/components/DocumentsTab.test.tsx"),
        "documentDrafts",
        "deletes a draft",
    ),
    (
        "DocumentsTab document",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx"),
        Path("apps/web/src/__tests__/components/DocumentsTab.test.tsx"),
        "documents",
        "deletes a document",
    ),
    (
        "InterviewsTab",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/InterviewsTab.tsx"),
        Path("apps/web/src/__tests__/components/InterviewsTab.test.tsx"),
        "interviewRounds",
        "deletes an interview round",
    ),
    (
        "ApplicationsPage",
        Path("apps/web/src/routes/_authenticated/applications/-components/ApplicationsPage.tsx"),
        Path("apps/web/src/__tests__/components/ApplicationsPage.test.tsx"),
        "applications",
        "bulk-deletes selected applications",
    ),
]

for name, source_path, test_path, cache_key, test_name in sites:
    source = source_path.read_text()
    tests = test_path.read_text()
    implementation_has_undo = (
        f"setQueryData(['{cache_key}'" in source
        and "onUndo:" in source
    )
    match = re.search(
        rf"\bit\(['\"]{re.escape(test_name)}['\"].*?(?=\n\s*\}\);|\n\s*\}}\);)",
        tests,
        re.S,
    )
    block = match.group(0) if match else ""
    has_cache_assertion = any(
        token in block
        for token in ("getQueryData", "setQueryData", "getQueryData", "getQueryCache", "queryClient.get")
    )
    has_undo_assertion = "onUndo" in block or "undo" in block.lower() and "expect" in block
    print(
        f"{name}: implementation_onUndo={implementation_has_undo}; "
        f"delete_test={'present' if match else 'missing'}; "
        f"cache_assertion={has_cache_assertion}; undo_assertion={has_undo_assertion}"
    )

mock = Path("apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx").read_text()
print(
    "shared_mock: "
    f"executes_onExecute={'onExecute();' in mock}; "
    f"invokes_onUndo={'onUndo' in mock.split('vi.mock(\\'`#/lib/undoToast`\\'')[1].split('}));', 1)[0]}"
)
PY

Repository: mankatcheung/job-finder

Length of output: 390


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

sites = [
    (
        "ApplicationDetailPage",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/ApplicationDetailPage.tsx"),
        Path("apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx"),
        "notes",
        "deletes a note",
    ),
    (
        "ContactsTab",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/ContactsTab.tsx"),
        Path("apps/web/src/__tests__/components/ContactsTab.test.tsx"),
        "contacts",
        "deletes a contact",
    ),
    (
        "DocumentsTab draft",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx"),
        Path("apps/web/src/__tests__/components/DocumentsTab.test.tsx"),
        "documentDrafts",
        "deletes a draft",
    ),
    (
        "DocumentsTab document",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx"),
        Path("apps/web/src/__tests__/components/DocumentsTab.test.tsx"),
        "documents",
        "deletes a document",
    ),
    (
        "InterviewsTab",
        Path("apps/web/src/routes/_authenticated/applications/$applicationId/-components/InterviewsTab.tsx"),
        Path("apps/web/src/__tests__/components/InterviewsTab.test.tsx"),
        "interviewRounds",
        "deletes an interview round",
    ),
    (
        "ApplicationsPage",
        Path("apps/web/src/routes/_authenticated/applications/-components/ApplicationsPage.tsx"),
        Path("apps/web/src/__tests__/components/ApplicationsPage.test.tsx"),
        "applications",
        "bulk-deletes selected applications",
    ),
]

for name, source_path, test_path, cache_key, test_name in sites:
    source = source_path.read_text()
    tests = test_path.read_text()
    implementation_has_undo = (
        f"setQueryData(['{cache_key}'" in source
        and "onUndo:" in source
    )
    match = re.search(
        rf"\bit\(['\"]{re.escape(test_name)}['\"].*?(?=\n\s*\}\);|\n\s*\}}\);)",
        tests,
        re.S,
    )
    block = match.group(0) if match else ""
    has_cache_assertion = any(
        token in block
        for token in ("getQueryData", "setQueryData", "getQueryCache", "queryClient.get")
    )
    has_undo_assertion = "onUndo" in block or (
        "undo" in block.lower() and "expect" in block
    )
    print(
        f"{name}: implementation_onUndo={implementation_has_undo}; "
        f"delete_test={'present' if match else 'missing'}; "
        f"cache_assertion={has_cache_assertion}; undo_assertion={has_undo_assertion}"
    )

mock = Path("apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx").read_text()
mock_section = mock.split("vi.mock('`#/lib/undoToast`'", 1)[1].split("}));", 1)[0]
print(
    "shared_mock: "
    f"executes_onExecute={'onExecute();' in mock_section}; "
    f"invokes_onUndo={'onUndo' in mock_section}"
)
PY

Repository: mankatcheung/job-finder

Length of output: 390


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

sites = [
    (
        "ApplicationDetailPage",
        "apps/web/src/routes/_authenticated/applications/$applicationId/-components/ApplicationDetailPage.tsx",
        "apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx",
        "deletes a note",
    ),
    (
        "ContactsTab",
        "apps/web/src/routes/_authenticated/applications/$applicationId/-components/ContactsTab.tsx",
        "apps/web/src/__tests__/components/ContactsTab.test.tsx",
        "deletes a contact",
    ),
    (
        "DocumentsTab draft",
        "apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx",
        "apps/web/src/__tests__/components/DocumentsTab.test.tsx",
        "deletes a draft",
    ),
    (
        "DocumentsTab document",
        "apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx",
        "apps/web/src/__tests__/components/DocumentsTab.test.tsx",
        "deletes a document",
    ),
    (
        "InterviewsTab",
        "apps/web/src/routes/_authenticated/applications/$applicationId/-components/InterviewsTab.tsx",
        "apps/web/src/__tests__/components/InterviewsTab.test.tsx",
        "deletes an interview round",
    ),
    (
        "ApplicationsPage",
        "apps/web/src/routes/_authenticated/applications/-components/ApplicationsPage.tsx",
        "apps/web/src/__tests__/components/ApplicationsPage.test.tsx",
        "bulk-deletes selected applications",
    ),
]

for name, source_name, test_name_path, test_name in sites:
    source = Path(source_name).read_text()
    tests = Path(test_name_path).read_text()
    pattern = (
        r"\bit\(['\"]" + re.escape(test_name)
        + r"['\"].*?(?=\n\s*\}\);)"
    )
    match = re.search(pattern, tests, re.S)
    block = match.group(0) if match else ""
    print(
        f"{name}: "
        f"implementation_onUndo={'onUndo:' in source}; "
        f"delete_test={'present' if match else 'missing'}; "
        f"cache_assertion={any(x in block for x in ('getQueryData', 'setQueryData', 'getQueryCache'))}; "
        f"undo_assertion={'onUndo' in block or ('undo' in block.lower() and 'expect' in block)}"
    )

mock = Path("apps/web/src/__tests__/components/ApplicationDetailPage.test.tsx").read_text()
mock_section = mock.split("vi.mock('`#/lib/undoToast`'", 1)[1].split("}));", 1)[0]
print(
    "shared_mock: "
    f"executes_onExecute={'onExecute();' in mock_section}; "
    f"invokes_onUndo={'onUndo' in mock_section}"
)
PY

Repository: mankatcheung/job-finder

Length of output: 890


Add coverage for optimistic deletion and undo restoration.

The existing deletion tests assert mutation requests only. No test covers document-draft deletion, optimistic cache removal, or undo restoration. Use a controllable showUndoToast mock and cover all six handlers, including removal across all ApplicationsPage pages.

📍 Affects 5 files
  • apps/web/src/routes/_authenticated/applications/$applicationId/-components/ApplicationDetailPage.tsx#L484-L493 (this comment)
  • apps/web/src/routes/_authenticated/applications/$applicationId/-components/ContactsTab.tsx#L350-L359
  • apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx#L242-L251
  • apps/web/src/routes/_authenticated/applications/$applicationId/-components/DocumentsTab.tsx#L396-L405
  • apps/web/src/routes/_authenticated/applications/$applicationId/-components/InterviewsTab.tsx#L425-L436
  • apps/web/src/routes/_authenticated/applications/-components/ApplicationsPage.tsx#L306-L319
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/web/src/routes/_authenticated/applications/`$applicationId/-components/ApplicationDetailPage.tsx
around lines 484 - 493, Add tests covering optimistic deletion and undo
restoration for all six handlers, using a controllable showUndoToast mock:
ApplicationDetailPage.tsx lines 484-493, ContactsTab.tsx lines 350-359,
DocumentsTab.tsx lines 242-251 and 396-405, InterviewsTab.tsx lines 425-436, and
ApplicationsPage.tsx lines 306-319. Verify document-draft deletion, optimistic
cache removal, restoration on undo, and removal of the deleted item across every
ApplicationsPage pagination page; retain existing mutation-request assertions.

Source: Coding guidelines

showUndoToast({
message: 'Note deleted',
onExecute: () => deleteNote.mutate(note.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,16 @@ export function ContactsTab({ applicationId }: { applicationId: string }) {
</button>
<button
onClick={() => {
const snapshot = qc.getQueryData(['contacts', applicationId]);
qc.setQueryData(['contacts', applicationId], (prev: any) => ({
contacts: (prev?.contacts ?? []).filter((c: any) => c.id !== contact.id),
}));
const snapshot = qc.getQueryData<{ contacts: Contact[] }>([
'contacts',
applicationId,
]);
qc.setQueryData<{ contacts: Contact[] }>(
['contacts', applicationId],
(prev) => ({
contacts: (prev?.contacts ?? []).filter((c) => c.id !== contact.id),
}),
);
showUndoToast({
message: 'Contact deleted',
onExecute: () => deleteContact.mutate(contact.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,16 @@ export function DocumentsTab({ applicationId }: { applicationId: string }) {
</div>
<button
onClick={() => {
const snapshot = qc.getQueryData(['documentDrafts', applicationId]);
qc.setQueryData(['documentDrafts', applicationId], (prev: any) => ({
documentDrafts: (prev?.documentDrafts ?? []).filter(
(d: any) => d.id !== draft.id,
),
}));
const snapshot = qc.getQueryData<{ documentDrafts: DocumentDraft[] }>([
'documentDrafts',
applicationId,
]);
qc.setQueryData<{ documentDrafts: DocumentDraft[] }>(
['documentDrafts', applicationId],
(prev) => ({
documentDrafts: (prev?.documentDrafts ?? []).filter((d) => d.id !== draft.id),
}),
);
showUndoToast({
message: 'Draft deleted',
onExecute: () => deleteDraft.mutate(draft.id),
Expand Down Expand Up @@ -389,10 +393,16 @@ export function DocumentsTab({ applicationId }: { applicationId: string }) {
</a>
<button
onClick={() => {
const snapshot = qc.getQueryData(['documents', applicationId]);
qc.setQueryData(['documents', applicationId], (prev: any) => ({
documents: (prev?.documents ?? []).filter((d: any) => d.id !== doc.id),
}));
const snapshot = qc.getQueryData<{ documents: Document[] }>([
'documents',
applicationId,
]);
qc.setQueryData<{ documents: Document[] }>(
['documents', applicationId],
(prev) => ({
documents: (prev?.documents ?? []).filter((d) => d.id !== doc.id),
}),
);
showUndoToast({
message: 'Document deleted',
onExecute: () => deleteDoc.mutate(doc.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,18 @@ export function InterviewsTab({
</button>
<button
onClick={() => {
const snapshot = qc.getQueryData(['interviewRounds', applicationId]);
qc.setQueryData(['interviewRounds', applicationId], (prev: any) => ({
interviewRounds: (prev?.interviewRounds ?? []).filter(
(r: any) => r.id !== round.id,
),
}));
const snapshot = qc.getQueryData<{ interviewRounds: InterviewRound[] }>([
'interviewRounds',
applicationId,
]);
qc.setQueryData<{ interviewRounds: InterviewRound[] }>(
['interviewRounds', applicationId],
(prev) => ({
interviewRounds: (prev?.interviewRounds ?? []).filter(
(r) => r.id !== round.id,
),
}),
);
showUndoToast({
message: 'Interview round deleted',
onExecute: () => deleteRound.mutate(round.id),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from '@tanstack/react-router';
import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
import { useInfiniteQuery, useQueryClient, type InfiniteData } from '@tanstack/react-query';
import { useState, useEffect, useMemo } from 'react';
import { showUndoToast } from '#/lib/undoToast';
import { ErrorState } from '#/components/ErrorState';
Expand All @@ -21,7 +21,13 @@ import {
} from 'lucide-react';
import { toast } from 'sonner';
import { Route } from '../index';
import { applicationsPageQueryOptions, APPLICATION_STATUSES, type Application } from '../index';
import {
applicationsPageQueryKey,
applicationsPageQueryOptions,
APPLICATION_STATUSES,
type Application,
type ApplicationsPageResult,
} from '../index';

function ApplicationsPage() {
const { status, starred, likelyGhosted } = Route.useSearch();
Expand Down Expand Up @@ -268,7 +274,16 @@ function ApplicationsPage() {
)}

{selectedCount > 0 && (
<BulkActionBar selectedIds={selectedIds} apps={apps} onClear={clearSelection} bulk={bulk} />
<BulkActionBar
selectedIds={selectedIds}
apps={apps}
onClear={clearSelection}
bulk={bulk}
status={status}
starred={starred}
likelyGhosted={likelyGhosted}
searchTerm={searchTerm}
/>
)}
</div>
);
Expand All @@ -279,11 +294,19 @@ function BulkActionBar({
apps,
onClear,
bulk,
status,
starred,
likelyGhosted,
searchTerm,
}: {
selectedIds: Set<string>;
apps: Application[];
onClear: () => void;
bulk: ReturnType<typeof useBulkActions>;
status: string | undefined;
starred: boolean | undefined;
likelyGhosted: boolean | undefined;
searchTerm: string;
}) {
const qc = useQueryClient();
const [tagInput, setTagInput] = useState('');
Expand All @@ -297,18 +320,22 @@ function BulkActionBar({
};

const onDelete = () => {
// Must match the exact key applicationsPageQueryOptions registers this
// query under (including the active filters) — getQueryData/setQueryData
// require an exact key match, unlike invalidateQueries' prefix matching.
const queryKey = applicationsPageQueryKey(status, starred, searchTerm, likelyGhosted);
// Snapshot all pages of the infinite query
const snapshot = qc.getQueryData(['applications', 'page']);
const snapshot = qc.getQueryData<InfiniteData<ApplicationsPageResult>>(queryKey);
// Optimistically remove selected apps from all pages
qc.setQueryData(['applications', 'page'], (prev: any) => {
qc.setQueryData<InfiniteData<ApplicationsPageResult>>(queryKey, (prev) => {
if (!prev) return prev;
return {
...prev,
pages: prev.pages.map((page: any) => ({
pages: prev.pages.map((page) => ({
...page,
applicationsPage: {
...page.applicationsPage,
items: page.applicationsPage.items.filter((a: any) => !ids.includes(a.id)),
items: page.applicationsPage.items.filter((a) => !ids.includes(a.id)),
},
})),
};
Expand All @@ -320,7 +347,7 @@ function BulkActionBar({
onClear();
},
onUndo: () => {
qc.setQueryData(['applications', 'page'], snapshot);
qc.setQueryData(queryKey, snapshot);
toast.dismiss();
},
});
Expand Down
25 changes: 17 additions & 8 deletions apps/web/src/routes/_authenticated/applications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,30 @@ export type ApplicationsPageResult = {

export { PAGE_SIZE, APPLICATION_STATUSES };

export function applicationsPageQueryKey(
status: string | undefined,
starred: boolean | undefined,
searchTerm: string,
likelyGhosted: boolean | undefined,
) {
return [
'applications',
'page',
status ?? null,
starred ?? false,
likelyGhosted ?? false,
searchTerm,
] as const;
}
Comment on lines +89 to +103

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep an absent filter distinct from false.

Lines [98-100] map undefined to false, but applicationsPageQueryOptions sends null for an absent starred filter and preserves an explicit false. It also omits an absent likelyGhosted value but sends false when supplied. These requests can therefore share one TanStack Query key while representing different filters.

apps/web/src/routes/_authenticated/applications/-components/ApplicationsPage.tsx Line [326] uses this key for optimistic updates, so the collision can display or update the wrong filtered list. Use a canonical absence value that is distinct from false, such as null, for both key segments.

Proposed fix
-    starred ?? false,
-    likelyGhosted ?? false,
+    starred ?? null,
+    likelyGhosted ?? null,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function applicationsPageQueryKey(
status: string | undefined,
starred: boolean | undefined,
searchTerm: string,
likelyGhosted: boolean | undefined,
) {
return [
'applications',
'page',
status ?? null,
starred ?? false,
likelyGhosted ?? false,
searchTerm,
] as const;
}
export function applicationsPageQueryKey(
status: string | undefined,
starred: boolean | undefined,
searchTerm: string,
likelyGhosted: boolean | undefined,
) {
return [
'applications',
'page',
status ?? null,
starred ?? null,
likelyGhosted ?? null,
searchTerm,
] as const;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/routes/_authenticated/applications/index.tsx` around lines 89 -
103, Update applicationsPageQueryKey so undefined starred and likelyGhosted
values map to null rather than false, preserving explicit false values as false.
Keep the query key aligned with applicationsPageQueryOptions to ensure absent
filters and false filters produce distinct keys, including for optimistic
updates in ApplicationsPage.


export function applicationsPageQueryOptions(
status: string | undefined,
starred: boolean | undefined,
searchTerm: string,
likelyGhosted: boolean | undefined,
) {
return infiniteQueryOptions({
queryKey: [
'applications',
'page',
status ?? null,
starred ?? false,
likelyGhosted ?? false,
searchTerm,
],
queryKey: applicationsPageQueryKey(status, starred, searchTerm, likelyGhosted),
queryFn: ({ pageParam }) =>
gqlClient.request<ApplicationsPageResult>(APPLICATIONS_PAGE_QUERY, {
status: status ?? null,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading