Skip to content

Commit 9244798

Browse files
authored
make tabs vertical, use a new textarea component to make it resizable, fix some lint warnings (#373)
1 parent 59625f3 commit 9244798

File tree

1 file changed

+70
-14
lines changed

1 file changed

+70
-14
lines changed

apps/roam/src/components/settings/NodeConfig.tsx

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import BlocksPanel from "roamjs-components/components/ConfigPanels/BlocksPanel";
66
import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel";
77
import { getSubTree } from "roamjs-components/util";
88
import Description from "roamjs-components/components/Description";
9-
import { Label, Tabs, Tab, TabId, InputGroup } from "@blueprintjs/core";
9+
import {
10+
Label,
11+
Tabs,
12+
Tab,
13+
TabId,
14+
InputGroup,
15+
TextArea,
16+
} from "@blueprintjs/core";
1017
import DiscourseNodeSpecification from "./DiscourseNodeSpecification";
1118
import DiscourseNodeAttributes from "./DiscourseNodeAttributes";
1219
import DiscourseNodeCanvasSettings from "./DiscourseNodeCanvasSettings";
@@ -50,7 +57,40 @@ const ValidatedInputPanel = ({
5057
</div>
5158
);
5259

53-
const useDebouncedRoamUpdater = (
60+
const ValidatedTextareaPanel = ({
61+
label,
62+
description,
63+
value,
64+
onChange,
65+
onBlur,
66+
placeholder,
67+
}: {
68+
label: string;
69+
description: string;
70+
value: string;
71+
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
72+
onBlur: () => void;
73+
placeholder?: string;
74+
}) => (
75+
<div className="flex flex-col">
76+
<Label>
77+
{label}
78+
<Description description={description} />
79+
<TextArea
80+
value={value}
81+
onChange={onChange}
82+
onBlur={onBlur}
83+
placeholder={placeholder}
84+
className="w-full"
85+
style={{ minHeight: 80, resize: "vertical" }}
86+
/>
87+
</Label>
88+
</div>
89+
);
90+
91+
const useDebouncedRoamUpdater = <
92+
T extends HTMLInputElement | HTMLTextAreaElement,
93+
>(
5494
uid: string,
5595
initialValue: string,
5696
isValid: boolean,
@@ -71,10 +111,10 @@ const useDebouncedRoamUpdater = (
71111
const existingBlock = getBasicTreeByParentUid(uid)[0];
72112
if (existingBlock) {
73113
if (existingBlock.text !== text) {
74-
updateBlock({ uid: existingBlock.uid, text });
114+
void updateBlock({ uid: existingBlock.uid, text });
75115
}
76116
} else if (text) {
77-
createBlock({ parentUid: uid, node: { text } });
117+
void createBlock({ parentUid: uid, node: { text } });
78118
}
79119
},
80120
timeout ? 500 : 0,
@@ -84,7 +124,7 @@ const useDebouncedRoamUpdater = (
84124
);
85125

86126
const handleChange = useCallback(
87-
(e: React.ChangeEvent<HTMLInputElement>) => {
127+
(e: React.ChangeEvent<T>) => {
88128
const newValue = e.target.value;
89129
setValue(newValue);
90130
saveToRoam(newValue, true);
@@ -135,12 +175,29 @@ const NodeConfig = ({
135175
value: tagValue,
136176
handleChange: handleTagChange,
137177
handleBlur: handleTagBlurFromHook,
138-
} = useDebouncedRoamUpdater(tagUid, node.tag || "", isConfigurationValid);
178+
} = useDebouncedRoamUpdater<HTMLInputElement>(
179+
tagUid,
180+
node.tag || "",
181+
isConfigurationValid,
182+
);
139183
const {
140184
value: formatValue,
141185
handleChange: handleFormatChange,
142186
handleBlur: handleFormatBlurFromHook,
143-
} = useDebouncedRoamUpdater(formatUid, node.format, isConfigurationValid);
187+
} = useDebouncedRoamUpdater<HTMLInputElement>(
188+
formatUid,
189+
node.format,
190+
isConfigurationValid,
191+
);
192+
const {
193+
value: descriptionValue,
194+
handleChange: handleDescriptionChange,
195+
handleBlur: handleDescriptionBlur,
196+
} = useDebouncedRoamUpdater<HTMLTextAreaElement>(
197+
descriptionUid,
198+
node.description || "",
199+
true,
200+
);
144201

145202
const getCleanTagText = (tag: string): string => {
146203
return tag.replace(/^#+/, "").trim().toUpperCase();
@@ -205,14 +262,13 @@ const NodeConfig = ({
205262
id="general"
206263
title="General"
207264
panel={
208-
<div className="flex flex-row gap-4 p-1">
209-
<TextPanel
210-
title="Description"
265+
<div className="flex flex-col gap-4 p-1">
266+
<ValidatedTextareaPanel
267+
label="Description"
211268
description={`Describing what the ${node.text} node represents in your graph.`}
212-
order={0}
213-
parentUid={node.type}
214-
uid={descriptionUid}
215-
defaultValue={node.description}
269+
value={descriptionValue}
270+
onChange={handleDescriptionChange}
271+
onBlur={handleDescriptionBlur}
216272
/>
217273
<TextPanel
218274
title="Shortcut"

0 commit comments

Comments
 (0)