Skip to content

Commit b2341e7

Browse files
authored
Merge pull request #26 from Health-Informatics-UoN/update/next_version
Remove concept sorting & router refresh
2 parents bb04bff + 12cb89b commit b2341e7

7 files changed

Lines changed: 19 additions & 11 deletions

File tree

components/ConceptList.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
55
import { Button } from "@/components/ui/button";
66
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
77
import { buildSearchParams } from "@/lib/helpers";
8+
import { useEffect, useState } from "react";
89

910
export default function ConceptList({ concepts }: { concepts: Concept[] }) {
1011
const router = useRouter();
1112
const pathname = usePathname();
1213
const searchParams = useSearchParams();
13-
const selectedConcepts = searchParams.getAll("conceptId").sort();
14+
const selectedConcepts = searchParams.getAll("conceptId")
15+
const [loading, setLoading] = useState(false);
1416

1517
const onSelect = (conceptId: string) => {
18+
if (loading) return;
19+
20+
setLoading(true);
21+
1622
const current = searchParams.getAll("conceptId");
1723

1824
const nextConceptIds = current.includes(conceptId)
@@ -25,9 +31,14 @@ export default function ConceptList({ concepts }: { concepts: Concept[] }) {
2531
page: 1,
2632
});
2733

28-
router.replace(`${pathname}?${query}`, { scroll: false });
29-
router.refresh();
34+
router.replace(`${pathname}?${query}`, {
35+
scroll: false,
36+
});
37+
3038
};
39+
useEffect(() => {
40+
setLoading(false);
41+
}, [searchParams]);
3142
const clearSelection = () => {
3243
const query = buildSearchParams({
3344
conceptIds: [],
@@ -36,7 +47,6 @@ export default function ConceptList({ concepts }: { concepts: Concept[] }) {
3647
});
3748

3849
router.replace(`${pathname}?${query}`, { scroll: false });
39-
4050
};
4151

4252
return (

components/DomainSelect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export default function DomainSelect({ domain }: { domain: string }) {
2222
}
2323

2424
// Keep selected concepts
25-
const conceptIds = searchParams.getAll("conceptId").sort();
25+
const conceptIds = searchParams.getAll("conceptId")
2626
conceptIds.forEach((id) => params.append("conceptId", id));
2727

2828
// Reset page number
2929
params.set("page", "1");
3030

31-
router.replace(`${pathname}?${params.toString()}`);
31+
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
3232
}
3333
return (
3434
<Select value={domain} onValueChange={handleChange}>

components/NoteCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default function NoteCard({
6767
router.replace(`${pathname}?${query}`, {
6868
scroll: false,
6969
});
70-
router.refresh();
7170
});
7271
};
7372

components/NotesList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default async function NotesList({
3232
.map((note) => note.note_source_value?.match(/PMC(\d+)/)?.[1])
3333
.filter((id): id is string => Boolean(id)),
3434
),
35-
).sort();
35+
);
3636
if (pmcids.length === 0) return;
3737
const articles =
3838
pmcids.length > 0 ? await getMultiplePmcArticles(pmcids) : {};

components/NotesPagination.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function NotesPagination({
3030
params.set("domain", domain);
3131
}
3232
// Get conceptIds and add to URL
33-
const conceptIds = searchParams.getAll("conceptId").sort();
33+
const conceptIds = searchParams.getAll("conceptId")
3434
conceptIds.forEach((id) => params.append("conceptId", id));
3535

3636
// Add the page number

lib/helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export function buildSearchParams({
1717
// Sort and add unique conceptIds
1818
[...new Set(conceptIds)]
1919
.map(String)
20-
.sort()
2120
.forEach((id) => params.append("conceptId", id));
2221

2322
// Set page

lib/services/conceptsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export async function getNotesForConcept(
196196
const es = getElasticClient();
197197

198198
// Sort concept IDs
199-
const sortedConceptIds = [...conceptIds].sort();
199+
const sortedConceptIds = [...conceptIds]
200200
// Set pagination
201201
const size = 10;
202202

0 commit comments

Comments
 (0)