Merge branch 'master' into 'feat/filter-by-time'
# Conflicts: # src/lib/database.d.ts # src/routes/+page.svelte # src/routes/space/[id]/+page.svelte
This commit is contained in:
852
package-lock.json
generated
852
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,29 +5,50 @@
|
||||
onclick?: (event: MouseEvent) => void;
|
||||
disabled?: boolean;
|
||||
type?: "button" | "submit" | "reset";
|
||||
style?: "normal" | "red";
|
||||
formaction?: string;
|
||||
children?: Snippet;
|
||||
}
|
||||
const { children, ...rest }: Props = $props();
|
||||
interface LinkProps {
|
||||
href: string;
|
||||
type: "link";
|
||||
style?: "normal" | "red";
|
||||
children?: Snippet;
|
||||
}
|
||||
const { children, type, style = "normal", ...rest }: Props | LinkProps = $props();
|
||||
</script>
|
||||
|
||||
<button {...rest}>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
{#if type === "link"}
|
||||
<a {...rest} class="button {style}">
|
||||
{@render children?.()}
|
||||
</a>
|
||||
{:else}
|
||||
<button class="button {style}" {type} {...rest}>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
button {
|
||||
.button {
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
background: linear-gradient(-83deg, #3fb095, #49bd85);
|
||||
box-shadow: 0rem 0rem 0.5rem #182125;
|
||||
color: #eaffeb;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
}
|
||||
button:focus {
|
||||
.normal {
|
||||
background: linear-gradient(-83deg, #3fb095, #49bd85);
|
||||
}
|
||||
.red {
|
||||
background-color: #bd4949;
|
||||
}
|
||||
.button:focus {
|
||||
outline: 2px solid #007bff;
|
||||
}
|
||||
button:disabled {
|
||||
.button:disabled {
|
||||
background: linear-gradient(-18deg, #66697b, #4e4e5e);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
338
src/lib/components/Feedback.svelte
Normal file
338
src/lib/components/Feedback.svelte
Normal file
@@ -0,0 +1,338 @@
|
||||
<script lang="ts">
|
||||
import crossUrl from "$lib/assets/cross.svg";
|
||||
import type { Table } from "$lib";
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import type { Database } from "$lib/database.d.ts";
|
||||
import { availableStudySpaceTags, wifiTags, powerOutletTags, volumeTags } from "$lib";
|
||||
import { invalidate } from "$app/navigation";
|
||||
|
||||
type StudySpaceData = Omit<
|
||||
Table<"study_spaces">,
|
||||
"id" | "created_at" | "updated_at" | "building_location_old" | "building_location"
|
||||
> & {
|
||||
id?: string;
|
||||
building_location?: google.maps.places.PlaceResult;
|
||||
};
|
||||
interface Props {
|
||||
studySpaceData: StudySpaceData;
|
||||
supabase: SupabaseClient<Database>;
|
||||
hideFunc: () => void;
|
||||
}
|
||||
|
||||
const { studySpaceData, supabase, hideFunc }: Props = $props();
|
||||
let newStudySpaceData: StudySpaceData = $state({ ...studySpaceData });
|
||||
let uploading = $state(false);
|
||||
async function uploadFeedback() {
|
||||
const { error: feedbackUpload } = await supabase
|
||||
.from("study_spaces")
|
||||
.update({
|
||||
volume: newStudySpaceData.volume,
|
||||
wifi: newStudySpaceData.wifi,
|
||||
power: newStudySpaceData.power,
|
||||
tags: newStudySpaceData.tags
|
||||
})
|
||||
.eq("id", newStudySpaceData.id ?? "");
|
||||
invalidate("db:study_spaces");
|
||||
if (feedbackUpload) return alert(`Error submitting feedback: ${feedbackUpload.message}`);
|
||||
else alert("Feedback submitted successfully!");
|
||||
}
|
||||
|
||||
// Tag
|
||||
let tagFilter = $state("");
|
||||
let tagFilterElem = $state<HTMLInputElement>();
|
||||
let filteredTags = $derived(
|
||||
availableStudySpaceTags
|
||||
.filter((tag) => tag.toLowerCase().includes(tagFilter.toLowerCase()))
|
||||
.filter((tag) => !newStudySpaceData.tags.includes(tag))
|
||||
);
|
||||
let dropdownVisible = $state(false);
|
||||
|
||||
function deleteTag(tagName: string) {
|
||||
return () => {
|
||||
newStudySpaceData.tags = newStudySpaceData.tags.filter((tag) => tag !== tagName);
|
||||
};
|
||||
}
|
||||
|
||||
function addTag(tagName: string) {
|
||||
return () => {
|
||||
if (!newStudySpaceData.tags.includes(tagName)) {
|
||||
newStudySpaceData.tags.push(tagName);
|
||||
}
|
||||
tagFilter = "";
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="overlay">
|
||||
<form
|
||||
onsubmit={async (event) => {
|
||||
event.preventDefault();
|
||||
uploading = true;
|
||||
await uploadFeedback();
|
||||
uploading = false;
|
||||
hideFunc();
|
||||
}}
|
||||
class="feedbackContainer"
|
||||
>
|
||||
<h1 class="submitHeader">Submit Feedback</h1>
|
||||
|
||||
<div class="compulsoryTags">
|
||||
<div class="compulsoryContainer">
|
||||
<label for="volume">Sound level:</label>
|
||||
<select
|
||||
bind:value={newStudySpaceData.volume}
|
||||
name="volume"
|
||||
class="compulsoryTagSelect"
|
||||
>
|
||||
<option value="" disabled selected>How noisy is it?</option>
|
||||
{#each volumeTags as volumeTag (volumeTag)}
|
||||
<option value={volumeTag}>{volumeTag}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="compulsoryContainer">
|
||||
<label for="powerOutlets">Power outlets:</label>
|
||||
<select
|
||||
bind:value={newStudySpaceData.power}
|
||||
name="poweOutlets"
|
||||
class="compulsoryTagSelect"
|
||||
>
|
||||
<option value="" disabled selected>Power outlets?</option>
|
||||
{#each powerOutletTags as powerOutletTag (powerOutletTag)}
|
||||
<option value={powerOutletTag}>{powerOutletTag}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="compulsoryContainer">
|
||||
<label for="wifi">Wifi:</label>
|
||||
<select bind:value={newStudySpaceData.wifi} name="wifi" class="compulsoryTagSelect">
|
||||
<option value="" disabled selected>How's the wifi?</option>
|
||||
{#each wifiTags as wifiTag (wifiTag)}
|
||||
<option value={wifiTag}>{wifiTag}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="tags">Additional tags:</label>
|
||||
<div class="tagDisplay">
|
||||
{#each newStudySpaceData.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"
|
||||
bind:value={tagFilter}
|
||||
bind:this={tagFilterElem}
|
||||
onfocus={() => {
|
||||
dropdownVisible = true;
|
||||
}}
|
||||
onblur={() => {
|
||||
dropdownVisible = false;
|
||||
}}
|
||||
onkeypress={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
const tag = filteredTags[0];
|
||||
if (tag) addTag(tag)();
|
||||
}
|
||||
}}
|
||||
placeholder="Add tags..."
|
||||
/>
|
||||
{#if dropdownVisible}
|
||||
<div class="tagDropdown">
|
||||
{#each filteredTags as avaliableTag (avaliableTag)}
|
||||
<button
|
||||
class="avaliableTag"
|
||||
onclick={addTag(avaliableTag)}
|
||||
onmousedown={(e) => {
|
||||
// Keep input focused
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
{avaliableTag}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<button disabled={uploading} class="submit">Submit</button>
|
||||
<button type="button" class="exit" aria-label="exit" onclick={hideFunc}
|
||||
><img src={crossUrl} alt="exit" /></button
|
||||
>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.overlay {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: fixed;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: rgba(8, 15, 18, 0.9);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.feedbackContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 80%;
|
||||
gap: 0.5rem;
|
||||
padding: 1rem;
|
||||
background-color: #182125;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.1);
|
||||
color: #eaffeb;
|
||||
position: absolute;
|
||||
translate: 0 -3.5rem;
|
||||
border: 2px solid #eaffeb;
|
||||
}
|
||||
|
||||
.submitHeader {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.submit {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.5rem;
|
||||
border: none;
|
||||
background-color: #49bd85;
|
||||
color: #ffffff;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.exit {
|
||||
position: absolute;
|
||||
top: 0.1rem;
|
||||
right: 0.1rem;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.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;
|
||||
box-shadow: 1px 1px 0.5rem rgba(0, 0, 0, 0.5);
|
||||
border-radius: 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 0.8rem 0.4rem;
|
||||
}
|
||||
.avaliableTag:first-child {
|
||||
padding-top: 0.6rem;
|
||||
background-color: hsl(201, 26%, 60%);
|
||||
}
|
||||
.avaliableTag:last-child {
|
||||
padding-bottom: 0.6rem;
|
||||
}
|
||||
|
||||
.compulsoryTags {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
border-radius: 0.5rem;
|
||||
background-color: none;
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.compulsoryContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: left;
|
||||
justify-content: top;
|
||||
border-radius: 0.5rem;
|
||||
background-color: none;
|
||||
}
|
||||
|
||||
.compulsoryTagSelect {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.5rem;
|
||||
border: 2px solid #eaffeb;
|
||||
background: none;
|
||||
color: #eaffeb;
|
||||
font-size: 0.9rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.compulsoryTagSelect option {
|
||||
background-color: #2e4653;
|
||||
color: #eaffeb;
|
||||
}
|
||||
</style>
|
||||
@@ -5,12 +5,13 @@
|
||||
value?: string | null;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
type?: "text" | "password" | "email" | "number";
|
||||
}
|
||||
|
||||
let { inputElem = $bindable(), value = $bindable(), name, ...rest }: Props = $props();
|
||||
</script>
|
||||
|
||||
<input type="text" id={name} {name} bind:value bind:this={inputElem} {...rest} />
|
||||
<input id={name} {name} bind:value bind:this={inputElem} {...rest} />
|
||||
|
||||
<style>
|
||||
input {
|
||||
|
||||
24
src/lib/database.d.ts
vendored
24
src/lib/database.d.ts
vendored
@@ -140,6 +140,7 @@ export type Database = {
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
|
||||
study_space_hours: {
|
||||
Row: {
|
||||
id: string
|
||||
@@ -180,6 +181,28 @@ export type Database = {
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
|
||||
users: {
|
||||
Row: {
|
||||
created_at: string
|
||||
id: string
|
||||
is_admin: boolean
|
||||
updated_at: string
|
||||
}
|
||||
Insert: {
|
||||
created_at?: string
|
||||
id: string
|
||||
is_admin?: boolean
|
||||
updated_at?: string
|
||||
}
|
||||
Update: {
|
||||
created_at?: string
|
||||
id?: string
|
||||
is_admin?: boolean
|
||||
updated_at?: string
|
||||
}
|
||||
Relationships: []
|
||||
|
||||
}
|
||||
}
|
||||
Views: {
|
||||
@@ -310,4 +333,3 @@ export const Constants = {
|
||||
Enums: {},
|
||||
},
|
||||
} as const
|
||||
|
||||
|
||||
@@ -1,9 +1,29 @@
|
||||
import type { LayoutServerLoad } from "./$types";
|
||||
|
||||
export const load: LayoutServerLoad = async ({ locals: { safeGetSession }, cookies }) => {
|
||||
export const load: LayoutServerLoad = async ({
|
||||
locals: { safeGetSession, supabase },
|
||||
cookies,
|
||||
depends
|
||||
}) => {
|
||||
depends("supabase:auth");
|
||||
const { session } = await safeGetSession();
|
||||
let adminMode = false;
|
||||
if (session) {
|
||||
const { data: userData, error: userError } = await supabase
|
||||
.from("users")
|
||||
.select("*")
|
||||
.eq("id", session.user.id)
|
||||
.single();
|
||||
if (userError) {
|
||||
console.error("Failed to fetch user data:", userError);
|
||||
}
|
||||
if (userData?.is_admin) {
|
||||
adminMode = true;
|
||||
}
|
||||
}
|
||||
return {
|
||||
session,
|
||||
adminMode,
|
||||
cookies: cookies.getAll()
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,14 +2,22 @@
|
||||
import posthog from "posthog-js";
|
||||
import logoUrl from "$lib/assets/logo.svg";
|
||||
import { onMount } from "svelte";
|
||||
import { invalidate } from "$app/navigation";
|
||||
|
||||
const { children } = $props();
|
||||
let { data, children } = $props();
|
||||
let { session, supabase } = $derived(data);
|
||||
|
||||
onMount(() => {
|
||||
posthog.init("phc_hTnel2Q8GKo0TgIBnFWBueJW1ATmCG9tJOtETnQTUdY", {
|
||||
api_host: "https://eu.i.posthog.com",
|
||||
person_profiles: "always"
|
||||
});
|
||||
const { data } = supabase.auth.onAuthStateChange((_, newSession) => {
|
||||
if (newSession?.expires_at !== session?.expires_at) {
|
||||
invalidate("supabase:auth");
|
||||
}
|
||||
});
|
||||
return () => data.subscription.unsubscribe();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -40,5 +40,5 @@ export const load: LayoutLoad = async ({ data, depends, fetch }) => {
|
||||
data: { user }
|
||||
} = await supabase.auth.getUser();
|
||||
|
||||
return { session, supabase, user };
|
||||
return { session, supabase, user, adminMode: data.adminMode };
|
||||
};
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
import crossUrl from "$lib/assets/cross.svg";
|
||||
import Navbar from "$lib/components/Navbar.svelte";
|
||||
import { allTags, volumeTags, wifiTags, powerOutletTags } from "$lib";
|
||||
import Button from "$lib/components/Button.svelte";
|
||||
|
||||
const { data } = $props();
|
||||
const { studySpaces, supabase } = $derived(data);
|
||||
const { studySpaces, supabase, session, adminMode } = $derived(data);
|
||||
|
||||
let selectedTags = $state<string[]>([]);
|
||||
let tagFilter = $state("");
|
||||
@@ -109,13 +110,21 @@
|
||||
</script>
|
||||
|
||||
<Navbar>
|
||||
<a href="/space/new/edit">
|
||||
<img src={crossUrl} alt="new" class="new-space" />
|
||||
</a>
|
||||
{#if session}
|
||||
<a href="/space/new/edit">
|
||||
<img src={crossUrl} alt="new" class="new-space" />
|
||||
</a>
|
||||
{/if}
|
||||
</Navbar>
|
||||
|
||||
<main>
|
||||
<a href="/space/reports" class="checkReports">Check Reports</a>
|
||||
|
||||
{#if adminMode}
|
||||
<div class="checkReports">
|
||||
<Button href="/space/reports" type="link" style="red">Check Reports</Button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="time-filter-container">
|
||||
<label>
|
||||
Open from:
|
||||
@@ -126,6 +135,7 @@
|
||||
<input type="time" bind:value={closingFilter} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="tag-filter-container">
|
||||
<form>
|
||||
<div class="tagDisplay">
|
||||
@@ -195,6 +205,14 @@
|
||||
{/each}
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
{#if session}
|
||||
<Button onclick={() => supabase.auth.signOut()}>Signout</Button>
|
||||
{:else}
|
||||
<Button href="/auth" type="link">Login / Signup</Button>
|
||||
{/if}
|
||||
</footer>
|
||||
|
||||
<style>
|
||||
main {
|
||||
display: grid;
|
||||
@@ -207,6 +225,15 @@
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.new-space {
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
@@ -238,15 +265,14 @@
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
color: #eaffeb;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1.5rem;
|
||||
gap: 0.5rem;
|
||||
max-width: 32rem;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.tagDisplay {
|
||||
@@ -329,14 +355,9 @@
|
||||
}
|
||||
.checkReports {
|
||||
grid-column: 1 / -1;
|
||||
display: block;
|
||||
text-align: center;
|
||||
color: #ffeaea;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-size: 1.2rem;
|
||||
text-decoration: none;
|
||||
padding: 0.5rem;
|
||||
background-color: #bd4949;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 20rem) {
|
||||
|
||||
14
src/routes/auth/+layout.svelte
Normal file
14
src/routes/auth/+layout.svelte
Normal file
@@ -0,0 +1,14 @@
|
||||
<script lang="ts">
|
||||
import Navbar from "$lib/components/Navbar.svelte";
|
||||
import crossUrl from "$lib/assets/cross.svg";
|
||||
|
||||
const { children } = $props();
|
||||
</script>
|
||||
|
||||
<Navbar>
|
||||
<a href="/">
|
||||
<img src={crossUrl} alt="close" />
|
||||
</a>
|
||||
</Navbar>
|
||||
|
||||
{@render children?.()}
|
||||
30
src/routes/auth/+page.server.ts
Normal file
30
src/routes/auth/+page.server.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { redirect, error } from "@sveltejs/kit";
|
||||
|
||||
import type { Actions } from "./$types";
|
||||
|
||||
export const actions: Actions = {
|
||||
signup: async ({ request, locals: { supabase } }) => {
|
||||
const formData = await request.formData();
|
||||
const email = formData.get("email") as string;
|
||||
const password = formData.get("password") as string;
|
||||
|
||||
const { error: authError } = await supabase.auth.signUp({ email, password });
|
||||
if (authError) {
|
||||
error(400, "Failed to sign up: " + authError.message);
|
||||
} else {
|
||||
redirect(303, "/");
|
||||
}
|
||||
},
|
||||
login: async ({ request, locals: { supabase } }) => {
|
||||
const formData = await request.formData();
|
||||
const email = formData.get("email") as string;
|
||||
const password = formData.get("password") as string;
|
||||
|
||||
const { error: authError } = await supabase.auth.signInWithPassword({ email, password });
|
||||
if (authError) {
|
||||
error(400, "Failed to log in: " + authError.message);
|
||||
} else {
|
||||
redirect(303, "/");
|
||||
}
|
||||
}
|
||||
};
|
||||
36
src/routes/auth/+page.svelte
Normal file
36
src/routes/auth/+page.svelte
Normal file
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import Button from "$lib/components/Button.svelte";
|
||||
import Text from "$lib/components/inputs/Text.svelte";
|
||||
</script>
|
||||
|
||||
<form method="POST" action="?/login">
|
||||
<label for="email">Email</label>
|
||||
<Text type="email" name="email" placeholder="your@email.com" />
|
||||
|
||||
<label for="password">Password</label>
|
||||
<Text type="password" name="password" placeholder="*********" />
|
||||
|
||||
<div class="actions">
|
||||
<Button type="submit">Login</Button>
|
||||
<Button formaction="?/signup">Signup</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-width: 600px;
|
||||
margin: 1rem auto;
|
||||
}
|
||||
label {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.actions {
|
||||
display: grid;
|
||||
margin-top: 0.5rem;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,7 +1,8 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals: { supabase } }) => {
|
||||
export const load: PageServerLoad = async ({ depends, params, locals: { supabase } }) => {
|
||||
depends("db:study_spaces");
|
||||
const { data: space, error: err } = await supabase
|
||||
.from("study_spaces")
|
||||
.select("*, study_space_images(*), study_space_hours(*)")
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
import Carousel from "$lib/components/Carousel.svelte";
|
||||
import CompulsoryTags from "$lib/components/CompulsoryTags.svelte";
|
||||
import Report from "$lib/components/Report.svelte";
|
||||
import Feedback from "$lib/components/Feedback.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { gmapsLoader, daysOfWeek, formatTime } from "$lib";
|
||||
import Button from "$lib/components/Button.svelte";
|
||||
|
||||
const { data } = $props();
|
||||
const { space, supabase } = $derived(data);
|
||||
|
||||
let adminMode = $state(true);
|
||||
const { space, supabase, adminMode } = $derived(data);
|
||||
|
||||
const place = $derived(space.building_location as google.maps.places.PlaceResult);
|
||||
const imgUrls = $derived(
|
||||
@@ -25,10 +25,15 @@
|
||||
);
|
||||
|
||||
let isReportVisible = $state(false);
|
||||
function hideFunc() {
|
||||
function hideReport() {
|
||||
isReportVisible = false;
|
||||
}
|
||||
|
||||
let isFeedbackPromptVisible = $state(false);
|
||||
function hideFeedbackPrompt() {
|
||||
isFeedbackPromptVisible = false;
|
||||
}
|
||||
|
||||
let mapElem = $state<HTMLDivElement>();
|
||||
onMount(async () => {
|
||||
if (!mapElem) return console.error("Map element not found");
|
||||
@@ -60,7 +65,17 @@
|
||||
</a>
|
||||
</Navbar>
|
||||
|
||||
{#if isReportVisible}<Report {data} studySpaceId={space.id} {hideFunc} />
|
||||
{#if isReportVisible}<Report {data} studySpaceId={space.id} hideFunc={hideReport} />
|
||||
{/if}
|
||||
{#if isFeedbackPromptVisible}
|
||||
<Feedback
|
||||
studySpaceData={{
|
||||
...space,
|
||||
building_location: place
|
||||
}}
|
||||
{supabase}
|
||||
hideFunc={hideFeedbackPrompt}
|
||||
/>
|
||||
{/if}
|
||||
<main>
|
||||
<Carousel urls={imgUrls} />
|
||||
@@ -110,17 +125,24 @@
|
||||
{/each}
|
||||
</p>
|
||||
<div class="addrMap" bind:this={mapElem}></div>
|
||||
{#if adminMode}
|
||||
<a href={`/space/${space.id}/edit`} class="editButton">Edit</a>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
class="reportButton"
|
||||
onclick={() => {
|
||||
isReportVisible = true;
|
||||
}}>Report</button
|
||||
>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="feedbackButton"
|
||||
onclick={() => {
|
||||
isFeedbackPromptVisible = true;
|
||||
}}
|
||||
>
|
||||
Help categorise this space
|
||||
</button>
|
||||
|
||||
<div class="actions">
|
||||
{#if adminMode}
|
||||
<Button href="/space/{space.id}/edit" type="link">Edit</Button>
|
||||
{:else}
|
||||
<Button onclick={() => (isReportVisible = true)} style="red">Report</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
@@ -147,6 +169,7 @@
|
||||
border: none;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.nameContainer {
|
||||
z-index: 10;
|
||||
display: block;
|
||||
@@ -218,21 +241,9 @@
|
||||
border-radius: 0.5rem;
|
||||
border: 2px solid #eaffeb;
|
||||
}
|
||||
.reportButton {
|
||||
.feedbackButton {
|
||||
width: 100%;
|
||||
padding: 0.4rem;
|
||||
border-radius: 0.5rem;
|
||||
border: none;
|
||||
background-color: #bd4949;
|
||||
color: #ffffff;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.editButton {
|
||||
width: 100%;
|
||||
padding: 0.4rem;
|
||||
padding: 0.7rem;
|
||||
border-radius: 0.5rem;
|
||||
border: none;
|
||||
background-color: #49bd85;
|
||||
@@ -240,7 +251,6 @@
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
margin-top: 1rem;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -262,5 +272,10 @@
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
color: #eaffeb;
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-top: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
28
supabase/migrations/20250612104310_users-admin.sql
Normal file
28
supabase/migrations/20250612104310_users-admin.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE users (
|
||||
id uuid PRIMARY KEY REFERENCES auth.users ON DELETE CASCADE,
|
||||
is_admin boolean NOT NULL DEFAULT false,
|
||||
created_at timestamp with time zone NOT NULL DEFAULT now(),
|
||||
updated_at timestamp with time zone NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TRIGGER users_handle_updated_at
|
||||
AFTER UPDATE ON users
|
||||
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||
|
||||
-- Auto-create users when auth.users are created
|
||||
CREATE FUNCTION handle_new_user()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = ''
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO public.users (id, contact_email)
|
||||
VALUES (NEW.id, NEW.email);
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE TRIGGER users_handle_new_user
|
||||
AFTER INSERT ON auth.users
|
||||
FOR EACH ROW EXECUTE FUNCTION handle_new_user();
|
||||
28
supabase/schemas/0001_users.sql
Normal file
28
supabase/schemas/0001_users.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE users (
|
||||
id uuid PRIMARY KEY REFERENCES auth.users ON DELETE CASCADE,
|
||||
is_admin boolean NOT NULL DEFAULT false,
|
||||
created_at timestamp with time zone NOT NULL DEFAULT now(),
|
||||
updated_at timestamp with time zone NOT NULL DEFAULT now(),
|
||||
);
|
||||
|
||||
CREATE TRIGGER users_handle_updated_at
|
||||
AFTER UPDATE ON users
|
||||
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||
|
||||
-- Auto-create users when auth.users are created
|
||||
CREATE FUNCTION handle_new_user()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = ''
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO public.users (id, contact_email)
|
||||
VALUES (NEW.id, NEW.email);
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE TRIGGER users_handle_new_user
|
||||
AFTER INSERT ON auth.users
|
||||
FOR EACH ROW EXECUTE FUNCTION handle_new_user();
|
||||
Reference in New Issue
Block a user