diff --git a/src/front/index.html b/src/front/index.html
index 233ae24..6471bae 100644
--- a/src/front/index.html
+++ b/src/front/index.html
@@ -42,8 +42,8 @@
12:37
diff --git a/src/front/static/css/style.css b/src/front/static/css/style.css
index 35cd827..56bb708 100644
--- a/src/front/static/css/style.css
+++ b/src/front/static/css/style.css
@@ -1,4 +1,13 @@
@import "tailwindcss";
+@layer utilities {
+ .no-scrollbar::-webkit-scrollbar {
+ display: none;
+ }
+ .no-scrollbar {
+ -ms-overflow-style: none;
+ scrollbar-width: none;
+ }
+}
@font-face {
font-family: Kubasta;
diff --git a/src/front/static/ts/main.ts b/src/front/static/ts/main.ts
index 112b5a9..5301e4e 100644
--- a/src/front/static/ts/main.ts
+++ b/src/front/static/ts/main.ts
@@ -1,6 +1,6 @@
import { oneko } from "./oneko.ts";
-import Profile from "./views/Profile.ts";
-let profile_view = new Profile;
+import ProfileMenu from "./views/ProfileMenu.ts";
+let profile_view = new ProfileMenu;
export async function isLogged(): Promise
{
let uuid_req = await fetch("http://localhost:3001/me", {
@@ -40,7 +40,9 @@ const routes = [
{ path: "/login", view: () => import("./views/LoginPage.ts") },
{ path: "/register", view: () => import("./views/RegisterPage.ts") },
- { path: "/friends", view: () => import("./views/Friends.ts") }
+ { path: "/friends", view: () => import("./views/Friends.ts") },
+ { path: "/profile", view: () => import("./views/Profile.ts") },
+ { path: "/settings", view: () => import("./views/Settings.ts") },
];
const router = async () => {
@@ -97,7 +99,8 @@ 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");
@@ -113,3 +116,5 @@ function updateClock() {
setInterval(updateClock, 5000);
updateClock();
+
+oneko();
diff --git a/src/front/static/ts/oneko.ts b/src/front/static/ts/oneko.ts
index 9c579d4..a2a159b 100644
--- a/src/front/static/ts/oneko.ts
+++ b/src/front/static/ts/oneko.ts
@@ -18,20 +18,23 @@ export function setOnekoState(state: string) {
default:
oneko_state = 0;
}
+ return;
}
export function setOnekoOffset() {
- if (oneko_state == 1)
+ if (oneko_state != 0)
{
offsetX = document.getElementById("window").offsetLeft + 44;
offsetY = document.getElementById("window").offsetTop + 44 + 24;
- console.log(offsetX, offsetY);
}
+ return;
}
-export function setBallPos(x: number, y: number) {
+export function setBallPos(x: number, y: number)
+{
mousePosX = x + offsetX;
mousePosY = y + offsetY;
+ return;
}
export function oneko() {
@@ -39,7 +42,7 @@ export function oneko() {
window.matchMedia(`(prefers-reduced-motion: reduce)`) === true ||
window.matchMedia(`(prefers-reduced-motion: reduce)`).matches === true;
- if (isReducedMotion) return;
+ if (isReducedMotion) return ;
const nekoEl = document.createElement("div");
@@ -141,15 +144,15 @@ export function oneko() {
{
mousePosX = event.clientX;
mousePosY = event.clientY;
- }
+ }
});
window.requestAnimationFrame(onAnimationFrame);
}
- let lastFrameTimestamp;
+ let lastFrameTimestamp: number;
- function onAnimationFrame(timestamp) {
+ function onAnimationFrame(timestamp: number) {
// Stops execution if the neko element is removed from DOM
if (!nekoEl.isConnected) {
return;
diff --git a/src/front/static/ts/views/Friends.ts b/src/front/static/ts/views/Friends.ts
index a47cf86..90ff80b 100644
--- a/src/front/static/ts/views/Friends.ts
+++ b/src/front/static/ts/views/Friends.ts
@@ -1,12 +1,13 @@
import Aview from "./Aview.ts"
import { setOnekoState } from "../oneko.ts"
import { dragElement } from "./drag.ts";
+import { isLogged, navigationManager } from "../main.ts"
export default class extends Aview {
constructor() {
super();
- this.setTitle("Friends list");
+ this.setTitle("friends list");
setOnekoState("default");
}
@@ -26,22 +27,47 @@ export default class extends Aview {
-
+
+
`;
}
async run() {
+ if (!await isLogged())
+ navigationManager("/");
+
+ dragElement(document.getElementById("window"));
let uuid: String;
uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
+ const n_friends = (document.getElementById("friends_n") as HTMLParagraphElement);
+ const friends_error_message = (document.getElementById("friends-error-message") as HTMLParagraphElement);
+ const friends_message = (document.getElementById("friends-msg") as HTMLParagraphElement)
+ const friends_list = (document.getElementById("friends_list") as HTMLUListElement);
+ const new_friend = (document.getElementById("new-friend") as HTMLInputElement);
+ const add_friend_err = (document.getElementById("add-friend-err") as HTMLParagraphElement);
+ const add_friend_msg = (document.getElementById("add-friend-msg") as HTMLParagraphElement);
+
+ async function removeFriend(name) {
+ const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/" + name, {
+ method: "DELETE",
+ credentials: "include",
+ });
+ if (data_req.status === 200) {
+ console.log("friends removed success fully");
+ } else {
+ console.log("could not remove friend");
+ }
+ }
const list_friends = async () => {
const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/count", {
@@ -54,7 +80,7 @@ export default class extends Aview {
let data = await data_req.json();
if (data.n_friends > 0) {
- const list_req = await fetch("http://localhost:3002/users/" + uuid + "/friends?iStart=0&iEnd=20", {
+ const list_req = await fetch("http://localhost:3002/users/" + uuid + "/friends?iStart=0&iEnd=2147483647", {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -70,8 +96,21 @@ export default class extends Aview {
let list = (await list_req.json()).friends as JSON;
for (let i = 0; i < data.n_friends; i++) {
- let new_friends = document.createElement('li')
- new_friends.innerHTML = "- " + list[i].friendName;
+ let new_friends = document.createElement('li');
+
+ const span = document.createElement('span');
+ span.textContent = list[i].friendName;
+
+ const but = document.createElement('button');
+ but.textContent = "-";
+ but.className = "bg-red-500 text-white px-2 py-0 rounded hover:bg-red-600";
+ but.onclick = function() {
+ removeFriend(list[i].friendName);
+ list_friends()
+ }
+
+ new_friends.appendChild(span);
+ new_friends.appendChild(but);
friends_list.appendChild(new_friends);
}
} else {
@@ -80,16 +119,13 @@ export default class extends Aview {
friends_error_message.classList.remove("hidden");
}
} else {
- friends_error_message.innerHTML = "failed to fetch friends";
- friends_error_message.classList.remove("hidden");
+ friends_message.innerHTML = "you have no friends D:";
+ friends_message.classList.remove("hidden");
}
}
+
const add_friend = async () => {
- const new_friend = (document.getElementById("new-friend") as HTMLInputElement);
- const add_friend_err = (document.getElementById("add-friend-err") as HTMLParagraphElement);
- const add_friend_msg = (document.getElementById("add-friend-msg") as HTMLParagraphElement);
-
const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/" + new_friend.value, {
method: "POST",
credentials: "include",
@@ -105,39 +141,13 @@ export default class extends Aview {
add_friend_err.classList.remove("hidden");
if (!add_friend_msg.classList.contains("hidden"))
add_friend_msg.classList.add("hidden")
+ list_friends()
+ return
}
list_friends()
+ new_friend.value = '';
}
- const rm_friend = async () => {
- const new_friend = (document.getElementById("new-friend") as HTMLInputElement);
- const add_friend_err = (document.getElementById("add-friend-err") as HTMLParagraphElement);
- const add_friend_msg = (document.getElementById("add-friend-msg") as HTMLParagraphElement);
-
- const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/" + new_friend.value, {
- method: "DELETE",
- credentials: "include",
- });
- let data = await data_req.json()
- if (data_req.status === 200) {
- add_friend_msg.innerHTML = data.msg;
- add_friend_msg.classList.remove("hidden");
- if (!add_friend_err.classList.contains("hidden"))
- add_friend_err.classList.add("hidden")
- } else {
- add_friend_err.innerHTML = data.error;
- add_friend_err.classList.remove("hidden");
- if (!add_friend_msg.classList.contains("hidden"))
- add_friend_msg.classList.add("hidden")
- }
- list_friends()
- }
-
- dragElement(document.getElementById("window"));
- const n_friends = (document.getElementById("friends_n") as HTMLParagraphElement);
- const friends_error_message = (document.getElementById("friends-error-message") as HTMLParagraphElement);
- const friends_list = (document.getElementById("friends_list") as HTMLUListElement);
-
try {
const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/count", {
method: "GET",
@@ -158,6 +168,5 @@ export default class extends Aview {
friends_error_message.classList.remove("hidden");
}
document.getElementById("add-friends-button")?.addEventListener("click", add_friend);
- document.getElementById("rm-friends-button")?.addEventListener("click", rm_friend);
}
}
diff --git a/src/front/static/ts/views/Game.ts b/src/front/static/ts/views/Game.ts
index 2b73777..5e29d7b 100644
--- a/src/front/static/ts/views/Game.ts
+++ b/src/front/static/ts/views/Game.ts
@@ -4,7 +4,7 @@ import { dragElement } from "./drag.js"
import { setOnekoState, setBallPos, setOnekoOffset } from "../oneko.ts"
export default class extends Aview {
-
+
running: boolean;
constructor()
@@ -27,7 +27,7 @@ export default class extends Aview {
-
+
`;
}
@@ -49,7 +65,6 @@ export default class extends Aview {
credentials: "include",
body: JSON.stringify({ user: username, password: password }),
});
- const data = await data_req.json();
if (data_req.status === 200)
{
@@ -58,6 +73,7 @@ export default class extends Aview {
}
else if (data_req.status === 400)
{
+ const data = await data_req.json();
document.getElementById("login-error-message").innerHTML = "error: " + data.error;
document.getElementById("login-error-message").classList.remove("hidden");
}
diff --git a/src/front/static/ts/views/Profile.ts b/src/front/static/ts/views/Profile.ts
index 502b15c..e233f52 100644
--- a/src/front/static/ts/views/Profile.ts
+++ b/src/front/static/ts/views/Profile.ts
@@ -1,29 +1,38 @@
import Aview from "./Aview.ts"
+import { dragElement } from "./drag.ts";
+import { setOnekoState } from "../oneko.ts"
import { isLogged, navigationManager } from "../main.ts"
+
export default class extends Aview {
constructor()
{
super();
this.setTitle("profile");
+ setOnekoState("default");
}
async getHTML() {
return `
-