|
@@ -1,5 +1,6 @@
|
|
|
import Input from "../components/form/Input.tsx";
|
|
import Input from "../components/form/Input.tsx";
|
|
|
import Button from "../components/form/Button.tsx";
|
|
import Button from "../components/form/Button.tsx";
|
|
|
|
|
+import FileInput from "../components/form/FileInput.tsx";
|
|
|
import ThemeToggle from "./ThemeToggle.tsx";
|
|
import ThemeToggle from "./ThemeToggle.tsx";
|
|
|
|
|
|
|
|
interface HomeBarProps {
|
|
interface HomeBarProps {
|
|
@@ -7,16 +8,17 @@ interface HomeBarProps {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const settingsData: { [key: string]: string } = {};
|
|
const settingsData: { [key: string]: string } = {};
|
|
|
|
|
+const newPostData: { [key: string]: string } = {};
|
|
|
|
|
|
|
|
export default function HomeBar(props: HomeBarProps) {
|
|
export default function HomeBar(props: HomeBarProps) {
|
|
|
- const doNewPost = async () => {
|
|
|
|
|
|
|
+ const doCreatePost = async () => {
|
|
|
globalThis.$loading?.show();
|
|
globalThis.$loading?.show();
|
|
|
const resp = await fetch("/api/post", {
|
|
const resp = await fetch("/api/post", {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: { "Content-Type": "application/json" },
|
|
headers: { "Content-Type": "application/json" },
|
|
|
body: JSON.stringify({
|
|
body: JSON.stringify({
|
|
|
- title: "",
|
|
|
|
|
- content: "",
|
|
|
|
|
|
|
+ title: newPostData["title"] || "",
|
|
|
|
|
+ content: newPostData["content"] || "",
|
|
|
}),
|
|
}),
|
|
|
});
|
|
});
|
|
|
const respJson = await resp.json();
|
|
const respJson = await resp.json();
|
|
@@ -27,6 +29,45 @@ export default function HomeBar(props: HomeBarProps) {
|
|
|
return false;
|
|
return false;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const showNewPost = () => {
|
|
|
|
|
+ newPostData["title"] = "";
|
|
|
|
|
+ newPostData["content"] = "";
|
|
|
|
|
+ globalThis.$modal?.show(
|
|
|
|
|
+ "New Post",
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <FileInput
|
|
|
|
|
+ label="Import file (optional)"
|
|
|
|
|
+ accept=".md,.txt"
|
|
|
|
|
+ onInput={(e) => {
|
|
|
|
|
+ const file = (e.target as HTMLInputElement).files?.[0];
|
|
|
|
|
+ if (!file) {
|
|
|
|
|
+ newPostData["title"] = "";
|
|
|
|
|
+ newPostData["content"] = "";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ newPostData["title"] = file.name.replace(/\.(md|txt)$/, "");
|
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
|
+ reader.onload = () => {
|
|
|
|
|
+ newPostData["content"] = reader.result as string;
|
|
|
|
|
+ };
|
|
|
|
|
+ reader.readAsText(file);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>,
|
|
|
|
|
+ [
|
|
|
|
|
+ {
|
|
|
|
|
+ text: "Create",
|
|
|
|
|
+ onClick: async () => {
|
|
|
|
|
+ await doCreatePost();
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ text: "Cancel",
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ );
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const doLogout = async () => {
|
|
const doLogout = async () => {
|
|
|
const resp = await fetch("/api/user/logout");
|
|
const resp = await fetch("/api/user/logout");
|
|
|
const respJson = await resp.json();
|
|
const respJson = await resp.json();
|
|
@@ -104,7 +145,7 @@ export default function HomeBar(props: HomeBarProps) {
|
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center justify-between">
|
|
|
<Button
|
|
<Button
|
|
|
type="button"
|
|
type="button"
|
|
|
- onClick={doNewPost}
|
|
|
|
|
|
|
+ onClick={showNewPost}
|
|
|
>
|
|
>
|
|
|
New Post
|
|
New Post
|
|
|
</Button>
|
|
</Button>
|