1
0
mirror of synced 2025-12-27 23:53:25 +00:00

feat(dashboard) frontend & working

This commit is contained in:
itsmrval
2024-08-02 11:16:54 +02:00
parent 77a6414fee
commit 6af894f319
5 changed files with 162 additions and 73 deletions

View File

@@ -15,13 +15,14 @@
'color': '0 0 15px rgba(99, 102, 241, 0.4)'
}
}
}
}
}
</script>
</head>
<body class="min-h-screen flex flex-col items-center justify-center p-4 bg-[url('/static/img/hero.svg')] bg-cover">
<h1 class="text-5xl p-4 text-center font-bold from-purple-600 via-pink-600 to-blue-600 bg-gradient-to-r bg-clip-text text-transparent">LKS <small>ninja</small></h1>
<img src="/static/img/logo.svg" width="128" height="128" class="mb-4" alt="Links Ninja">
<div class="bg-white/0 ring-1 ring-black/5 rounded-3xl p-8 w-full max-w-2xl backdrop-blur-md">
<div class="bg-white rounded-2xl p-6 shadow mb-6">
@@ -45,19 +46,23 @@
<span id="result-link"></span>
<button id="copy-btn" class="ml-2 px-2 py-1 bg-blue-500 text-white rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-300">Copy</button>
</div>
<div id="error" class="hidden p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400" role="alert">
<span class="font-medium">⚠️ An error occured!</span>
<span id="error-content"></span>
</div>
<div class="mt-6 flex justify-between items-center">
{{if .loggedIn}}
<a href="/dashboard"
class="px-6 py-2 bg-gradient-to-r from-green-400 to-blue-400 text-white rounded-full hover:from-green-500 hover:to-blue-500 focus:outline-none focus:ring-2 focus:ring-green-300 transition duration-300 ease-in-out transform hover:scale-105">
class="px-6 py-2 bg-blue-400 text-white rounded-full focus:outline-none focus:ring-2 focus:ring-green-300 transition duration-300 ease-in-out transform hover:scale-105">
Dashboard
</a>
<a href="/logout" class="px-6 py-2 bg-gradient-to-r from-purple-400 to-indigo-400 text-white rounded-full hover:from-purple-500 hover:to-indigo-500 focus:outline-none focus:ring-2 focus:ring-purple-300 transition duration-300 ease-in-out transform hover:scale-105">
<a href="/logout" class="px-6 py-2 bg-purple-400 text-white rounded-full focus:outline-none focus:ring-2 focus:ring-purple-300 transition duration-300 ease-in-out transform hover:scale-105">
Logout
</a>
{{else}}
<a href="/login"
class="px-6 py-2 bg-gradient-to-r from-blue-400 to-cyan-400 text-white rounded-full hover:from-blue-500 hover:to-cyan-500 focus:outline-none focus:ring-2 focus:ring-blue-300 transition duration-300 ease-in-out transform hover:scale-105">
class="px-6 py-2 bg-blue-400 text-white rounded-full focus:outline-none focus:ring-2 focus:ring-blue-300 transition duration-300 ease-in-out transform hover:scale-105">
<i class="fab fa-github"></i> Login using GitHub
</a>
{{end}}
@@ -65,6 +70,10 @@
</div>
<script>
const errorBox = document.getElementById('error');
const errorContent = document.getElementById('error-content');
const resultBox = document.getElementById('result');
const resultLink = document.getElementById('result-link');
document.getElementById('shorten-form').addEventListener('submit', function(e) {
e.preventDefault();
fetch('/', {
@@ -74,8 +83,14 @@
.then(response => response.json())
.then(data => {
this.reset();
const resultBox = document.getElementById('result');
const resultLink = document.getElementById('result-link');
errorBox.classList.add('hidden');
resultBox.classList.add('hidden');
if (data.error) {
errorContent.textContent = data.error;
errorBox.classList.remove('hidden');
return;
}
const shortURL = window.location.origin + '/' + data.shortURL;
resultLink.textContent = shortURL;
resultLink.setAttribute('data-url', shortURL);