From 1f5a82afbab25b1aa6cc2aef69cdb45906715799 Mon Sep 17 00:00:00 2001 From: Keenan Yafiq Date: Sun, 3 May 2026 21:02:39 +0700 Subject: [PATCH] feat: see others submissions --- app.js | 97 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/app.js b/app.js index 1745fbd..96afee6 100644 --- a/app.js +++ b/app.js @@ -18,6 +18,7 @@ const DEFAULT_IDENTITY = { const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJmb290cWxxem13YnBxdm9oaXF1Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzUyNTgyMjYsImV4cCI6MjA5MDgzNDIyNn0.yYwJ_YWhlMHGDVTQvbwAfVEPO9cJVo5QIlrllGDobSI"; const FEEDBACK_API_URL = "https://rfootqlqzmwbpqvohiqu.supabase.co/functions/v1/submit-feedback"; const USERS_API_URL = "https://rfootqlqzmwbpqvohiqu.supabase.co/functions/v1/hyper-action"; +const BETTER_LYRICS_LOGO = "https://better-lyrics.boidu.dev/icons/logo.svg"; let ytPlayer = null; window.parsedLines = []; @@ -88,11 +89,12 @@ async function signPayload(privateKeyJwk, payloadObj) { async function apiFetch(endpoint, options = {}) { const res = await fetch(`${API_BASE_URL}${endpoint}`, options); const isJson = res.headers.get("content-type")?.includes("application/json"); + const json = await res.json() if (!res.ok) { - const errorText = isJson ? (await res.json()).message || (await res.json()).error : await res.text(); + const errorText = isJson ? json.message || json.error : await res.text(); throw new Error(errorText || `Error ${res.status}`); } - return isJson ? res.json() : res.text(); + return isJson ? json : res.text(); } async function apiSignedAction(endpoint, payloadData) { @@ -260,16 +262,27 @@ async function initSearchPage() { } async function initSubmissionsPage() { + const user = JSON.parse(localStorage.getItem('unisonIdentity')); + const urlParams = new URLSearchParams(window.location.search); + const name = urlParams.get('name'); + const parsedName = name ? `${name}'${name.toLowerCase().endsWith('s') ? '' : 's'}` : "Their" + const id = urlParams.get('id') || user.keyId; + + const same = id === user.keyId + + const header = document.getElementById('search-header'); + header.innerText = `${same ? 'My' : parsedName} Submissions` + document.querySelector("title").innerText = `${same ? 'My' : parsedName} Submissions | Unison` + const resultsDiv = document.getElementById('search-results'); - resultsDiv.innerHTML = `
sync Loading your submissions...
`; + resultsDiv.innerHTML = `
sync Loading ${same ? 'your' : 'their'} submissions...
`; try { - const user = JSON.parse(localStorage.getItem('unisonIdentity')); - const res = await apiFetch(`/mine?limit=50`, { headers: { "x-key-id": user.keyId } }); + const res = await apiFetch(`/mine?limit=50`, { headers: { "x-key-id": id } }); const items = res.data ||[]; if (!items.length) { - resultsDiv.innerHTML = `
You haven't submitted any lyrics yet.
`; + resultsDiv.innerHTML = `
${same ? "You" : "They"} haven't submitted any lyrics yet.
`; return; } @@ -281,6 +294,7 @@ async function initSubmissionsPage() {
${(item.format || 'LRC').toUpperCase()} ${item.syncType ? `${item.syncType.toUpperCase()}` : ''} + ${item.confidence ? `${item.confidence.toUpperCase()} CONFIDENCE` : ''}