Skip to content

Commit

Permalink
feat: separate project link dialog to AppProjectLinkDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ascpixi committed Dec 28, 2024
1 parent 254279e commit cd47a7d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 43 deletions.
56 changes: 13 additions & 43 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { AddNodeMenu } from "./components/app/AddNodeMenu";
import { AppRenderDialog } from "./components/app/AppRenderDialog";
import { AppAboutDialog } from "./components/app/AppAboutDialog";
import { ConfirmationDialog } from "./components/app/ConfirmationDialog";
import { AppProjectLinkDialog } from "./components/app/AppProjectLinkDialog";

const shouldShowTour = !getPersistentData().tourComplete;
const shouldLoadExisting = location.hash.startsWith("#p:");
Expand Down Expand Up @@ -48,12 +49,9 @@ export default function App() {

const aboutDialogRef = useRef<HTMLDialogElement>(null);
const resetDialogRef = useRef<HTMLDialogElement>(null);
const renderDialogRef = useRef<HTMLDialogElement>(null);

const [projLink, setProjLink] = useState<string>("");
const projLinkDialogRef = useRef<HTMLDialogElement>(null);
const projLinkTextRef = useRef<HTMLTextAreaElement>(null);

const renderDialogRef = useRef<HTMLDialogElement>(null);

const [realtimeCtx] = useState(tone.getContext());

Expand Down Expand Up @@ -141,12 +139,6 @@ export default function App() {
: location.origin + location.pathname;

setProjLink(root + "#p:" + data);
projLinkDialogRef.current!.showModal();

setTimeout(() => {
projLinkTextRef.current!.focus();
projLinkTextRef.current!.select();
}, 50);
}

async function saveAsFile() {
Expand Down Expand Up @@ -310,39 +302,6 @@ export default function App() {
</div>
}

<dialog ref={projLinkDialogRef} className="modal">
<div className="modal-box max-w-none w-1/2">
<h3 className="font-bold text-lg">Project link</h3>
<p className="py-4">
This is a link to your project - whenever you'll open it, this
version of the project will be restored.
</p>

<textarea ref={projLinkTextRef}
className="textarea textarea-bordered w-full h-full min-h-[200px]"
aria-label="Project link"
value={projLink}
readOnly
/>

<div className="modal-action">
<form method="dialog">
<button className="btn">Close</button>
</form>
</div>
</div>
</dialog>

<ConfirmationDialog
ref={resetDialogRef}
content={<>
Are you sure you want to create a new project? If you did not save
this one before, it will be lost forever!
</>}
confirm="Yes, create a new one"
onConfirm={reset}
/>

<dialog ref={tourDialogRef} className="modal">
<div className="modal-box">
<h3 className="font-bold text-lg">Interactive tour (tutorial)</h3>
Expand All @@ -362,8 +321,19 @@ export default function App() {
</dialog>

<AppAboutDialog ref={aboutDialogRef} />
<AppProjectLinkDialog link={projLink}/>
<AppRenderDialog ref={renderDialogRef} graph={graph} />

<ConfirmationDialog
ref={resetDialogRef}
content={<>
Are you sure you want to create a new project? If you did not save
this one before, it will be lost forever!
</>}
confirm="Yes, create a new one"
onConfirm={reset}
/>

<flow.ReactFlow
onMouseDownCapture={() => setShowCtxMenu(false)}
nodes={graph.nodes}
Expand Down
45 changes: 45 additions & 0 deletions src/components/app/AppProjectLinkDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect, useRef } from "react"

export function AppProjectLinkDialog({ link }: {
link: string
}) {
const dialogRef = useRef<HTMLDialogElement>(null);
const textAreaRef = useRef<HTMLTextAreaElement>(null);

useEffect(() => {
if (link.trim() == "")
return;

dialogRef.current!.showModal();

setTimeout(() => {
textAreaRef.current!.focus();
textAreaRef.current!.select();
}, 50);
}, [link]);

return (
<dialog ref={dialogRef} className="modal">
<div className="modal-box max-w-none w-1/2">
<h3 className="font-bold text-lg">Project link</h3>
<p className="py-4">
This is a link to your project - whenever you'll open it, this
version of the project will be restored.
</p>

<textarea ref={textAreaRef}
className="textarea textarea-bordered w-full h-full min-h-[200px]"
aria-label="Project link"
value={link}
readOnly
/>

<div className="modal-action">
<form method="dialog">
<button className="btn">Close</button>
</form>
</div>
</div>
</dialog>
);
};

0 comments on commit cd47a7d

Please sign in to comment.