feat: middle save
This commit is contained in:
parent
0475f9cdd1
commit
536af9b0e0
9 changed files with 73 additions and 26 deletions
|
@ -39,7 +39,6 @@ func init() {
|
||||||
);
|
);
|
||||||
`))
|
`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
.ka-nav {
|
.ka-nav {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 50px;
|
min-height: 60px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
22
src/App.tsx
22
src/App.tsx
|
@ -10,9 +10,10 @@ import "./App.scss";
|
||||||
import kuma from "./assets/kuma.png";
|
import kuma from "./assets/kuma.png";
|
||||||
import NotFound from "./components/notfound";
|
import NotFound from "./components/notfound";
|
||||||
import Login from "./components/login";
|
import Login from "./components/login";
|
||||||
import { useAuthStore } from "./store/auth";
|
import { AccountData, useAuthStore } from "./store/auth";
|
||||||
import Logout from "./components/logout";
|
import Logout from "./components/logout";
|
||||||
import Settings from "./components/settings";
|
import Settings from "./components/settings";
|
||||||
|
import { FileNavigator } from "./components/navigation";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
|
@ -31,6 +32,7 @@ function Dashboard({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<main className="container-md ka-view">
|
<main className="container-md ka-view">
|
||||||
<Header />
|
<Header />
|
||||||
|
<FileNavigator />
|
||||||
{children}
|
{children}
|
||||||
<Footer />
|
<Footer />
|
||||||
</main>
|
</main>
|
||||||
|
@ -70,6 +72,7 @@ function View() {
|
||||||
function Header() {
|
function Header() {
|
||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
const [isAuth, setAuth] = useState(false);
|
const [isAuth, setAuth] = useState(false);
|
||||||
|
const [username, setUsername] = useState("undefined");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (auth.token === null) {
|
if (auth.token === null) {
|
||||||
|
@ -80,6 +83,21 @@ function Header() {
|
||||||
if (ok)
|
if (ok)
|
||||||
setAuth(true);
|
setAuth(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fetch("/api/auth/read", {
|
||||||
|
method: "GET",
|
||||||
|
mode: "same-origin",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Basic ${auth.token}`
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
if (res.status !== 200)
|
||||||
|
return;
|
||||||
|
|
||||||
|
return res.json();
|
||||||
|
}).then((data: AccountData) => {
|
||||||
|
setUsername(data.username);
|
||||||
|
});
|
||||||
}, [auth, isAuth]);
|
}, [auth, isAuth]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -107,7 +125,7 @@ function Header() {
|
||||||
<DynamicIcon name="settings" size={15} />
|
<DynamicIcon name="settings" size={15} />
|
||||||
</a>
|
</a>
|
||||||
<div className="login-info">
|
<div className="login-info">
|
||||||
<span>Logged in as Admin</span>
|
<span>Logged in as {username}</span>
|
||||||
<a className="login-btn" href="/logout">
|
<a className="login-btn" href="/logout">
|
||||||
Logout
|
Logout
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
.ka-dir-row {
|
.ka-dir-row {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 35px;
|
||||||
display: grid;
|
display: grid;
|
||||||
padding: 0.25rem 10px;
|
padding: 0.25rem 10px;
|
||||||
place-items: left center;
|
place-items: left center;
|
||||||
|
|
|
@ -107,19 +107,10 @@ function FileView() {
|
||||||
{convert(path.data.total)}
|
{convert(path.data.total)}
|
||||||
|
|
||||||
<div id="download">
|
<div id="download">
|
||||||
<button className="download-btn secondary" onClick={ev => {
|
<a className="download-btn" href={`/api/download${path.data?.path}`}>
|
||||||
ev.preventDefault();
|
|
||||||
const link = document.createElement("a");
|
|
||||||
link.href = `/api/download${path.data?.path}`;
|
|
||||||
link.download = `/api/download${path.data?.path}`;
|
|
||||||
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
}}>
|
|
||||||
<DynamicIcon name="cloud-download" />
|
<DynamicIcon name="cloud-download" />
|
||||||
<span>Download</span>
|
<span>Download</span>
|
||||||
</button>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
10
src/components/navigation/index.tsx
Normal file
10
src/components/navigation/index.tsx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { useLocation } from "react-router";
|
||||||
|
|
||||||
|
export function FileNavigator() {
|
||||||
|
const location = useLocation();
|
||||||
|
const split = location.pathname.substring(1, location.pathname.length).split("/");
|
||||||
|
|
||||||
|
return <div>
|
||||||
|
|
||||||
|
</div>;
|
||||||
|
}
|
|
@ -33,8 +33,12 @@ function Settings() {
|
||||||
return (
|
return (
|
||||||
<div className="ka-settings">
|
<div className="ka-settings">
|
||||||
<h2 className="ka-title">General</h2>
|
<h2 className="ka-title">General</h2>
|
||||||
|
|
||||||
<AccountSetting auth={auth} />
|
<AccountSetting auth={auth} />
|
||||||
|
|
||||||
|
<h2 className="ka-title">Private Directory</h2>
|
||||||
|
<SettingBox>
|
||||||
|
<h3>Not provided features</h3>
|
||||||
|
</SettingBox>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +56,8 @@ function AccountSetting({ auth }: { auth: AuthState }) {
|
||||||
const pwRef = useRef<HTMLInputElement>(null);
|
const pwRef = useRef<HTMLInputElement>(null);
|
||||||
const ckRef = useRef<HTMLInputElement>(null);
|
const ckRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const [remove, setRemove] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingBox>
|
<SettingBox>
|
||||||
<h4>Account Setting</h4>
|
<h4>Account Setting</h4>
|
||||||
|
@ -117,7 +123,14 @@ function AccountSetting({ auth }: { auth: AuthState }) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form className="box-col">
|
<form className="box-col">
|
||||||
<button type="submit" className="danger" onClick={ev => {
|
<label className="checkbox">
|
||||||
|
<input type="checkbox" onChange={ev => {
|
||||||
|
setRemove(ev.target.checked);
|
||||||
|
}} />
|
||||||
|
<span>I agree to remove my account.</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit" className="danger" disabled={!remove} onClick={ev => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
fetch("/api/auth/delete", {
|
fetch("/api/auth/delete", {
|
||||||
|
|
|
@ -49,10 +49,29 @@
|
||||||
.line {
|
.line {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.checkbox {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: row;
|
||||||
|
|
||||||
|
span {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pw-change {
|
#pw-change {
|
||||||
|
input[type="text"], input[type="password"] {
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 25px 0 0 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
.input-pass {
|
.input-pass {
|
||||||
height: 40;
|
height: 40;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -62,11 +81,6 @@
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
|
||||||
width: 100%;
|
|
||||||
border-radius: 25px 0 0 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pw-btn {
|
.pw-btn {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
|
@ -76,8 +90,4 @@
|
||||||
border-radius: 0 25px 25px 0;
|
border-radius: 0 25px 25px 0;
|
||||||
background-color: var(--nav-color);
|
background-color: var(--nav-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,11 @@ export interface AuthData {
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AccountData {
|
||||||
|
ok: number;
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface AuthState {
|
export interface AuthState {
|
||||||
token: string | null;
|
token: string | null;
|
||||||
|
|
Loading…
Reference in a new issue