Skip to content

Commit d38e117

Browse files
committed
REFACTOR: Move theory select dialog to same module as widget.
1 parent 22eb64b commit d38e117

File tree

3 files changed

+74
-48
lines changed

3 files changed

+74
-48
lines changed

packages/frontend/src/document/model_document_editor.tsx

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import type { ChangeFn, DocHandle } from "@automerge/automerge-repo";
2-
import Dialog from "@corvu/dialog";
32
import { MultiProvider } from "@solid-primitives/context";
43
import { useNavigate, useParams } from "@solidjs/router";
5-
import {
6-
type Accessor,
7-
Match,
8-
Switch,
9-
createMemo,
10-
createResource,
11-
createSignal,
12-
useContext,
13-
} from "solid-js";
4+
import { type Accessor, Match, Switch, createMemo, createResource, useContext } from "solid-js";
145
import invariant from "tiny-invariant";
156

167
import type { JsonValue, Permissions } from "catcolab-api";
@@ -44,7 +35,7 @@ import { type TheoryLibrary, TheoryLibraryContext } from "../stdlib";
4435
import type { Theory } from "../theory";
4536
import { PermissionsButton } from "../user";
4637
import { type IndexedMap, indexMap } from "../util/indexing";
47-
import { TheorySelector } from "./theory_selector";
38+
import { TheorySelectorDialog } from "./theory_selector";
4839
import { type ModelDocument, newAnalysisDocument } from "./types";
4940

5041
import "./model_document_editor.css";
@@ -223,7 +214,6 @@ export function ModelPane(props: {
223214
}) {
224215
const theories = useContext(TheoryLibraryContext);
225216
invariant(theories, "Library of theories should be provided as context");
226-
const [theorySelectorOpen, setTheorySelectorOpen] = createSignal(false);
227217

228218
const liveDoc = () => props.liveDoc;
229219
const doc = () => props.liveDoc.doc;
@@ -242,26 +232,16 @@ export function ModelPane(props: {
242232
placeholder="Untitled"
243233
/>
244234
</div>
245-
<Dialog open={theorySelectorOpen()} onOpenChange={setTheorySelectorOpen}>
246-
<Dialog.Trigger class="theory-selector-button">
247-
{liveDoc().theory()?.name || "Theory"}
248-
</Dialog.Trigger>
249-
<Dialog.Portal>
250-
<Dialog.Overlay class="overlay" />
251-
<Dialog.Content class="popup">
252-
<TheorySelector
253-
theory={props.liveDoc.theory()?.id}
254-
setTheory={(id) => {
255-
changeDoc((model) => {
256-
model.theory = id;
257-
});
258-
setTheorySelectorOpen(false);
259-
}}
260-
theories={theories}
261-
/>
262-
</Dialog.Content>
263-
</Dialog.Portal>
264-
</Dialog>
235+
<TheorySelectorDialog
236+
theory={props.liveDoc.theory()}
237+
setTheory={(id) => {
238+
changeDoc((model) => {
239+
model.theory = id;
240+
});
241+
}}
242+
theories={theories}
243+
disabled={doc().notebook.cells.some((cell) => cell.tag === "formal")}
244+
/>
265245
</div>
266246
<MultiProvider
267247
values={[

packages/frontend/src/document/theory_selector.css

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
cursor: pointer;
88
font-weight: 500;
99

10-
&:hover {
10+
& .placeholder {
11+
color: darkgray;
12+
}
13+
14+
&:hover,
15+
& .placeholder:hover {
1116
color: var(--topos-color);
1217
}
1318
}
1419

1520
.theory-selector {
1621
display: flex;
1722
flex-direction: column;
18-
margin: 5px;
23+
gap: 10px;
24+
1925
background-color: transparent;
2026
text-align: left;
2127
border-top: transparent;
@@ -27,20 +33,25 @@
2733
opacity: 0;
2834
}
2935

36+
& label:hover {
37+
color: var(--topos-color);
38+
cursor: pointer;
39+
}
40+
3041
& .division {
42+
display: flex;
43+
flex-direction: column;
44+
gap: 5px;
45+
}
46+
47+
& .division-name {
3148
font-weight: 600;
3249
padding-bottom: 1px;
3350
opacity: 35%;
3451
}
3552

3653
& .theory {
37-
margin: 5px;
38-
padding: 5px;
39-
}
40-
41-
& .theory:hover {
42-
color: var(--topos-color);
43-
cursor: pointer;
54+
margin-left: 2ex;
4455
}
4556

4657
& .description {

packages/frontend/src/document/theory_selector.tsx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,52 @@
1-
import { For, createMemo } from "solid-js";
1+
import Dialog from "@corvu/dialog";
2+
import { For, Show, createMemo, createSignal } from "solid-js";
23

34
import type { TheoryLibrary, TheoryMeta } from "../stdlib";
45
import type { TheoryId } from "../theory";
56

67
import "./theory_selector.css";
78

89
type TheorySelectorProps = {
9-
theory: TheoryId | undefined;
10+
theory: TheoryMeta | undefined;
1011
setTheory: (theory: TheoryId | undefined) => void;
1112
theories: TheoryLibrary;
1213
};
1314

14-
export const TheorySelector = (props: TheorySelectorProps) => {
15+
export function TheorySelectorDialog(
16+
props: {
17+
disabled?: boolean;
18+
} & TheorySelectorProps,
19+
) {
20+
const [theorySelectorOpen, setTheorySelectorOpen] = createSignal(false);
21+
22+
return (
23+
<Dialog open={theorySelectorOpen()} onOpenChange={setTheorySelectorOpen}>
24+
<Dialog.Trigger class="theory-selector-button" disabled={props.disabled}>
25+
<Show
26+
when={props.theory}
27+
fallback={<span class="placeholder">Choose a logic</span>}
28+
>
29+
{props.theory?.name}
30+
</Show>
31+
</Dialog.Trigger>
32+
<Dialog.Portal>
33+
<Dialog.Overlay class="overlay" />
34+
<Dialog.Content class="popup">
35+
<TheorySelector
36+
theory={props.theory}
37+
setTheory={(id) => {
38+
props.setTheory(id);
39+
setTheorySelectorOpen(false);
40+
}}
41+
theories={props.theories}
42+
/>
43+
</Dialog.Content>
44+
</Dialog.Portal>
45+
</Dialog>
46+
);
47+
}
48+
49+
export function TheorySelector(props: TheorySelectorProps) {
1550
const groupedTheories = createMemo(() => {
1651
const grouped = new Map<string, TheoryMeta[]>();
1752

@@ -29,8 +64,8 @@ export const TheorySelector = (props: TheorySelectorProps) => {
2964
<div class="theory-selector">
3065
<For each={groupedTheories()}>
3166
{([category, theories]) => (
32-
<>
33-
<h4 class="division">{category}</h4>
67+
<div class="division">
68+
<h4 class="division-name">{category}</h4>
3469
<For each={theories}>
3570
{(meta) => (
3671
<div class="theory">
@@ -51,9 +86,9 @@ export const TheorySelector = (props: TheorySelectorProps) => {
5186
</div>
5287
)}
5388
</For>
54-
</>
89+
</div>
5590
)}
5691
</For>
5792
</div>
5893
);
59-
};
94+
}

0 commit comments

Comments
 (0)