Skip to content

Commit 615e5bf

Browse files
committed
course whitelist toggle
1 parent f4304f4 commit 615e5bf

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

app/courses/[courseId]/media/[mediaId]/SimilarSegments.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { SimilarSegmentsQuery } from "@/__generated__/SimilarSegmentsQuery.graphql";
22
import SearchResultsBox from "@/components/search/SearchResultsBox";
3-
import { CircularProgress, Drawer } from "@mui/material";
3+
import {
4+
CircularProgress,
5+
Drawer,
6+
FormControlLabel,
7+
Switch,
8+
} from "@mui/material";
9+
import { useParams } from "next/navigation";
410
import { useState, useTransition } from "react";
511
import { graphql, useLazyLoadQuery } from "react-relay";
612
import useBus from "use-bus";
@@ -15,16 +21,30 @@ export function SimilarSegments() {
1521
}
1622
});
1723

24+
const params = useParams();
25+
const [onlySameCourse, setOnlySameCourse] = useState(true);
26+
1827
const segments = useLazyLoadQuery<SimilarSegmentsQuery>(
1928
graphql`
20-
query SimilarSegmentsQuery($segmentId: UUID!, $skip: Boolean!) {
21-
getSemanticallySimilarEntities(segmentId: $segmentId, count: 10)
22-
@skip(if: $skip) {
29+
query SimilarSegmentsQuery(
30+
$segmentId: UUID!
31+
$skip: Boolean!
32+
$whitelist: [UUID!]
33+
) {
34+
getSemanticallySimilarEntities(
35+
segmentId: $segmentId
36+
count: 10
37+
courseWhitelist: $whitelist
38+
) @skip(if: $skip) {
2339
...SearchResultsBox
2440
}
2541
}
2642
`,
27-
{ segmentId: segmentId!, skip: !segmentId }
43+
{
44+
segmentId: segmentId!,
45+
skip: !segmentId,
46+
whitelist: onlySameCourse ? [params.courseId] : undefined,
47+
}
2848
);
2949

3050
return (
@@ -33,7 +53,20 @@ export function SimilarSegments() {
3353
onClose={() => setSegmentId(null)}
3454
anchor="right"
3555
>
36-
<div className="w-[66vw] h-screen flex">
56+
<div className="w-[66vw] h-screen flex flex-col">
57+
{params.courseId && (
58+
<FormControlLabel
59+
className="px-4 pt-4"
60+
control={
61+
<Switch
62+
checked={onlySameCourse}
63+
onChange={(e) => setOnlySameCourse(e.target.checked)}
64+
/>
65+
}
66+
label="Only search the current course"
67+
/>
68+
)}
69+
3770
{isLoading && (
3871
<div className="flex items-center justify-center w-full h-full">
3972
<CircularProgress className="place-self-center justify-self-center" />

0 commit comments

Comments
 (0)