Skip to content

Commit 9568435

Browse files
authored
Merge pull request #208 from MKuranowski/default-to-custom-questions
"Default to custom questions" mode
2 parents 682fc37 + eca2de1 commit 9568435

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/components/AddQuestionDialog.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
DialogTrigger,
1212
} from "@/components/ui/dialog";
1313
import { SidebarMenuButton } from "@/components/ui/sidebar-l";
14-
import { addQuestion, isLoading, leafletMapContext } from "@/lib/context";
14+
import {
15+
addQuestion,
16+
defaultCustomQuestions,
17+
isLoading,
18+
leafletMapContext,
19+
} from "@/lib/context";
1520

1621
export const AddQuestionDialog = ({
1722
children,
@@ -59,7 +64,14 @@ export const AddQuestionDialog = ({
5964
const center = map.getCenter();
6065
addQuestion({
6166
id: "tentacles",
62-
data: { lat: center.lat, lng: center.lng },
67+
data: defaultCustomQuestions.get()
68+
? {
69+
lat: center.lat,
70+
lng: center.lng,
71+
locationType: "custom",
72+
places: [],
73+
}
74+
: { lat: center.lat, lng: center.lng },
6375
});
6476
return true;
6577
};
@@ -70,7 +82,9 @@ export const AddQuestionDialog = ({
7082
const center = map.getCenter();
7183
addQuestion({
7284
id: "matching",
73-
data: { lat: center.lat, lng: center.lng },
85+
data: defaultCustomQuestions.get()
86+
? { lat: center.lat, lng: center.lng, type: "custom-points" }
87+
: { lat: center.lat, lng: center.lng },
7488
});
7589
return true;
7690
};
@@ -81,7 +95,9 @@ export const AddQuestionDialog = ({
8195
const center = map.getCenter();
8296
addQuestion({
8397
id: "measuring",
84-
data: { lat: center.lat, lng: center.lng },
98+
data: defaultCustomQuestions.get()
99+
? { lat: center.lat, lng: center.lng, type: "custom-measure" }
100+
: { lat: center.lat, lng: center.lng },
85101
});
86102
return true;
87103
};

src/components/OptionDrawers.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
customInitPreference,
2020
customPresets,
2121
customStations,
22+
defaultCustomQuestions,
2223
defaultUnit,
2324
disabledStations,
2425
displayHidingZonesOptions,
@@ -72,6 +73,7 @@ const PASTEBIN_URL_PARAM = "pb";
7273

7374
export const OptionDrawers = ({ className }: { className?: string }) => {
7475
useStore(triggerLocalRefresh);
76+
const $defaultCustomQuestions = useStore(defaultCustomQuestions);
7577
const $defaultUnit = useStore(defaultUnit);
7678
const $animateMapMovements = useStore(animateMapMovements);
7779
const $autoZoom = useStore(autoZoom);
@@ -615,6 +617,19 @@ export const OptionDrawers = ({ className }: { className?: string }) => {
615617
}
616618
/>
617619
</div>
620+
<div className="flex flex-row items-center gap-2">
621+
<label className="text-2xl font-semibold font-poppins">
622+
Default to custom questions?
623+
</label>
624+
<Checkbox
625+
checked={$defaultCustomQuestions}
626+
onCheckedChange={() =>
627+
defaultCustomQuestions.set(
628+
!$defaultCustomQuestions,
629+
)
630+
}
631+
/>
632+
</div>
618633
<div className="flex flex-row items-center gap-2">
619634
<label className="text-2xl font-semibold font-poppins">
620635
Hider mode?

src/lib/context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ export const followMe = persistentAtom<boolean>("followMe", false, {
348348
encode: JSON.stringify,
349349
decode: JSON.parse,
350350
});
351+
export const defaultCustomQuestions = persistentAtom<boolean>(
352+
"defaultCustomQuestions",
353+
false,
354+
{
355+
encode: JSON.stringify,
356+
decode: JSON.parse,
357+
},
358+
);
351359

352360
export const pastebinApiKey = persistentAtom<string>("pastebinApiKey", "");
353361
export const alwaysUsePastebin = persistentAtom<boolean>(

0 commit comments

Comments
 (0)