Skip to content

Commit 373c15f

Browse files
authored
ENG-1256: Allow editing of left sidebar section names (#677)
* edit section names * debounce
1 parent 1be01db commit 373c15f

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import discourseConfigRef from "~/utils/discourseConfigRef";
2-
import React, { useCallback, useEffect, useMemo, useState } from "react";
2+
import React, {
3+
useCallback,
4+
useEffect,
5+
useMemo,
6+
useRef,
7+
useState,
8+
} from "react";
39
import AutocompleteInput from "roamjs-components/components/AutocompleteInput";
410
import getAllPageNames from "roamjs-components/queries/getAllPageNames";
511
import {
@@ -11,6 +17,7 @@ import {
1117
} from "@blueprintjs/core";
1218
import createBlock from "roamjs-components/writes/createBlock";
1319
import deleteBlock from "roamjs-components/writes/deleteBlock";
20+
import updateBlock from "roamjs-components/writes/updateBlock";
1421
import type { RoamBasicNode } from "roamjs-components/types";
1522
import NumberPanel from "roamjs-components/components/ConfigPanels/NumberPanel";
1623
import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel";
@@ -523,6 +530,7 @@ const LeftSidebarPersonalSectionsContent = ({
523530
const [settingsDialogSectionUid, setSettingsDialogSectionUid] = useState<
524531
string | null
525532
>(null);
533+
const sectionTitleUpdateTimeoutRef = useRef<ReturnType<typeof setTimeout>>();
526534

527535
useEffect(() => {
528536
const initialize = async () => {
@@ -633,7 +641,6 @@ const LeftSidebarPersonalSectionsContent = ({
633641
if (!personalSectionUid) {
634642
return null;
635643
}
636-
637644
return (
638645
<div className="flex flex-col gap-4 p-1">
639646
<div className="mb-2">
@@ -692,6 +699,36 @@ const LeftSidebarPersonalSectionsContent = ({
692699
>
693700
<div className="space-y-4 p-4">
694701
<div className="space-y-3">
702+
<div>
703+
<label className="mb-1 flex items-center text-sm font-medium">
704+
Section Title
705+
<span
706+
className="bp3-icon bp3-icon-info-sign ml-1"
707+
title="Display name for this section"
708+
/>
709+
</label>
710+
<InputGroup
711+
value={activeDialogSection.text}
712+
onChange={(e) => {
713+
const nextValue = e.target.value;
714+
const sectionUid = activeDialogSection.uid;
715+
setSections((prev) =>
716+
prev.map((s) =>
717+
s.uid === sectionUid ? { ...s, text: nextValue } : s,
718+
),
719+
);
720+
clearTimeout(sectionTitleUpdateTimeoutRef.current);
721+
sectionTitleUpdateTimeoutRef.current = setTimeout(() => {
722+
void updateBlock({
723+
uid: sectionUid,
724+
text: nextValue,
725+
}).then(() => {
726+
refreshAndNotify();
727+
});
728+
}, 300);
729+
}}
730+
/>
731+
</div>
695732
<NumberPanel
696733
title="Truncate-result?"
697734
description="Maximum characters to display"

0 commit comments

Comments
 (0)