diff --git a/src/front/static/ts/main.ts b/src/front/static/ts/main.ts index 6533fd8..112b5a9 100644 --- a/src/front/static/ts/main.ts +++ b/src/front/static/ts/main.ts @@ -7,10 +7,9 @@ export async function isLogged(): Promise { method: "GET", credentials: "include", }); - if (uuid_req.status === 200) - { + if (uuid_req.status === 200) { let uuid = await uuid_req.json(); - document.cookie = `uuid=${uuid.user};max-age=${60*60*24*7}`; + document.cookie = `uuid=${uuid.user};max-age=${60 * 60 * 24 * 7}`; return true; } else // 401 @@ -40,6 +39,8 @@ const routes = [ { path: "/login", view: () => import("./views/LoginPage.ts") }, { path: "/register", view: () => import("./views/RegisterPage.ts") }, + + { path: "/friends", view: () => import("./views/Friends.ts") } ]; const router = async () => { @@ -65,20 +66,18 @@ const router = async () => { view.run(); }; -document.getElementById("profile-button")?.addEventListener("click", () => {profile_view.run();}); +document.getElementById("profile-button")?.addEventListener("click", () => { profile_view.run(); }); window.addEventListener("popstate", router); document.addEventListener("DOMContentLoaded", () => { isLogged(); - document.body.addEventListener("click", e=> { - if (!e.target.closest("#taskbar-menu") && !e.target.matches("#profile-button")) - { - profile_view.open = false; - document.getElementById("taskbar-menu").innerHTML = ""; - } - if (e.target.matches("[data-link]")) - { + document.body.addEventListener("click", e => { + if (!e.target.closest("#taskbar-menu") && !e.target.matches("#profile-button")) { + profile_view.open = false; + document.getElementById("taskbar-menu").innerHTML = ""; + } + if (e.target.matches("[data-link]")) { e.preventDefault(); navigationManager(e.target.href); } @@ -86,9 +85,8 @@ document.addEventListener("DOMContentLoaded", () => { e.preventDefault(); }); - document.body.addEventListener("dblclick", e=> { - if (e.target.closest("[data-icon]")) - { + document.body.addEventListener("dblclick", e => { + if (e.target.closest("[data-icon]")) { e.preventDefault(); navigationManager(e.target.closest("[data-icon]").href); } @@ -99,8 +97,7 @@ document.addEventListener("DOMContentLoaded", () => { oneko(); -function updateClock() -{ +function updateClock() { const days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; const clock = document.getElementById("taskbar-clock"); diff --git a/src/front/static/ts/views/Friends.ts b/src/front/static/ts/views/Friends.ts new file mode 100644 index 0000000..d384508 --- /dev/null +++ b/src/front/static/ts/views/Friends.ts @@ -0,0 +1,45 @@ +import Aview from "./Aview.ts" +import { setOnekoState } from "../oneko.ts" + +export default class extends Aview { + + constructor() { + super(); + this.setTitle("Friends list"); + setOnekoState("default"); + } + + async getHTML() { + return ` +
+
+ friends.ts +
+ + + × +
+
+ +
+

+
+
+ `; + } + + async run() { + let uuid: String; + + uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; + + const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { + method: "GET", + credentials: "include", + }); + if (userdata_req.status == 404) { + console.error("invalid user"); + return; + } + } +}