Skip to content

Commit 56ec7bc

Browse files
committed
prettier, port alias textpanel to presonaltextpanel
1 parent a3a687d commit 56ec7bc

File tree

3 files changed

+45
-52
lines changed

3 files changed

+45
-52
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import posthog from "posthog-js";
2222

2323
const pagesToUids = (pages: RoamBasicNode[]) => pages.map((p) => p.text);
2424

25-
2625
const PageItem = memo(
2726
({
2827
page,
@@ -164,11 +163,7 @@ const LeftSidebarGlobalSectionsContent = ({
164163
newPages.splice(newIndex, 0, removed);
165164

166165
setPages(newPages);
167-
setGlobalSetting(
168-
["Left sidebar", "Children"],
169-
pagesToUids(newPages),
170-
);
171-
166+
setGlobalSetting(["Left sidebar", "Children"], pagesToUids(newPages));
172167

173168
if (childrenUid) {
174169
const order = direction === "down" ? newIndex + 1 : newIndex;
@@ -216,7 +211,7 @@ const LeftSidebarGlobalSectionsContent = ({
216211
["Left sidebar", "Children"],
217212
pagesToUids(updatedPages),
218213
);
219-
214+
220215
setNewPageInput("");
221216
setAutocompleteKey((prev) => prev + 1);
222217
posthog.capture("Left Sidebar Global Settings: Page Added", {
@@ -244,7 +239,7 @@ const LeftSidebarGlobalSectionsContent = ({
244239
["Left sidebar", "Children"],
245240
pagesToUids(updatedPages),
246241
);
247-
242+
248243
refreshAndNotify();
249244
} catch (error) {
250245
renderToast({
@@ -296,7 +291,6 @@ const LeftSidebarGlobalSectionsContent = ({
296291
uid={globalSection.settings?.folded?.uid || ""}
297292
parentUid={globalSection.settings?.uid || ""}
298293
disabled={!globalSection.children?.length}
299-
300294
/>
301295
<GlobalFlagPanel
302296
title="Collapsable"
@@ -306,7 +300,6 @@ const LeftSidebarGlobalSectionsContent = ({
306300
order={1}
307301
uid={globalSection.settings?.collapsable?.uid || ""}
308302
parentUid={globalSection.settings?.uid || ""}
309-
310303
/>
311304
</div>
312305

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

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import deleteBlock from "roamjs-components/writes/deleteBlock";
2020
import updateBlock from "roamjs-components/writes/updateBlock";
2121
import type { RoamBasicNode } from "roamjs-components/types";
2222
import { setPersonalSetting } from "~/components/settings/utils/accessors";
23-
import { PersonalNumberPanel } from "~/components/settings/components/BlockPropSettingPanels";
24-
import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel";
23+
import {
24+
PersonalNumberPanel,
25+
PersonalTextPanel,
26+
} from "~/components/settings/components/BlockPropSettingPanels";
2527
import {
2628
LeftSidebarPersonalSectionConfig,
2729
getLeftSidebarPersonalSectionConfig,
@@ -86,7 +88,6 @@ const SectionItem = memo(
8688
const originalName = blockText || section.text;
8789
const [childInput, setChildInput] = useState("");
8890
const [childInputKey, setChildInputKey] = useState(0);
89-
const aliasDebounceRef = useRef<ReturnType<typeof setTimeout>>();
9091

9192
const [expandedChildLists, setExpandedChildLists] = useState<Set<string>>(
9293
new Set(),
@@ -503,45 +504,36 @@ const SectionItem = memo(
503504
style={{ width: "400px" }}
504505
>
505506
<div className="p-4">
506-
<TextPanel
507+
<PersonalTextPanel
507508
title="Alias"
508509
description="Display name for this item"
510+
settingKeys={["Left sidebar"]}
511+
initialValue={child.alias?.value ?? ""}
509512
order={0}
510513
uid={child.alias?.uid}
511514
parentUid={child.uid}
512-
defaultValue=""
513-
options={{
514-
onChange: (
515-
event: React.ChangeEvent<HTMLInputElement>,
516-
) => {
517-
const nextValue = event.target.value;
518-
setSections((prev) =>
519-
prev.map((s) =>
520-
s.uid === section.uid
521-
? {
522-
...s,
523-
children: s.children?.map((c) =>
524-
c.uid === child.uid
525-
? {
526-
...c,
527-
alias: {
528-
...c.alias,
529-
value: nextValue,
530-
},
531-
}
532-
: c,
533-
),
534-
}
535-
: s,
536-
),
537-
);
538-
clearTimeout(aliasDebounceRef.current);
539-
aliasDebounceRef.current = setTimeout(() => {
540-
syncAllSectionsToBlockProps(
541-
sectionsRef.current,
542-
);
543-
}, 250);
544-
},
515+
setter={(_keys, value) => {
516+
const updatedSections = sectionsRef.current.map(
517+
(s) =>
518+
s.uid === section.uid
519+
? {
520+
...s,
521+
children: s.children?.map((c) =>
522+
c.uid === child.uid
523+
? {
524+
...c,
525+
alias: {
526+
...c.alias,
527+
value,
528+
},
529+
}
530+
: c,
531+
),
532+
}
533+
: s,
534+
);
535+
setSections(updatedSections);
536+
syncAllSectionsToBlockProps(updatedSections);
545537
}}
546538
/>
547539
</div>

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ const BaseMultiTextPanel = ({
457457
);
458458
};
459459

460-
type TextWrapperProps = Omit<BaseTextPanelProps, "setter">;
460+
type TextWrapperProps = Omit<BaseTextPanelProps, "setter"> & {
461+
setter?: TextSetter;
462+
};
461463
type FlagWrapperProps = Omit<BaseFlagPanelProps, "setter">;
462464
type NumberWrapperProps = Omit<BaseNumberPanelProps, "setter"> & {
463465
setter?: NumberSetter;
@@ -559,16 +561,22 @@ export const GlobalMultiTextPanel = (props: MultiTextWrapperProps) => (
559561
<BaseMultiTextPanel {...props} {...globalAccessors.multiText} />
560562
);
561563

562-
export const PersonalTextPanel = (props: TextWrapperProps) => (
563-
<BaseTextPanel {...props} {...personalAccessors.text} />
564+
export const PersonalTextPanel = ({ setter, ...props }: TextWrapperProps) => (
565+
<BaseTextPanel {...props} setter={setter ?? personalAccessors.text.setter} />
564566
);
565567

566568
export const PersonalFlagPanel = (props: FlagWrapperProps) => (
567569
<BaseFlagPanel {...props} {...personalAccessors.flag} />
568570
);
569571

570-
export const PersonalNumberPanel = ({ setter, ...props }: NumberWrapperProps) => (
571-
<BaseNumberPanel {...props} setter={setter ?? personalAccessors.number.setter} />
572+
export const PersonalNumberPanel = ({
573+
setter,
574+
...props
575+
}: NumberWrapperProps) => (
576+
<BaseNumberPanel
577+
{...props}
578+
setter={setter ?? personalAccessors.number.setter}
579+
/>
572580
);
573581

574582
export const PersonalSelectPanel = (props: SelectWrapperProps) => (

0 commit comments

Comments
 (0)