Skip to content

Commit ffc900b

Browse files
committed
Implemented canvas persistance
1 parent b2319ed commit ffc900b

24 files changed

Lines changed: 1152 additions & 124 deletions

commons/components/Icon.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,4 +654,13 @@ export function StickyNoteIcon() {
654654
<path d="M15 3v4a2 2 0 0 0 2 2h4" />
655655
</svg>
656656
);
657-
}
657+
}
658+
659+
export function CopyIcon() {
660+
return (
661+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-copy">
662+
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
663+
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
664+
</svg>
665+
);
666+
}

commons/components/Sidebar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function Sidebar({ isOpen, onSidebarClose }) {
6262
<NotesIcon />
6363
Notes
6464
</Link>
65-
<Link className="sidebar-button canvas" to="/canvas">
65+
<Link className="sidebar-button canvas" activeClassName="is-active" to="/canvases/">
6666
<BoardIcon />
6767
Canvas
6868
</Link>

commons/http/ApiClient.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { showToast } from "../components/Toast.jsx";
22

3-
async function request(method, url, payload) {
3+
async function request(method, url, payload, opts) {
44
const options = {
55
method: method,
6-
headers: {}
6+
headers: {},
7+
...opts,
78
};
89

910
if (payload instanceof FormData) {
@@ -319,6 +320,28 @@ async function deleteToken(tokenId) {
319320
return await request('DELETE', `/api/mcp/tokens/${tokenId}/`);
320321
}
321322

323+
// Canvases
324+
325+
async function getCanvases() {
326+
return await request('GET', '/api/canvases/');
327+
}
328+
329+
async function getCanvasById(canvasId) {
330+
return await request('GET', `/api/canvases/${canvasId}/`);
331+
}
332+
333+
async function createCanvas(canvas) {
334+
return await request('POST', '/api/canvases/', canvas);
335+
}
336+
337+
async function updateCanvas(canvasId, canvas, opts) {
338+
return await request('PUT', `/api/canvases/${canvasId}/`, canvas, opts);
339+
}
340+
341+
async function deleteCanvas(canvasId) {
342+
return await request('DELETE', `/api/canvases/${canvasId}/`);
343+
}
344+
322345
export default {
323346
request,
324347
checkUser,
@@ -362,5 +385,10 @@ export default {
362385
incrementTemplateUsage,
363386
getTokens,
364387
createToken,
365-
deleteToken
366-
};
388+
deleteToken,
389+
getCanvases,
390+
getCanvasById,
391+
createCanvas,
392+
updateCanvas,
393+
deleteCanvas
394+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.canvas-delete-modal {
2+
width: 400px;
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { h } from "../../assets/preact.esm.js"
2+
import { ModalBackdrop, ModalContainer, ModalHeader, ModalContent, ModalFooter } from "../../commons/components/Modal.jsx";
3+
import Button from "../../commons/components/Button.jsx";
4+
import "./CanvasDeleteModal.css";
5+
6+
export default function CanvasDeleteModal({ onDeleteClick, onCloseClick }) {
7+
return (
8+
<ModalBackdrop onClose={onCloseClick}>
9+
<ModalContainer className="canvas-delete-modal">
10+
<ModalHeader title="Delete Canvas" onClose={onCloseClick} />
11+
<ModalContent>
12+
<p className="modal-description">Are you sure you want to <b>permanently delete</b> this canvas?</p>
13+
</ModalContent>
14+
<ModalFooter isRightAligned>
15+
<Button onClick={onCloseClick}>Cancel</Button>
16+
<Button variant="danger" onClick={onDeleteClick}>Delete</Button>
17+
</ModalFooter>
18+
</ModalContainer>
19+
</ModalBackdrop>
20+
);
21+
}

features/canvas/CanvasPage.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
flex: 1;
1111
position: relative;
1212
overflow: hidden;
13-
background: var(--background-color);
13+
background: var(--bg-primary);
1414
}
1515

1616
.canvas-loading {
@@ -19,6 +19,6 @@
1919
justify-content: center;
2020
height: 100%;
2121
font-size: 1.125rem;
22-
color: var(--text-muted);
22+
color: var(--text-secondary);
2323
}
24-
}
24+
}

0 commit comments

Comments
 (0)