From e625afd3b4be148a1a9e151c8ea96069e2b618bc Mon Sep 17 00:00:00 2001 From: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com> Date: Thu, 5 Jun 2025 23:10:55 +0100 Subject: [PATCH 1/4] feat: added tags on upload and view tweaked navbar --- src/lib/components/Navbar.svelte | 4 +- src/lib/components/inputs/Text.svelte | 5 + src/lib/components/inputs/Textarea.svelte | 5 + src/lib/database.d.ts | 3 + src/lib/index.ts | 3 +- src/routes/space/+page.svelte | 148 +++++++++++++++++- src/routes/space/[id]/+page.svelte | 40 ++++- .../migrations/20250605162005_add_tags.sql | 3 + 8 files changed, 196 insertions(+), 15 deletions(-) create mode 100644 supabase/migrations/20250605162005_add_tags.sql diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 7cb89ea..2b8c514 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -21,11 +21,11 @@ display: flex; position: sticky; width: 100%; - height: 4rem; + height: 3.5rem; top: 0; left: 0; right: 0; - background: linear-gradient(-77deg, #2e4653, #3a5b56); + background: linear-gradient(-77deg, #2e4653, #223a37); box-shadow: 0rem 0rem 0.5rem #182125; align-items: center; overflow: hidden; diff --git a/src/lib/components/inputs/Text.svelte b/src/lib/components/inputs/Text.svelte index 494a68d..8488479 100644 --- a/src/lib/components/inputs/Text.svelte +++ b/src/lib/components/inputs/Text.svelte @@ -22,6 +22,11 @@ font-size: 1rem; } + ::placeholder { + color: #859a90; + opacity: 1; + } + input:focus { border-color: #007bff; outline: none; diff --git a/src/lib/components/inputs/Textarea.svelte b/src/lib/components/inputs/Textarea.svelte index 9ec4ebf..a167e26 100644 --- a/src/lib/components/inputs/Textarea.svelte +++ b/src/lib/components/inputs/Textarea.svelte @@ -25,6 +25,11 @@ font-size: 1rem; } + ::placeholder { + color: #859a90; + opacity: 1; + } + textarea:focus { border-color: #007bff; outline: none; diff --git a/src/lib/database.d.ts b/src/lib/database.d.ts index b254ea8..ba2f1c3 100644 --- a/src/lib/database.d.ts +++ b/src/lib/database.d.ts @@ -70,6 +70,7 @@ export type Database = { description: string | null id: string location: string | null + tags: string[] updated_at: string | null } Insert: { @@ -78,6 +79,7 @@ export type Database = { description?: string | null id?: string location?: string | null + tags?: string[] updated_at?: string | null } Update: { @@ -86,6 +88,7 @@ export type Database = { description?: string | null id?: string location?: string | null + tags?: string[] updated_at?: string | null } Relationships: [] diff --git a/src/lib/index.ts b/src/lib/index.ts index 72ed306..3b12f80 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -23,5 +23,6 @@ export const availableStudySpaceTags = [ "Hot", "Air conditioned", "Cold", - "Cringe" + "Cringe", + "PCs" ]; diff --git a/src/routes/space/+page.svelte b/src/routes/space/+page.svelte index af46874..f17fe0c 100644 --- a/src/routes/space/+page.svelte +++ b/src/routes/space/+page.svelte @@ -7,7 +7,7 @@ import Button from "$lib/components/Button.svelte"; import Images from "$lib/components/inputs/Images.svelte"; import type { Table } from "$lib"; - + import { availableStudySpaceTags } from "$lib"; const { data } = $props(); const { supabase } = $derived(data); @@ -16,7 +16,8 @@ let studySpaceData = $state, "id" | "created_at" | "updated_at">>({ description: "", building_location: "", - location: "" + location: "", + tags: [] }); async function uploadStudySpace() { @@ -63,6 +64,35 @@ invalidate: ["db:study_spaces"] }); } + + // Tag + let filteredTags = $state(availableStudySpaceTags); + let dropdownVisible = $state(false); + + function deleteTag(tagName: string) { + return () => { + studySpaceData.tags = studySpaceData.tags.filter((tag) => tag !== tagName); + }; + } + + function filterTags() { + const input = document.querySelector(".tagInput") as HTMLInputElement; + const filter = input.value.toLowerCase(); + filteredTags = availableStudySpaceTags + .filter((tag) => tag.toLowerCase().includes(filter)) + .filter((tag) => !studySpaceData.tags.includes(tag)); + } + + function addTag(tagName: string) { + return () => { + if (!studySpaceData.tags.includes(tagName)) { + studySpaceData.tags.push(tagName); + } + const input = document.querySelector(".tagInput") as HTMLInputElement; + input.value = ""; + filterTags(); + }; + } @@ -89,13 +119,46 @@ required /> - + +
+ {#each studySpaceData.tags as tagName (tagName)} + + {/each} + { + dropdownVisible = true; + }} + onblur={() => { + setTimeout(() => { + dropdownVisible = false; + }, 100); // Delay to allow click on tag + }} + placeholder="Add tags..." + /> + {#if dropdownVisible} +
+ {#each filteredTags as avaliableTag (avaliableTag)} + + {/each} +
+ {/if} +
+ +