pastebin/js/views/App.tsx

71 lines
2.3 KiB
TypeScript

// pastebin.run
// Copyright (C) 2022 Konrad Borowski
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { createSignal, Show } from "solid-js";
import Editor from "./Editor";
export default function App({
autoDelete,
rawPasteElement,
code,
}: {
autoDelete: Element | null;
rawPasteElement: Element | null;
code: string;
}) {
let form: HTMLFormElement | undefined;
const [isPaste, setIsPaste] = createSignal(true);
const [_, setCodeView] = createSignal({ code: "" });
const [label, setLabel] = createSignal<Element>();
return (
<form action="/" method="post" ref={(e) => (form = e)}>
<Show when={isPaste()}>{autoDelete}</Show>
<div id="toolbar">
<Show when={isPaste()}>{rawPasteElement}</Show>
<span id="right-buttons">
<select name="duration" id="duration">
<option value="1h">1 Hour</option>
<option value="3h">3 Hours</option>
<option value="24h">24 Hours</option>
<option value="3d">3 Days</option>
<option value="7d">7 Days</option>
<option value="90d">90 Days</option>
</select>{" "}
<button type="submit" name="share">
Share
</button>
</span>
</div>
<div id="split">
<div id="extrafieldsplit">
<div>{label}</div>
<div id="textarea">
<Editor
code={code}
onInput={() => {
setIsPaste(false);
}}
form={form as HTMLFormElement}
setCodeView={setCodeView}
setLabel={setLabel}
/>
</div>
</div>
</div>
</form>
);
}