Merge branch 'feat/reports' into 'master'
feat: reports See merge request gk1623/drp-48!8 Co-authored-by: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com>
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
background-color: #eaffeb;
|
background-color: #eaffeb;
|
||||||
color: #2e4653;
|
color: #2e4653;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0.2rem 0.6rem;
|
padding: 0.2rem 0.2rem;
|
||||||
}
|
}
|
||||||
.compulsoryTagYellow {
|
.compulsoryTagYellow {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
background-color: #ffffd4;
|
background-color: #ffffd4;
|
||||||
color: #534b2e;
|
color: #534b2e;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0.2rem 0.6rem;
|
padding: 0.2rem 0.2rem;
|
||||||
}
|
}
|
||||||
.compulsoryTagRed {
|
.compulsoryTagRed {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -57,6 +57,6 @@
|
|||||||
background-color: #ffcece;
|
background-color: #ffcece;
|
||||||
color: #532e2e;
|
color: #532e2e;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0.2rem 0.6rem;
|
padding: 0.2rem 0.2rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
137
src/lib/components/Report.svelte
Normal file
137
src/lib/components/Report.svelte
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { reportTypes } from "$lib";
|
||||||
|
import crossUrl from "$lib/assets/cross.svg";
|
||||||
|
import Textarea from "./inputs/Textarea.svelte";
|
||||||
|
import type { Table } from "$lib";
|
||||||
|
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||||
|
import type { Database } from "$lib/database.d.ts";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
data: { supabase: SupabaseClient<Database> };
|
||||||
|
studySpaceId: string;
|
||||||
|
hideFunc: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data, studySpaceId, hideFunc }: Props = $props();
|
||||||
|
const { supabase } = $derived(data);
|
||||||
|
|
||||||
|
let uploading = $state(false);
|
||||||
|
let reportData = $state<Omit<Table<"reports">, "id" | "created_at" | "updated_at">>({
|
||||||
|
study_space_id: studySpaceId,
|
||||||
|
type: "",
|
||||||
|
content: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
async function uploadReport() {
|
||||||
|
const { error: reportUploadError } = await supabase
|
||||||
|
.from("reports")
|
||||||
|
.insert(reportData)
|
||||||
|
.select()
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (reportUploadError)
|
||||||
|
return alert(`Error submitting report: ${reportUploadError.message}`);
|
||||||
|
else alert("Report submitted successfully!");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="overlay">
|
||||||
|
<form
|
||||||
|
onsubmit={async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
uploading = true;
|
||||||
|
await uploadReport();
|
||||||
|
uploading = false;
|
||||||
|
hideFunc();
|
||||||
|
}}
|
||||||
|
class="reportContainer"
|
||||||
|
>
|
||||||
|
<h1>Submit a Report</h1>
|
||||||
|
<p>What's the reason?</p>
|
||||||
|
<select name="reportType" class="reportType" required bind:value={reportData.type}>
|
||||||
|
<option value="" disabled selected>Report type</option>
|
||||||
|
{#each reportTypes as reportType (reportType)}
|
||||||
|
<option value={reportType}>{reportType}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
<label for="description">Briefly describe the problem:</label>
|
||||||
|
<Textarea
|
||||||
|
name="description"
|
||||||
|
placeholder="Image is inappropriate..."
|
||||||
|
rows={2}
|
||||||
|
bind:value={reportData.content}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
disabled={!reportData.type || reportData.content?.length === 0 || 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reportContainer {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reportType {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reportType option {
|
||||||
|
background-color: #2e4653;
|
||||||
|
color: #eaffeb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
.compulsoryContainer {
|
.compulsoryContainer {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: repeat(3, 1fr);
|
||||||
gap: 0.5rem;
|
gap: 0.4rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
35
src/lib/database.d.ts
vendored
35
src/lib/database.d.ts
vendored
@@ -34,6 +34,41 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
public: {
|
public: {
|
||||||
Tables: {
|
Tables: {
|
||||||
|
reports: {
|
||||||
|
Row: {
|
||||||
|
content: string | null
|
||||||
|
created_at: string | null
|
||||||
|
id: string
|
||||||
|
study_space_id: string | null
|
||||||
|
type: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
content?: string | null
|
||||||
|
created_at?: string | null
|
||||||
|
id?: string
|
||||||
|
study_space_id?: string | null
|
||||||
|
type: string
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
content?: string | null
|
||||||
|
created_at?: string | null
|
||||||
|
id?: string
|
||||||
|
study_space_id?: string | null
|
||||||
|
type?: string
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "reports_study_space_id_fkey"
|
||||||
|
columns: ["study_space_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "study_spaces"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
study_space_images: {
|
study_space_images: {
|
||||||
Row: {
|
Row: {
|
||||||
created_at: string | null
|
created_at: string | null
|
||||||
|
|||||||
@@ -24,3 +24,9 @@ export const availableStudySpaceTags = [
|
|||||||
export const volumeTags = ["Silent", "Quiet", "Some Noise", "Loud"];
|
export const volumeTags = ["Silent", "Quiet", "Some Noise", "Loud"];
|
||||||
export const wifiTags = ["Good WiFi", "Moderate WiFi", "Bad WiFi", "No WiFi"];
|
export const wifiTags = ["Good WiFi", "Moderate WiFi", "Bad WiFi", "No WiFi"];
|
||||||
export const powerOutletTags = ["Many Outlets", "Some Outlets", "No Outlets"];
|
export const powerOutletTags = ["Many Outlets", "Some Outlets", "No Outlets"];
|
||||||
|
export const reportTypes = [
|
||||||
|
"Inappropriate content",
|
||||||
|
"Duplicate content",
|
||||||
|
"Incorrect content",
|
||||||
|
"Other"
|
||||||
|
];
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import placeholder from "$lib/assets/study_space.png";
|
import placeholder from "$lib/assets/study_space.png";
|
||||||
import Carousel from "$lib/components/Carousel.svelte";
|
import Carousel from "$lib/components/Carousel.svelte";
|
||||||
import CompulsoryTags from "$lib/components/CompulsoryTags.svelte";
|
import CompulsoryTags from "$lib/components/CompulsoryTags.svelte";
|
||||||
|
import Report from "$lib/components/Report.svelte";
|
||||||
|
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
const { space, supabase } = $derived(data);
|
const { space, supabase } = $derived(data);
|
||||||
@@ -17,6 +18,11 @@
|
|||||||
.publicUrl
|
.publicUrl
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let isReportVisible = $state(false);
|
||||||
|
function hideFunc() {
|
||||||
|
isReportVisible = false;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Navbar>
|
<Navbar>
|
||||||
@@ -25,6 +31,8 @@
|
|||||||
</a>
|
</a>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
||||||
|
{#if isReportVisible}<Report {data} studySpaceId={space.id} {hideFunc} />
|
||||||
|
{/if}
|
||||||
<main>
|
<main>
|
||||||
<Carousel urls={imgUrls} />
|
<Carousel urls={imgUrls} />
|
||||||
<div class="nameContainer">
|
<div class="nameContainer">
|
||||||
@@ -51,6 +59,14 @@
|
|||||||
<p class="addrContainer">
|
<p class="addrContainer">
|
||||||
{space.building_location}
|
{space.building_location}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="reportButton"
|
||||||
|
onclick={() => {
|
||||||
|
isReportVisible = true;
|
||||||
|
}}>Report</button
|
||||||
|
>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -141,4 +157,15 @@
|
|||||||
font-size: 1.3rem;
|
font-size: 1.3rem;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.reportButton {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.4rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
border: none;
|
||||||
|
background-color: #bd4949;
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ alter table "public"."study_spaces" add column "power" text;
|
|||||||
alter table "public"."study_spaces" add column "volume" text;
|
alter table "public"."study_spaces" add column "volume" text;
|
||||||
alter table "public"."study_spaces" add column "wifi" text;
|
alter table "public"."study_spaces" add column "wifi" text;
|
||||||
|
|
||||||
update "public"."study_spaces" set "power" = 'Many' where "power" is null;
|
update "public"."study_spaces" set "power" = 'Many Outlets' where "power" is null;
|
||||||
update "public"."study_spaces" set "volume" = 'Quiet' where "volume" is null;
|
update "public"."study_spaces" set "volume" = 'Quiet' where "volume" is null;
|
||||||
update "public"."study_spaces" set "wifi" = 'Good' where "wifi" is null;
|
update "public"."study_spaces" set "wifi" = 'Good WiFi' where "wifi" is null;
|
||||||
|
|
||||||
alter table "public"."study_spaces" alter column "power" set not null;
|
alter table "public"."study_spaces" alter column "power" set not null;
|
||||||
alter table "public"."study_spaces" alter column "volume" set not null;
|
alter table "public"."study_spaces" alter column "volume" set not null;
|
||||||
|
|||||||
12
supabase/migrations/20250610163930_add_report_table.sql
Normal file
12
supabase/migrations/20250610163930_add_report_table.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE reports (
|
||||||
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
study_space_id uuid REFERENCES study_spaces(id) ON DELETE CASCADE,
|
||||||
|
created_at timestamp with time zone DEFAULT now(),
|
||||||
|
updated_at timestamp with time zone DEFAULT now(),
|
||||||
|
type text NOT NULL,
|
||||||
|
content text
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TRIGGER reports_updated_at
|
||||||
|
AFTER UPDATE ON reports
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||||
@@ -28,6 +28,14 @@ CREATE TABLE study_space_images (
|
|||||||
PRIMARY KEY (study_space_id, image_path)
|
PRIMARY KEY (study_space_id, image_path)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE reports (
|
||||||
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
study_space_id uuid REFERENCES study_spaces(id) ON DELETE CASCADE,
|
||||||
|
created_at timestamp with time zone DEFAULT now(),
|
||||||
|
updated_at timestamp with time zone DEFAULT now(),
|
||||||
|
type text NOT NULL,
|
||||||
|
content text
|
||||||
|
);
|
||||||
|
|
||||||
-- Triggers
|
-- Triggers
|
||||||
CREATE TRIGGER study_spaces_updated_at
|
CREATE TRIGGER study_spaces_updated_at
|
||||||
@@ -37,3 +45,7 @@ FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
|||||||
CREATE TRIGGER study_space_images_updated_at
|
CREATE TRIGGER study_space_images_updated_at
|
||||||
AFTER UPDATE ON study_space_images
|
AFTER UPDATE ON study_space_images
|
||||||
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER reports_updated_at
|
||||||
|
AFTER UPDATE ON reports
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||||
|
|||||||
Reference in New Issue
Block a user