add simple index page for user use
This commit is contained in:
parent
f9a4a30e61
commit
0a0a1b2a50
8 changed files with 412 additions and 20 deletions
170
public/css/style.css
Normal file
170
public/css/style.css
Normal file
|
@ -0,0 +1,170 @@
|
|||
:root {
|
||||
--bg: #0d0d0d;
|
||||
--fg: #f5f5f5;
|
||||
--accent: #4ea3ff;
|
||||
--card: #1c1c1c;
|
||||
--border: #333;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font-family: system-ui, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
main {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
background: var(--card);
|
||||
padding: 2rem;
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 0 10px #0008;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
text-align: center;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.profile {
|
||||
text-align: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
#avatar {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid var(--border);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
select,
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 0.6rem;
|
||||
margin-top: 0.25rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
font-size: 1rem;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
}
|
||||
|
||||
select:focus,
|
||||
button:hover {
|
||||
border-color: var(--accent);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#set-timezone {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
margin-top: 1rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
#set-timezone:hover {
|
||||
background: #2c8de6;
|
||||
}
|
||||
|
||||
a#login-btn {
|
||||
display: block;
|
||||
text-align: center;
|
||||
padding: 0.75rem;
|
||||
margin-top: 1rem;
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
border-radius: 0.5rem;
|
||||
text-decoration: none;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
a#login-btn:hover {
|
||||
background: #2c8de6;
|
||||
}
|
||||
|
||||
#status-msg {
|
||||
margin-top: 1rem;
|
||||
text-align: center;
|
||||
font-size: 0.9rem;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
button.danger {
|
||||
background: #ff4e4e;
|
||||
color: white;
|
||||
}
|
||||
|
||||
button.danger:hover {
|
||||
background: #e63838;
|
||||
}
|
||||
|
||||
.ts-wrapper.single .ts-control {
|
||||
background-color: var(--card);
|
||||
color: var(--fg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.6rem;
|
||||
font-size: 1rem;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.ts-wrapper.single.focus .ts-control {
|
||||
background-color: var(--card);
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(78, 163, 255, 0.25);
|
||||
}
|
||||
|
||||
.ts-dropdown {
|
||||
background-color: var(--card);
|
||||
color: var(--fg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.ts-dropdown .option {
|
||||
padding: 0.5rem 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.ts-dropdown .option:hover {
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.ts-dropdown .option.active {
|
||||
background-color: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.ts-wrapper .ts-control input {
|
||||
color: var(--fg);
|
||||
}
|
||||
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
41
public/index.html
Normal file
41
public/index.html
Normal file
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Timezone DB</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/css/tom-select.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/js/tom-select.complete.min.js" defer></script>
|
||||
|
||||
<link rel="stylesheet" href="/public/css/style.css" />
|
||||
<script src="/public/js/index.js" defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<section id="login-section" class="hidden">
|
||||
<h1>Timezone DB</h1>
|
||||
<a href="/auth/discord?redirect=/" id="login-btn">Log in with Discord</a>
|
||||
</section>
|
||||
|
||||
<section id="timezone-section" class="hidden">
|
||||
<div class="profile">
|
||||
<img id="avatar" class="hidden" width="80" height="80" alt="Avatar" />
|
||||
<h2 id="auth-status">Logged in</h2>
|
||||
</div>
|
||||
|
||||
<label for="timezone-select">Select your timezone:</label>
|
||||
<select id="timezone-select">
|
||||
<option value="">Select timezone</option>
|
||||
</select>
|
||||
<button id="set-timezone">Save</button>
|
||||
<button id="delete-timezone" class="danger hidden">Delete Timezone</button>
|
||||
|
||||
<p id="status-msg"></p>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
87
public/js/index.js
Normal file
87
public/js/index.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
const loginSection = document.getElementById("login-section");
|
||||
const timezoneSection = document.getElementById("timezone-section");
|
||||
const avatarEl = document.getElementById("avatar");
|
||||
const authStatusEl = document.getElementById("auth-status");
|
||||
const timezoneSelect = document.getElementById("timezone-select");
|
||||
const setBtn = document.getElementById("set-timezone");
|
||||
const statusMsg = document.getElementById("status-msg");
|
||||
|
||||
const timezones = Intl.supportedValuesOf("timeZone");
|
||||
timezones.forEach(tz => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = tz;
|
||||
opt.textContent = tz;
|
||||
timezoneSelect.appendChild(opt);
|
||||
});
|
||||
|
||||
const ts = new TomSelect("#timezone-select", {
|
||||
create: false,
|
||||
sorted: true,
|
||||
searchField: ["text"],
|
||||
maxOptions: 1000
|
||||
});
|
||||
|
||||
async function fetchUserInfo() {
|
||||
try {
|
||||
const res = await fetch("/me", { credentials: "include" });
|
||||
if (!res.ok) throw new Error();
|
||||
|
||||
const json = await res.json();
|
||||
const user = json.user;
|
||||
const tz = json.timezone;
|
||||
|
||||
authStatusEl.textContent = user.username;
|
||||
|
||||
if (user.avatar) {
|
||||
avatarEl.src = `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`;
|
||||
avatarEl.classList.remove("hidden");
|
||||
}
|
||||
|
||||
loginSection.classList.add("hidden");
|
||||
timezoneSection.classList.remove("hidden");
|
||||
|
||||
const deleteBtn = document.getElementById("delete-timezone");
|
||||
|
||||
if (tz) {
|
||||
ts.setValue(tz);
|
||||
deleteBtn.classList.remove("hidden");
|
||||
} else {
|
||||
ts.clear();
|
||||
deleteBtn.classList.add("hidden");
|
||||
}
|
||||
|
||||
deleteBtn.addEventListener("click", async () => {
|
||||
try {
|
||||
const res = await fetch("/delete", { credentials: "include" });
|
||||
if (!res.ok) throw new Error();
|
||||
|
||||
ts.clear();
|
||||
statusMsg.textContent = "Timezone deleted.";
|
||||
deleteBtn.classList.add("hidden");
|
||||
} catch {
|
||||
statusMsg.textContent = "Failed to delete timezone.";
|
||||
}
|
||||
});
|
||||
|
||||
} catch {
|
||||
loginSection.classList.remove("hidden");
|
||||
timezoneSection.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
setBtn.addEventListener("click", async () => {
|
||||
const timezone = ts.getValue();
|
||||
if (!timezone) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/set?timezone=${encodeURIComponent(timezone)}`, {
|
||||
credentials: "include",
|
||||
});
|
||||
if (!res.ok) throw new Error();
|
||||
statusMsg.textContent = "Timezone updated!";
|
||||
} catch {
|
||||
statusMsg.textContent = "Failed to update timezone.";
|
||||
}
|
||||
});
|
||||
|
||||
fetchUserInfo();
|
Loading…
Add table
Add a link
Reference in a new issue