Refactor navbar implementation: replace navbar.js with main.js, update HTML references, and enhance button styles. Add author username to paste retrieval response and implement clipboard notification feature.

### Copilot Generated Commit Message
This commit is contained in:
whoswhip
2025-05-19 02:11:24 -04:00
parent 704d7149fc
commit 1382fb9f07
12 changed files with 189 additions and 23 deletions
+22 -3
View File
@@ -843,6 +843,7 @@ namespace SharpbinV2.Server
return; return;
} }
var paste = await Database.GetPasteFromID(pasteid); var paste = await Database.GetPasteFromID(pasteid);
string authorUsername = null;
if (paste == null) if (paste == null)
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
@@ -852,15 +853,33 @@ namespace SharpbinV2.Server
if (paste.AuthorUUID != "0") if (paste.AuthorUUID != "0")
{ {
var user = await Database.UserFromUUID(paste.AuthorUUID); var user = await Database.UserFromUUID(paste.AuthorUUID);
paste.AuthorUUID = user.Username; authorUsername = user?.Username;
} }
else else
{ {
paste.AuthorUUID = "Anonymous"; paste.AuthorUUID = "Anonymous";
authorUsername = "Anonymous";
} }
paste.FilePath = null;
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, paste = paste }); await context.Response.WriteAsJsonAsync(new
{
success = true,
paste = new
{
paste.UUID,
paste.ID,
paste.Visibility,
paste.Title,
paste.AuthorUUID,
username = authorUsername,
paste.Created,
paste.Edited,
paste.Size,
paste.TrueSize,
paste.Views,
paste.Syntax
}
});
}); });
app.MapGet("/api/pastes/{pasteid}", async (HttpContext context) => app.MapGet("/api/pastes/{pasteid}", async (HttpContext context) =>
{ {
+1 -1
View File
@@ -33,6 +33,6 @@
</div> </div>
<script src="js/archive.js"></script> <script src="js/archive.js"></script>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
</body> </body>
</html> </html>
+11 -1
View File
@@ -80,10 +80,20 @@ button {
background-color: var(--neutral-800); background-color: var(--neutral-800);
color: var(--neutral-50); color: var(--neutral-50);
cursor: pointer; cursor: pointer;
transition: background-color 0.3s; transition: background-color 0.2s;
font-size: 1rem; font-size: 1rem;
} }
button:hover {
background-color: var(--neutral-700);
border-color: var(--neutral-600);
}
button:active {
background-color: var(--neutral-600);
border-color: var(--neutral-500);
}
.hljs { .hljs {
padding: 1rem; padding: 1rem;
border-radius: 6px; border-radius: 6px;
+47 -1
View File
@@ -7,7 +7,7 @@
} }
:root { :root {
--neutral-50: #fafafa; --neutral-50: #fafafa;
--neutral-100: #f5f5f5; --neutral-100: #f5f5f5;
--neutral-200: #e5e5e5; --neutral-200: #e5e5e5;
--neutral-300: #d4d4d4; --neutral-300: #d4d4d4;
@@ -128,6 +128,7 @@ select:hover {
outline: none; outline: none;
border: 1px solid var(--neutral-600); border: 1px solid var(--neutral-600);
} }
select:focus { select:focus {
outline: none; outline: none;
border: 1px solid var(--neutral-600); border: 1px solid var(--neutral-600);
@@ -136,3 +137,48 @@ select:focus {
#syntax { #syntax {
padding-left: 14rem; padding-left: 14rem;
} }
#syntax-label {
margin-bottom: -2.3rem;
margin-top: 1.1rem;
z-index: 2;
align-self: flex-start;
margin-left: 1rem;
pointer-events: none;
}
@media screen and (max-width: 800px) {
.main-container {
width: 90%;
}
.create-form textarea {
max-height: 100%;
}
#syntax-label {
margin-bottom: 0.5rem;
margin-top: 0.5rem;
margin-left: 0;
text-align: center;
align-self: center;
max-width: 12rem;
overflow: hidden;
white-space: nowrap;
/*
possible style, just not good for small screens on desktop for some reason
margin-left: 6.7rem;
max-width: 12rem;
overflow: hidden;
white-space: nowrap;
margin-bottom: -1.9rem;
*/
}
#syntax {
padding-left: 0.7rem;
}
}
+1 -1
View File
@@ -48,5 +48,5 @@
</div> </div>
</body> </body>
<script src="js/dash.js"></script> <script src="js/dash.js"></script>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
</html> </html>
+1 -1
View File
@@ -20,5 +20,5 @@
</div> </div>
</body> </body>
<script src="js/error.js"></script> <script src="js/error.js"></script>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
</html> </html>
+2 -2
View File
@@ -20,7 +20,7 @@
<form class="create-form" id="create-form"> <form class="create-form" id="create-form">
<input type="text" name="title" id="title" placeholder="Title" maxlength="500"> <input type="text" name="title" id="title" placeholder="Title" maxlength="500">
<textarea name="content" id="content" placeholder="Content"></textarea> <textarea name="content" id="content" placeholder="Content"></textarea>
<label style="margin-bottom: -2.3rem; margin-top: 1.1rem; z-index: 2; align-self: flex-start; margin-left: 1rem; pointer-events: none;">Syntax Highlighting -</label> <label id="syntax-label" style="">Syntax Highlighting -</label>
<select name="syntax" id="syntax"> <select name="syntax" id="syntax">
<option value="none">None</option> <option value="none">None</option>
<option value="AutoHotkey">AutoHotkey</option> <option value="AutoHotkey">AutoHotkey</option>
@@ -57,7 +57,7 @@
</form> </form>
</div> </div>
</body> </body>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
<script src="js/index.js"></script> <script src="js/index.js"></script>
</html> </html>
@@ -120,7 +120,7 @@ const navbarHTML = `
.nav-links { .nav-links {
position: fixed; position: fixed;
top: 60px; top: 55px;
left: 0; left: 0;
right: 0; right: 0;
background-color: var(--neutral-900); background-color: var(--neutral-900);
@@ -134,27 +134,22 @@ const navbarHTML = `
} }
.nav-links.show { .nav-links.show {
max-height: 300px; max-height: 350px;
padding: 1rem 0; padding: 1rem 0;
padding-bottom: 2rem;
} }
.nav-link { .nav-link {
width: 90%; width: 90%;
max-width: 90%;
text-align: center; text-align: center;
padding: 1rem; padding: 1rem;
border-bottom: 1px solid var(--neutral-800);
} }
.home-link { .home-link {
border: none;
border-bottom: 1px solid var(--neutral-800);
order: -1; order: -1;
} }
.nav-link:last-child {
border-bottom: none;
}
.hamburger { .hamburger {
display: flex; display: flex;
} }
@@ -212,3 +207,98 @@ window.toggleMenu = function () {
nav.classList.toggle('show'); nav.classList.toggle('show');
hamburger.classList.toggle('active'); hamburger.classList.toggle('active');
}; };
function showNotification(message, type = 'info', duration = 3000) {
if (!document.getElementById('notification-style')) {
const style = document.createElement('style');
style.id = 'notification-style';
style.textContent = `
.notification-container {
position: fixed;
bottom: 32px;
right: 32px;
z-index: 2000;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 0.75rem;
}
.notification {
min-width: 240px;
max-width: 350px;
padding: 12px 20px;
border-radius: 8px;
color: #ef4444;
font-size: 1rem;
font-weight: 500;
box-shadow: 0 6px 24px rgba(0,0,0,0.28);
margin-top: 0.5rem;
opacity: 0;
transform: translateY(20px);
animation: notification-in 0.3s forwards;
border: 1px solid rgba(220, 38, 38, 0.2);
background: rgba(220, 38, 38, 0.1);
letter-spacing: 0.01em;
display: flex;
align-items: center;
gap: 0.75em;
}
.notification-info {
color: #e5e7eb;
background: var(--neutral-900, #181a20);
border: 1px solid var(--neutral-800, #23272f);
}
.notification-warning {
color: #f59e42;
background: rgba(245, 158, 66, 0.10);
border: 1px solid rgba(245, 158, 66, 0.18);
}
.notification-error {
color: #ef4444;
background: rgba(220, 38, 38, 0.1);
border: 1px solid rgba(220, 38, 38, 0.2);
}
@keyframes notification-in {
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 600px) {
.notification-container {
right: 8px;
bottom: 8px;
}
.notification {
min-width: 160px;
max-width: 90vw;
padding: 0.75rem 1rem;
}
}
`;
document.head.appendChild(style);
}
let container = document.querySelector('.notification-container');
if (!container) {
container = document.createElement('div');
container.className = 'notification-container';
document.body.appendChild(container);
}
const notif = document.createElement('div');
notif.className = `notification notification-${type}`;
notif.textContent = message;
container.appendChild(notif);
setTimeout(() => {
notif.style.opacity = '0';
notif.style.transform = 'translateY(20px)';
setTimeout(() => {
notif.remove();
if (container.childElementCount === 0) {
container.remove();
}
}, 300);
}, duration);
}
+1
View File
@@ -38,6 +38,7 @@ function addInfo(paste) {
document.getElementById("info-throbber").style.display = "none"; document.getElementById("info-throbber").style.display = "none";
document.getElementById("copy-button").addEventListener("click", function () { document.getElementById("copy-button").addEventListener("click", function () {
navigator.clipboard.writeText(window.location.href); navigator.clipboard.writeText(window.location.href);
showNotification("Paste copied to clipboard!", "info", 2000);
}); });
document.getElementById("download-button").addEventListener("click", function () { document.getElementById("download-button").addEventListener("click", function () {
const content = document.getElementById("paste-content").innerText; const content = document.getElementById("paste-content").innerText;
+1 -1
View File
@@ -38,7 +38,7 @@
</div> </div>
<script src="js/login.js"></script> <script src="js/login.js"></script>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
</body> </body>
</html> </html>
+1 -1
View File
@@ -40,5 +40,5 @@
</div> </div>
</body> </body>
<script src="js/paste.js"></script> <script src="js/paste.js"></script>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
</html> </html>
+1 -1
View File
@@ -46,7 +46,7 @@
</div> </div>
<script src="js/register.js"></script> <script src="js/register.js"></script>
<script src="js/navbar.js"></script> <script src="js/main.js"></script>
</body> </body>
</html> </html>