Skip to content

Commit

Permalink
Merge pull request #620 from ollixx/ollixx/issue239
Browse files Browse the repository at this point in the history
Ollixx/issue239
  • Loading branch information
alexanderson1993 authored May 3, 2024
2 parents 88c3e46 + 5351343 commit 0f723db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
8 changes: 6 additions & 2 deletions client/app/data/plugins/deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const deck = t.router({
deckId: z.string(),
}),
z.union([
z.object({ generateName: z.string() }),
z.object({ newName: z.string() }),
z.object({ newIndex: z.number() }),
z.object({
Expand All @@ -110,12 +111,15 @@ export const deck = t.router({
const deckIndex = ship.decks.findIndex(
(deck) => deck.name === input.deckId,
);
if ("newName" in input) {
if ("generateName" in input) {
deck.name = generateIncrementedName(
input.newName,
input.generateName,
ship.decks.map((deck) => deck.name),
);
}
if ("newName" in input) {
deck.name = input.newName;
}
if ("newIndex" in input && typeof input.newIndex === "number") {
moveArrayItem(ship.decks, deckIndex, input.newIndex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SVGImageLoader } from "@thorium/ui/SVGImageLoader";
import { useParams } from "@remix-run/react";
import { useParams, useNavigate } from "@remix-run/react";
import PanZoom from "@client/components/ui/PanZoom";
import useMeasure from "@client/hooks/useMeasure";
import { useEffect, useRef, useState } from "react";
Expand All @@ -16,6 +16,7 @@ import { NodeCircle } from "./NodeCircle";
import { EdgeContextProvider } from "./EdgeContextProvider";
import { DeckEdges } from "./DeckEdges";
import { q } from "@client/context/AppContext";
import { usePrompt } from "@thorium/ui/AlertDialog";

export interface PanStateI {
x: number;
Expand Down Expand Up @@ -58,6 +59,7 @@ export default function DeckConfig() {
const panned = useRef(false);

const confirm = useConfirm();
const navigate = useNavigate();

const elementNameRef = useRef<HTMLParagraphElement>(null);
useEffect(() => {
Expand Down Expand Up @@ -103,6 +105,9 @@ export default function DeckConfig() {
</div>
);
}

const prompt = usePrompt();

return (
<div className="flex-1 flex flex-col gap-4 h-full " ref={ref}>
<PanZoom
Expand Down Expand Up @@ -253,6 +258,34 @@ export default function DeckConfig() {
>
{addingEdges ? "Done Adding Edges" : "Add Edges"}
</Button>
<Button
onClick={async (event) => {
event.preventDefault();
event.stopPropagation();
const deckname = await prompt({
header: "Change the current deck's name",
body: "Give this deck a distinct name",
defaultValue: deck.name,
inputProps: { className: "input-error" },
});
if (typeof deckname === "string") {
const result = await q.plugin.ship.deck.update.netSend({
pluginId,
shipId,
deckId: deck.name,
newName: deckname,
});
if (result) {
deck.name = deckname;
navigate(`../${result.name}`);
}
}
}}
>
Rename Deck
</Button>
</div>
<div>
{addingNodes && <p>Click on map to add node</p>}
{addingEdges &&
(selectedNodeId ? (
Expand Down

0 comments on commit 0f723db

Please sign in to comment.