Skip to content

Commit

Permalink
Feat: add upload button (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamy authored Jun 20, 2024
1 parent c1aeab5 commit 47839ec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Help } from "./Help";
import { useRegionContext } from "./Region";
import { useAppStore } from "./store";
import { type Point as PointId, type Quad } from "./store/editor";
import { Upload } from "./Upload";
import { v } from "./vector";

type Point = { x: number; y: number };
Expand Down Expand Up @@ -41,6 +42,13 @@ const Toolbar = styled("div", {
},
});

const Buttons = styled("div", {
base: {
display: "flex",
gap: "5px",
},
});

export function Editor() {
const [store] = useAppStore().file;

Expand Down Expand Up @@ -75,10 +83,11 @@ export function EditorToolbar() {
Size: {width()} x {height()} Current: {move.current().x},{" "}
{move.current().y} Origin: {move.origin().x}, {move.origin().y}
</div>
<div>
<Buttons>
<Upload />
<Help />
<Header />
</div>
</Buttons>
</Toolbar>
);
}
Expand Down
15 changes: 6 additions & 9 deletions src/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { Show, createSignal } from "solid-js";
import { Portal } from "solid-js/web";
import { Button } from "./styles";

const HelpButton = styled(Button, {
base: {
marginRight: "15px",
},
});

const Backdrop = styled("div", {
base: {
position: "absolute",
Expand Down Expand Up @@ -43,9 +37,9 @@ export function Help() {

return (
<>
<HelpButton title="Click to show help" onClick={() => setShown(true)}>
<Button title="Click to show help" onClick={() => setShown(true)}>
Help
</HelpButton>
</Button>
<Show when={shown()}>
<Portal mount={document.body}>
<Modal close={() => setShown(false)} />
Expand All @@ -61,7 +55,10 @@ function Modal(props: { close: () => void }) {
<Backdrop onClick={() => props.close()} />
<Content>
<div>
<p>Drag and drop an image onto the app to upload.</p>
<p>
Drag and drop an image onto the app, or use Upload button to select
a file to upload.
</p>
<br />
<p>
The <b>left region</b> is the uploaded image:
Expand Down
32 changes: 32 additions & 0 deletions src/Upload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createSignal } from "solid-js";
import { useAppStore } from "./store";
import { Button } from "./styles";

export function Upload() {
const [_, { setFile }] = useAppStore().file;
const [input, setInput] = createSignal<HTMLInputElement>();

function show() {
input()?.click();
}

function upload() {
const file = input()?.files?.[0];
if (file) {
setFile(file);
}
}

return (
<>
<Button onClick={show}>Upload</Button>
<input
ref={setInput}
hidden
type="file"
accept="image/*"
onChange={upload}
/>
</>
);
}

0 comments on commit 47839ec

Please sign in to comment.