Skip to content

Commit

Permalink
fix: update title on mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
huyjs9 committed Jul 21, 2024
1 parent 9393f5c commit 1bff574
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default function ControlPanel({
}) {
const [modal, setModal] = useState(MODAL.NONE);
const [sidesheet, setSidesheet] = useState(SIDESHEET.NONE);
const [prevTitle, setPrevTitle] = useState(title);
const [showEditName, setShowEditName] = useState(false);
const [importDb, setImportDb] = useState("");
const [exportData, setExportData] = useState({
Expand Down Expand Up @@ -728,7 +727,6 @@ export default function ControlPanel({
rename: {
function: () => {
setModal(MODAL.RENAME);
setPrevTitle(title);
},
},
delete_diagram: {
Expand Down Expand Up @@ -1309,10 +1307,8 @@ export default function ControlPanel({
setExportData={setExportData}
title={title}
setTitle={setTitle}
setPrevTitle={setPrevTitle}
setDiagramId={setDiagramId}
setModal={setModal}
prevTitle={prevTitle}
importDb={importDb}
/>
<Sidesheet
Expand Down
19 changes: 13 additions & 6 deletions src/components/EditorHeader/Modal/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Modal as SemiUIModal,
} from "@douyinfe/semi-ui";
import { DB, MODAL, STATUS } from "../../../data/constants";
import { useState } from "react";
import { useEffect, useState } from "react";
import { db } from "../../../data/db";
import {
useAreas,
Expand Down Expand Up @@ -48,8 +48,6 @@ export default function Modal({
setModal,
title,
setTitle,
prevTitle,
setPrevTitle,
setDiagramId,
exportData,
setExportData,
Expand All @@ -65,6 +63,7 @@ export default function Modal({
const { setTasks } = useTasks();
const { setTransform } = useTransform();
const { setUndoStack, setRedoStack } = useUndoRedo();
const [uncontrolledTitle, setUncontrolledTitle] = useState(title);
const [importSource, setImportSource] = useState({
src: "",
overwrite: true,
Expand All @@ -78,6 +77,12 @@ export default function Modal({
const [selectedDiagramId, setSelectedDiagramId] = useState(0);
const [saveAsTitle, setSaveAsTitle] = useState(title);

useEffect(() => {
if (title !== uncontrolledTitle) {
setUncontrolledTitle(title);
}
}, [title]);

Check warning on line 84 in src/components/EditorHeader/Modal/Modal.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useEffect has a missing dependency: 'uncontrolledTitle'. Either include it or remove the dependency array

Check warning on line 84 in src/components/EditorHeader/Modal/Modal.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook useEffect has a missing dependency: 'uncontrolledTitle'. Either include it or remove the dependency array

const overwriteDiagram = () => {
setTables(importData.tables);
setRelationships(importData.relationships);
Expand Down Expand Up @@ -212,7 +217,7 @@ export default function Modal({
setModal(MODAL.NONE);
return;
case MODAL.RENAME:
setPrevTitle(title);
setTitle(uncontrolledTitle);
setModal(MODAL.NONE);
return;
case MODAL.SAVEAS:
Expand Down Expand Up @@ -256,7 +261,9 @@ export default function Modal({
/>
);
case MODAL.RENAME:
return <Rename title={title} setTitle={setTitle} />;
return (
<Rename title={uncontrolledTitle} setTitle={setUncontrolledTitle} />
);
case MODAL.OPEN:
return (
<Open
Expand Down Expand Up @@ -339,7 +346,7 @@ export default function Modal({
});
}}
onCancel={() => {
if (modal === MODAL.RENAME) setTitle(prevTitle);
if (modal === MODAL.RENAME) setUncontrolledTitle(title);
setModal(MODAL.NONE);
}}
centered
Expand Down

0 comments on commit 1bff574

Please sign in to comment.