From 451a7e88a3f0226635228cd61c507529e7821919 Mon Sep 17 00:00:00 2001 From: adjoly Date: Sat, 18 Oct 2025 21:29:51 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20friends=20list=20working=20(kinda)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/static/ts/views/Friends.ts | 65 +++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/src/front/static/ts/views/Friends.ts b/src/front/static/ts/views/Friends.ts index d384508..2908abf 100644 --- a/src/front/static/ts/views/Friends.ts +++ b/src/front/static/ts/views/Friends.ts @@ -1,5 +1,6 @@ import Aview from "./Aview.ts" import { setOnekoState } from "../oneko.ts" +import { dragElement } from "./drag.ts"; export default class extends Aview { @@ -21,8 +22,11 @@ export default class extends Aview { -
-

+
+ + +
`; @@ -31,15 +35,56 @@ export default class extends Aview { async run() { let uuid: String; - uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; + 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); - const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, { - method: "GET", - credentials: "include", - }); - if (userdata_req.status == 404) { - console.error("invalid user"); - return; + try { + uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2]; + const data_req = await fetch("http://localhost:3002/users/" + uuid + "/friends/count", { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + }); + if (data_req.status === 200) { + let data = await data_req.json(); + n_friends.innerHTML = ":D friends count : " + data.n_friends; + n_friends.classList.remove("hidden"); + + if (data.n_friends > 0) { + const list_req = await fetch("http://localhost:3002/users/" + uuid + "/friends?iStart=0&iEnd=20", { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + }); + if (list_req.status === 200) { + friends_list.classList.remove("hidden") + + 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; + friends_list.appendChild(new_friends); + } + } else { + n_friends.classList.add("hidden"); + friends_error_message.innerHTML = (await list_req.json()).error; + friends_error_message.classList.remove("hidden"); + } + } else { + friends_error_message.innerHTML = "failed to fetch friends"; + friends_error_message.classList.remove("hidden"); + } + } + } catch (error) { + friends_error_message.innerHTML = "failed to fetch friends"; + friends_error_message.classList.remove("hidden"); } } }