feat: added tags on upload and view tweaked navbar
This commit is contained in:
@@ -21,11 +21,11 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 4rem;
|
height: 3.5rem;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
background: linear-gradient(-77deg, #2e4653, #3a5b56);
|
background: linear-gradient(-77deg, #2e4653, #223a37);
|
||||||
box-shadow: 0rem 0rem 0.5rem #182125;
|
box-shadow: 0rem 0rem 0.5rem #182125;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::placeholder {
|
||||||
|
color: #859a90;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
input:focus {
|
input:focus {
|
||||||
border-color: #007bff;
|
border-color: #007bff;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|||||||
@@ -25,6 +25,11 @@
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::placeholder {
|
||||||
|
color: #859a90;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
textarea:focus {
|
textarea:focus {
|
||||||
border-color: #007bff;
|
border-color: #007bff;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|||||||
3
src/lib/database.d.ts
vendored
3
src/lib/database.d.ts
vendored
@@ -70,6 +70,7 @@ export type Database = {
|
|||||||
description: string | null
|
description: string | null
|
||||||
id: string
|
id: string
|
||||||
location: string | null
|
location: string | null
|
||||||
|
tags: string[]
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
@@ -78,6 +79,7 @@ export type Database = {
|
|||||||
description?: string | null
|
description?: string | null
|
||||||
id?: string
|
id?: string
|
||||||
location?: string | null
|
location?: string | null
|
||||||
|
tags?: string[]
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
@@ -86,6 +88,7 @@ export type Database = {
|
|||||||
description?: string | null
|
description?: string | null
|
||||||
id?: string
|
id?: string
|
||||||
location?: string | null
|
location?: string | null
|
||||||
|
tags?: string[]
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
|
|||||||
@@ -23,5 +23,6 @@ export const availableStudySpaceTags = [
|
|||||||
"Hot",
|
"Hot",
|
||||||
"Air conditioned",
|
"Air conditioned",
|
||||||
"Cold",
|
"Cold",
|
||||||
"Cringe"
|
"Cringe",
|
||||||
|
"PCs"
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import Button from "$lib/components/Button.svelte";
|
import Button from "$lib/components/Button.svelte";
|
||||||
import Images from "$lib/components/inputs/Images.svelte";
|
import Images from "$lib/components/inputs/Images.svelte";
|
||||||
import type { Table } from "$lib";
|
import type { Table } from "$lib";
|
||||||
|
import { availableStudySpaceTags } from "$lib";
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
const { supabase } = $derived(data);
|
const { supabase } = $derived(data);
|
||||||
|
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
let studySpaceData = $state<Omit<Table<"study_spaces">, "id" | "created_at" | "updated_at">>({
|
let studySpaceData = $state<Omit<Table<"study_spaces">, "id" | "created_at" | "updated_at">>({
|
||||||
description: "",
|
description: "",
|
||||||
building_location: "",
|
building_location: "",
|
||||||
location: ""
|
location: "",
|
||||||
|
tags: []
|
||||||
});
|
});
|
||||||
|
|
||||||
async function uploadStudySpace() {
|
async function uploadStudySpace() {
|
||||||
@@ -63,6 +64,35 @@
|
|||||||
invalidate: ["db:study_spaces"]
|
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();
|
||||||
|
};
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Navbar>
|
<Navbar>
|
||||||
@@ -89,13 +119,46 @@
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<label for="description">Add a description:</label>
|
<label for="tags">Add tags:</label>
|
||||||
|
<div class="tagDisplay">
|
||||||
|
{#each studySpaceData.tags as tagName (tagName)}
|
||||||
|
<button class="tag" onclick={deleteTag(tagName)} type="button">
|
||||||
|
{tagName}
|
||||||
|
<img src={crossUrl} alt="delete" /></button
|
||||||
|
>
|
||||||
|
{/each}
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="tagInput"
|
||||||
|
class="tagInput"
|
||||||
|
oninput={filterTags}
|
||||||
|
onfocus={() => {
|
||||||
|
dropdownVisible = true;
|
||||||
|
}}
|
||||||
|
onblur={() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
dropdownVisible = false;
|
||||||
|
}, 100); // Delay to allow click on tag
|
||||||
|
}}
|
||||||
|
placeholder="Add tags..."
|
||||||
|
/>
|
||||||
|
{#if dropdownVisible}
|
||||||
|
<div class="tagDropdown">
|
||||||
|
{#each filteredTags as avaliableTag (avaliableTag)}
|
||||||
|
<button class="avaliableTag" onclick={addTag(avaliableTag)} type="button">
|
||||||
|
{avaliableTag}</button
|
||||||
|
>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label for="description">Optional brief description:</label>
|
||||||
<Textarea
|
<Textarea
|
||||||
name="description"
|
name="description"
|
||||||
bind:value={studySpaceData.description}
|
bind:value={studySpaceData.description}
|
||||||
placeholder="A quiet and well-lit, but small space..."
|
placeholder="A quiet room with a lovely view of the park."
|
||||||
rows={5}
|
rows={2}
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<label for="building-location">Add the building location:</label>
|
<label for="building-location">Add the building location:</label>
|
||||||
@@ -111,7 +174,7 @@
|
|||||||
type="submit"
|
type="submit"
|
||||||
disabled={(spaceImgs?.length || 0) === 0 ||
|
disabled={(spaceImgs?.length || 0) === 0 ||
|
||||||
!studySpaceData.location ||
|
!studySpaceData.location ||
|
||||||
!studySpaceData.description ||
|
studySpaceData.tags.length === 0 ||
|
||||||
!studySpaceData.building_location ||
|
!studySpaceData.building_location ||
|
||||||
uploading}
|
uploading}
|
||||||
>
|
>
|
||||||
@@ -143,4 +206,75 @@
|
|||||||
margin-left: -0.5rem;
|
margin-left: -0.5rem;
|
||||||
width: calc(100% + 1rem);
|
width: calc(100% + 1rem);
|
||||||
}
|
}
|
||||||
|
.tagDisplay {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.4rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: left;
|
||||||
|
justify-content: left;
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
border: 2px solid #eaffeb;
|
||||||
|
background: none;
|
||||||
|
color: #eaffeb;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
.tagInput {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: none;
|
||||||
|
color: #eaffeb;
|
||||||
|
font-size: 1rem;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
::placeholder {
|
||||||
|
color: #859a90;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.tag {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
background-color: #2e4653;
|
||||||
|
color: #eaffeb;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
cursor: pointer;
|
||||||
|
border-width: 0rem;
|
||||||
|
}
|
||||||
|
.tag img {
|
||||||
|
width: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
margin-left: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tagDropdown {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.4rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
position: absolute;
|
||||||
|
background-color: #2e4653;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 0.5rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
max-height: 10rem;
|
||||||
|
top: 100%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.avaliableTag {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #eaffeb;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin: 0%;
|
||||||
|
padding: 0%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -29,11 +29,21 @@
|
|||||||
<div class="nameContainer">
|
<div class="nameContainer">
|
||||||
{space.location}
|
{space.location}
|
||||||
</div>
|
</div>
|
||||||
<p class="descContainer">
|
{#if space.description != null && space.description.length > 0}
|
||||||
{space.description}
|
<p class="descContainer">
|
||||||
</p>
|
{space.description}
|
||||||
|
</p>
|
||||||
|
<hr />
|
||||||
|
{/if}
|
||||||
|
<div class="tagContainer">
|
||||||
|
{#each space.tags as tag}
|
||||||
|
<span class="tag">
|
||||||
|
{tag}
|
||||||
|
</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<div class="whereSubtitle">Where it is:</div>
|
<div class="subtitle">Where it is:</div>
|
||||||
<p class="addrContainer">
|
<p class="addrContainer">
|
||||||
{space.building_location}
|
{space.building_location}
|
||||||
</p>
|
</p>
|
||||||
@@ -87,7 +97,7 @@
|
|||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.whereSubtitle {
|
.subtitle {
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
@@ -98,4 +108,24 @@
|
|||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
padding: 0rem 1.4rem;
|
padding: 0rem 1.4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tagContainer {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.4rem;
|
||||||
|
padding: 1.4rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
background-color: #2e4653;
|
||||||
|
color: #eaffeb;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.2rem 0.6rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
3
supabase/migrations/20250605162005_add_tags.sql
Normal file
3
supabase/migrations/20250605162005_add_tags.sql
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
alter table "public"."study_spaces" add column "tags" text[] not null default ARRAY[]::text[];
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user