merge: merge feat/filter-by-time into master #46
40
src/lib/components/OpeningTimes.svelte
Normal file
40
src/lib/components/OpeningTimes.svelte
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Table } from "$lib";
|
||||||
|
import { formatTime } from "$lib";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
hours: Table<"study_space_hours">[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructure hours with a safe default to avoid undefined
|
||||||
|
const { hours }: Props = $props();
|
||||||
|
|
||||||
|
// Determine today's index (0 = Sunday, 6 = Saturday)
|
||||||
|
const todayIndex = new Date().getDay();
|
||||||
|
|
||||||
|
// Find the hours entry matching today
|
||||||
|
const todayHours = hours.find((h) => h.day_of_week === todayIndex);
|
||||||
|
|
||||||
|
// Compute the display string for opening times
|
||||||
|
let openingDisplay = $state("");
|
||||||
|
if (todayHours) {
|
||||||
|
openingDisplay = todayHours.is_24_7
|
||||||
|
? "Open 24/7"
|
||||||
|
: `${formatTime(todayHours.opens_at)} - ${formatTime(todayHours.closes_at)}`;
|
||||||
|
} else {
|
||||||
|
openingDisplay = "Closed";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="opening-times">
|
||||||
|
<strong>Today's Opening Times:</strong>
|
||||||
|
{openingDisplay}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.opening-times {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #eaffeb;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CompulsoryTags from "./CompulsoryTags.svelte";
|
import CompulsoryTags from "./CompulsoryTags.svelte";
|
||||||
|
import OpeningTimes from "./OpeningTimes.svelte";
|
||||||
import type { Table } from "$lib";
|
import type { Table } from "$lib";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
space: Table<"study_spaces">;
|
space: Table<"study_spaces">;
|
||||||
|
hours: Table<"study_space_hours">[];
|
||||||
alt: string;
|
alt: string;
|
||||||
imgSrc: string;
|
imgSrc: string;
|
||||||
href?: string;
|
href?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { space, alt, imgSrc, href }: Props = $props();
|
const { space, hours, alt, imgSrc, href }: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a class="card" {href}>
|
<a class="card" {href}>
|
||||||
@@ -24,6 +26,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
<div class="openingTimesContainer"><OpeningTimes {hours} /></div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|||||||
43
src/lib/database.d.ts
vendored
43
src/lib/database.d.ts
vendored
@@ -140,6 +140,48 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
study_space_hours: {
|
||||||
|
Row: {
|
||||||
|
id: string
|
||||||
|
study_space_id: string
|
||||||
|
day_of_week: number
|
||||||
|
opens_at: string
|
||||||
|
closes_at: string
|
||||||
|
is_24_7: boolean
|
||||||
|
created_at: string | null
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
id?: string
|
||||||
|
study_space_id: string
|
||||||
|
day_of_week: number
|
||||||
|
opens_at: string
|
||||||
|
closes_at: string
|
||||||
|
is_24_7: boolean
|
||||||
|
created_at?: string | null
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
id?: string
|
||||||
|
study_space_id?: string
|
||||||
|
day_of_week?: number
|
||||||
|
opens_at?: string
|
||||||
|
closes_at?: string
|
||||||
|
is_24_7?: boolean
|
||||||
|
created_at?: string | null
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "study_space_hours_study_space_id_fkey"
|
||||||
|
columns: ["study_space_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "study_spaces"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
users: {
|
users: {
|
||||||
Row: {
|
Row: {
|
||||||
created_at: string
|
created_at: string
|
||||||
@@ -160,6 +202,7 @@ export type Database = {
|
|||||||
updated_at?: string
|
updated_at?: string
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Views: {
|
Views: {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export type Enum<T extends keyof Database["public"]["Enums"]> = Database["public
|
|||||||
export const availableStudySpaceTags = [
|
export const availableStudySpaceTags = [
|
||||||
"Crowded",
|
"Crowded",
|
||||||
"Group study",
|
"Group study",
|
||||||
"24/7",
|
|
||||||
"Food allowed",
|
"Food allowed",
|
||||||
"No food allowed",
|
"No food allowed",
|
||||||
"Well lit",
|
"Well lit",
|
||||||
@@ -43,3 +42,20 @@ export async function gmapsLoader() {
|
|||||||
libraries: ["places"]
|
libraries: ["places"]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatTime(time: string) {
|
||||||
|
const [h, m] = time.split(":").map(Number);
|
||||||
|
const date = new Date();
|
||||||
|
date.setHours(h, m);
|
||||||
|
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
||||||
|
}
|
||||||
|
|
||||||
|
export const daysOfWeek = [
|
||||||
|
"Sunday",
|
||||||
|
"Monday",
|
||||||
|
"Tuesday",
|
||||||
|
"Wednesday",
|
||||||
|
"Thursday",
|
||||||
|
"Friday",
|
||||||
|
"Saturday"
|
||||||
|
];
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export const load: PageServerLoad = async ({ depends, locals: { supabase } }) =>
|
|||||||
depends("db:study_spaces");
|
depends("db:study_spaces");
|
||||||
const { data: studySpaces, error: err } = await supabase
|
const { data: studySpaces, error: err } = await supabase
|
||||||
.from("study_spaces")
|
.from("study_spaces")
|
||||||
.select("*, study_space_images(*)");
|
.select("*, study_space_images(*), study_space_hours(*)");
|
||||||
if (err) error(500, "Failed to load study spaces");
|
if (err) error(500, "Failed to load study spaces");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
let selectedTags = $state<string[]>([]);
|
let selectedTags = $state<string[]>([]);
|
||||||
let tagFilter = $state("");
|
let tagFilter = $state("");
|
||||||
|
let openingFilter = $state("");
|
||||||
|
let closingFilter = $state("");
|
||||||
let tagFilterElem = $state<HTMLInputElement>();
|
let tagFilterElem = $state<HTMLInputElement>();
|
||||||
|
|
||||||
function categorySelected(category: string[]) {
|
function categorySelected(category: string[]) {
|
||||||
@@ -33,19 +35,60 @@
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Convert "HH:MM" or "HH:MM:SS" to minutes since midnight
|
||||||
|
function toMinutes(timeStr: string): number {
|
||||||
|
const [h, m] = timeStr.slice(0, 5).split(":").map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine tag and time filtering
|
||||||
let filteredStudySpaces = $derived(
|
let filteredStudySpaces = $derived(
|
||||||
selectedTags.length === 0
|
studySpaces
|
||||||
? studySpaces
|
// tag filtering
|
||||||
: studySpaces.filter((space) => {
|
.filter((space) => {
|
||||||
|
if (selectedTags.length === 0) return true;
|
||||||
const allTags = [
|
const allTags = [
|
||||||
...(space.tags || []),
|
...(space.tags || []),
|
||||||
space.volume,
|
space.volume,
|
||||||
space.wifi,
|
space.wifi,
|
||||||
space.power
|
space.power
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
return selectedTags.every((tag) => allTags.includes(tag));
|
return selectedTags.every((tag) => allTags.includes(tag));
|
||||||
})
|
})
|
||||||
|
// opening time filter
|
||||||
|
.filter((space) => {
|
||||||
|
if (!openingFilter) return true;
|
||||||
|
const entry = space.study_space_hours?.find(
|
||||||
|
(h) => h.day_of_week === new Date().getDay()
|
||||||
|
);
|
||||||
|
if (!entry) return false;
|
||||||
|
if (entry.is_24_7) return true;
|
||||||
|
const openMin = toMinutes(entry.opens_at);
|
||||||
|
let closeMin = toMinutes(entry.closes_at);
|
||||||
|
// Treat midnight as end of day and handle overnight spans
|
||||||
|
if (closeMin === 0) closeMin = 24 * 60;
|
||||||
|
if (closeMin <= openMin) closeMin += 24 * 60;
|
||||||
|
const filterMin = toMinutes(openingFilter);
|
||||||
|
// Include spaces open at the filter time
|
||||||
|
return filterMin >= openMin && filterMin < closeMin;
|
||||||
|
})
|
||||||
|
// closing time filter
|
||||||
|
.filter((space) => {
|
||||||
|
if (!closingFilter) return true;
|
||||||
|
const entry = space.study_space_hours?.find(
|
||||||
|
(h) => h.day_of_week === new Date().getDay()
|
||||||
|
);
|
||||||
|
if (!entry) return false;
|
||||||
|
if (entry.is_24_7) return true;
|
||||||
|
const openMin = toMinutes(entry.opens_at);
|
||||||
|
let closeMin = toMinutes(entry.closes_at);
|
||||||
|
if (closeMin === 0) closeMin = 24 * 60;
|
||||||
|
if (closeMin <= openMin) closeMin += 24 * 60;
|
||||||
|
const filterMin =
|
||||||
|
toMinutes(closingFilter) === 0 ? 24 * 60 : toMinutes(closingFilter);
|
||||||
|
// Include spaces still open at the filter time
|
||||||
|
return filterMin > openMin && filterMin <= closeMin;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let dropdownVisible = $state(false);
|
let dropdownVisible = $state(false);
|
||||||
@@ -75,11 +118,24 @@
|
|||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
{#if adminMode}
|
{#if adminMode}
|
||||||
<div class="checkReports">
|
<div class="checkReports">
|
||||||
<Button href="/space/reports" type="link" style="red">Check Reports</Button>
|
<Button href="/space/reports" type="link" style="red">Check Reports</Button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<div class="time-filter-container">
|
||||||
|
<label>
|
||||||
|
Open from:
|
||||||
|
<input type="time" bind:value={openingFilter} />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Open until:
|
||||||
|
<input type="time" bind:value={closingFilter} />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="tag-filter-container">
|
<div class="tag-filter-container">
|
||||||
<form>
|
<form>
|
||||||
<div class="tagDisplay">
|
<div class="tagDisplay">
|
||||||
@@ -144,6 +200,7 @@
|
|||||||
href="/space/{studySpace.id}"
|
href="/space/{studySpace.id}"
|
||||||
imgSrc={imgUrl}
|
imgSrc={imgUrl}
|
||||||
space={studySpace}
|
space={studySpace}
|
||||||
|
hours={studySpace.study_space_hours}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</main>
|
</main>
|
||||||
@@ -185,6 +242,29 @@
|
|||||||
grid-column: 1 / -1;
|
grid-column: 1 / -1;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-filter-container {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
.time-filter-container label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #eaffeb;
|
||||||
|
}
|
||||||
|
.time-filter-container input[type="time"] {
|
||||||
|
background: none;
|
||||||
|
border: 2px solid #eaffeb;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
color: #eaffeb;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export const load: PageServerLoad = async ({ depends, params, locals: { supabase
|
|||||||
depends("db:study_spaces");
|
depends("db:study_spaces");
|
||||||
const { data: space, error: err } = await supabase
|
const { data: space, error: err } = await supabase
|
||||||
.from("study_spaces")
|
.from("study_spaces")
|
||||||
.select("*, study_space_images(*)")
|
.select("*, study_space_images(*), study_space_hours(*)")
|
||||||
.eq("id", params.id)
|
.eq("id", params.id)
|
||||||
.single();
|
.single();
|
||||||
if (err) error(500, "Failed to load study space");
|
if (err) error(500, "Failed to load study space");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import Report from "$lib/components/Report.svelte";
|
import Report from "$lib/components/Report.svelte";
|
||||||
import Feedback from "$lib/components/Feedback.svelte";
|
import Feedback from "$lib/components/Feedback.svelte";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { gmapsLoader } from "$lib";
|
import { gmapsLoader, daysOfWeek, formatTime } from "$lib";
|
||||||
import Button from "$lib/components/Button.svelte";
|
import Button from "$lib/components/Button.svelte";
|
||||||
|
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
@@ -50,6 +50,13 @@
|
|||||||
map
|
map
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const hoursByDay = $derived(new Map(space.study_space_hours.map((h) => [h.day_of_week, h])));
|
||||||
|
|
||||||
|
const openingEntries = daysOfWeek.map((day, idx) => ({
|
||||||
|
day,
|
||||||
|
entry: hoursByDay.get(idx)
|
||||||
|
}));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Navbar>
|
<Navbar>
|
||||||
@@ -92,6 +99,22 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<hr />
|
<hr />
|
||||||
|
<div class="subtitle">Opening Times:</div>
|
||||||
|
{#each openingEntries as { day, entry } (entry)}
|
||||||
|
<div class="opening-entry">
|
||||||
|
<span class="day">{day}:</span>
|
||||||
|
<span class="times">
|
||||||
|
{#if entry}
|
||||||
|
{entry.is_24_7
|
||||||
|
? "Open All Day"
|
||||||
|
: `${formatTime(entry.opens_at)} – ${formatTime(entry.closes_at)}`}
|
||||||
|
{:else}
|
||||||
|
Closed
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
|
||||||
<div class="subtitle">Where it is:</div>
|
<div class="subtitle">Where it is:</div>
|
||||||
<p class="addrContainer">
|
<p class="addrContainer">
|
||||||
{#if place.name}
|
{#if place.name}
|
||||||
@@ -230,6 +253,26 @@
|
|||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.opening-entry {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto 1fr;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.5rem 1.4rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.opening-entry .day {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #ffffff;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.opening-entry .times {
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
color: #eaffeb;
|
||||||
|
|
||||||
.actions {
|
.actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ type StudySpaceData = Omit<
|
|||||||
> & {
|
> & {
|
||||||
id?: string;
|
id?: string;
|
||||||
building_location?: google.maps.places.PlaceResult;
|
building_location?: google.maps.places.PlaceResult;
|
||||||
|
opening_times?: {
|
||||||
|
day_of_week: number;
|
||||||
|
opens_at: string;
|
||||||
|
closes_at: string;
|
||||||
|
is_24_7: boolean;
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, locals: { supabase } }) => {
|
export const load: PageServerLoad = async ({ params, locals: { supabase } }) => {
|
||||||
@@ -34,6 +40,13 @@ export const load: PageServerLoad = async ({ params, locals: { supabase } }) =>
|
|||||||
const studySpaceData = space as StudySpaceData & Partial<typeof space>;
|
const studySpaceData = space as StudySpaceData & Partial<typeof space>;
|
||||||
|
|
||||||
const images = studySpaceData.study_space_images || [];
|
const images = studySpaceData.study_space_images || [];
|
||||||
|
const { data: hours, error: hoursErr } = await supabase
|
||||||
|
.from("study_space_hours")
|
||||||
|
.select("day_of_week, opens_at, closes_at, is_24_7")
|
||||||
|
.eq("study_space_id", params.id)
|
||||||
|
.order("day_of_week", { ascending: true });
|
||||||
|
if (hoursErr) error(500, "Failed to load opening times");
|
||||||
|
studySpaceData.opening_times = hours;
|
||||||
|
|
||||||
delete studySpaceData.created_at;
|
delete studySpaceData.created_at;
|
||||||
delete studySpaceData.updated_at;
|
delete studySpaceData.updated_at;
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
wifiTags,
|
wifiTags,
|
||||||
powerOutletTags,
|
powerOutletTags,
|
||||||
volumeTags,
|
volumeTags,
|
||||||
gmapsLoader
|
gmapsLoader,
|
||||||
|
daysOfWeek
|
||||||
} from "$lib";
|
} from "$lib";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import type { Json } from "$lib/database.js";
|
import type { Json } from "$lib/database.js";
|
||||||
@@ -20,10 +21,25 @@
|
|||||||
const { supabase } = $derived(data);
|
const { supabase } = $derived(data);
|
||||||
|
|
||||||
const { space, images } = $derived(data);
|
const { space, images } = $derived(data);
|
||||||
const studySpaceData = $derived({
|
const studySpaceData = $state({
|
||||||
|
opening_times: daysOfWeek.map((_, index) => ({
|
||||||
|
day_of_week: index,
|
||||||
|
opens_at: "",
|
||||||
|
closes_at: "",
|
||||||
|
is_24_7: false
|
||||||
|
})),
|
||||||
...space
|
...space
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!space) return;
|
||||||
|
const { opening_times, ...rest } = space;
|
||||||
|
Object.assign(studySpaceData, rest);
|
||||||
|
if (opening_times) {
|
||||||
|
studySpaceData.opening_times = opening_times;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let scrollPosition = $state(0);
|
let scrollPosition = $state(0);
|
||||||
const existingImages = $derived(
|
const existingImages = $derived(
|
||||||
Promise.all(
|
Promise.all(
|
||||||
@@ -46,11 +62,13 @@
|
|||||||
if (!spaceImgs || spaceImgs.length < 1) return alert("Please select an image file.");
|
if (!spaceImgs || spaceImgs.length < 1) return alert("Please select an image file.");
|
||||||
if (!studySpaceData.building_location) return alert("Please select a building location.");
|
if (!studySpaceData.building_location) return alert("Please select a building location.");
|
||||||
|
|
||||||
|
const { opening_times, ...spacePayload } = studySpaceData;
|
||||||
|
|
||||||
const { data: studySpaceInsert, error: studySpaceError } = await supabase
|
const { data: studySpaceInsert, error: studySpaceError } = await supabase
|
||||||
.from("study_spaces")
|
.from("study_spaces")
|
||||||
.upsert(
|
.upsert(
|
||||||
{
|
{
|
||||||
...studySpaceData,
|
...spacePayload,
|
||||||
building_location: studySpaceData.building_location as Json
|
building_location: studySpaceData.building_location as Json
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -102,6 +120,23 @@
|
|||||||
.select();
|
.select();
|
||||||
if (imageInsertError) return alert(`Error creating image: ${imageInsertError.message}`);
|
if (imageInsertError) return alert(`Error creating image: ${imageInsertError.message}`);
|
||||||
|
|
||||||
|
const { error: deleteErr } = await supabase
|
||||||
|
.from("study_space_hours")
|
||||||
|
.delete()
|
||||||
|
.eq("study_space_id", studySpaceInsert.id);
|
||||||
|
if (deleteErr) return alert(`Error clearing old hours: ${deleteErr.message}`);
|
||||||
|
|
||||||
|
const { error: hoursErr } = await supabase.from("study_space_hours").insert(
|
||||||
|
opening_times.map((h) => ({
|
||||||
|
study_space_id: studySpaceInsert.id,
|
||||||
|
day_of_week: h.day_of_week,
|
||||||
|
opens_at: h.opens_at,
|
||||||
|
closes_at: h.closes_at,
|
||||||
|
is_24_7: h.is_24_7
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
if (hoursErr) return alert(`Error saving opening times: ${hoursErr.message}`);
|
||||||
|
|
||||||
alert("Thank you for your contribution!");
|
alert("Thank you for your contribution!");
|
||||||
// Redirect to the new study space page
|
// Redirect to the new study space page
|
||||||
await goto(`/space/${studySpaceInsert.id}`, {
|
await goto(`/space/${studySpaceInsert.id}`, {
|
||||||
@@ -161,6 +196,20 @@
|
|||||||
});
|
});
|
||||||
spaceImgs = dt.files;
|
spaceImgs = dt.files;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --- Helper functions for opening times ---
|
||||||
|
function toggle247(index: number) {
|
||||||
|
const ot = studySpaceData.opening_times[index];
|
||||||
|
if (ot.is_24_7) {
|
||||||
|
ot.opens_at = "00:00";
|
||||||
|
ot.closes_at = "00:00";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTimes(index: number) {
|
||||||
|
const ot = studySpaceData.opening_times[index];
|
||||||
|
ot.is_24_7 = ot.opens_at === "00:00" && ot.closes_at === "00:00";
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Navbar>
|
<Navbar>
|
||||||
@@ -254,6 +303,39 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label for="opening-times-label">Opening Times:</label>
|
||||||
|
<div class="opening-times">
|
||||||
|
{#each daysOfWeek as day, index (index)}
|
||||||
|
<div class="opening-time-item">
|
||||||
|
<label for={"opens-" + index}>{day}</label>
|
||||||
|
<input
|
||||||
|
id={"opens-" + index}
|
||||||
|
type="time"
|
||||||
|
bind:value={studySpaceData.opening_times[index].opens_at}
|
||||||
|
required
|
||||||
|
onchange={() => updateTimes(index)}
|
||||||
|
/>
|
||||||
|
<span>to</span>
|
||||||
|
<input
|
||||||
|
id={"closes-" + index}
|
||||||
|
type="time"
|
||||||
|
bind:value={studySpaceData.opening_times[index].closes_at}
|
||||||
|
required
|
||||||
|
onchange={() => updateTimes(index)}
|
||||||
|
/>
|
||||||
|
<label for={"is247-" + index}>
|
||||||
|
<input
|
||||||
|
id={"is247-" + index}
|
||||||
|
type="checkbox"
|
||||||
|
bind:checked={studySpaceData.opening_times[index].is_24_7}
|
||||||
|
onchange={() => toggle247(index)}
|
||||||
|
/>
|
||||||
|
All day
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
<label for="tags">Additional tags:</label>
|
<label for="tags">Additional tags:</label>
|
||||||
<div class="tagDisplay">
|
<div class="tagDisplay">
|
||||||
{#each studySpaceData.tags as tagName (tagName)}
|
{#each studySpaceData.tags as tagName (tagName)}
|
||||||
@@ -488,4 +570,36 @@
|
|||||||
.additionalImages input {
|
.additionalImages input {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Opening times layout and inputs styling */
|
||||||
|
.opening-times {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opening-time-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opening-time-item label {
|
||||||
|
margin-top: 0;
|
||||||
|
width: 6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opening-time-item input[type="time"] {
|
||||||
|
padding: 0.5rem;
|
||||||
|
height: 2.5rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
border: 2px solid #eaffeb;
|
||||||
|
background: none;
|
||||||
|
color: #eaffeb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opening-time-item span {
|
||||||
|
margin: 0 0.5rem;
|
||||||
|
color: #eaffeb;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE study_space_hours (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
study_space_id UUID REFERENCES study_spaces(id) ON DELETE CASCADE,
|
||||||
|
day_of_week INT CHECK (day_of_week BETWEEN 0 AND 6), -- 0 = Sunday, 6 = Saturday
|
||||||
|
opens_at TIME NOT NULL,
|
||||||
|
closes_at TIME NOT NULL,
|
||||||
|
is_24_7 BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at timestamp with time zone DEFAULT now(),
|
||||||
|
updated_at timestamp with time zone DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TRIGGER study_space_hours_updated_at
|
||||||
|
AFTER UPDATE ON study_space_hours
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||||
@@ -18,6 +18,7 @@ CREATE TABLE study_spaces (
|
|||||||
volume text NOT NULL,
|
volume text NOT NULL,
|
||||||
wifi text NOT NULL,
|
wifi text NOT NULL,
|
||||||
power text NOT NULL,
|
power text NOT NULL,
|
||||||
|
|
||||||
created_at timestamp with time zone DEFAULT now(),
|
created_at timestamp with time zone DEFAULT now(),
|
||||||
updated_at timestamp with time zone DEFAULT now()
|
updated_at timestamp with time zone DEFAULT now()
|
||||||
);
|
);
|
||||||
@@ -39,6 +40,17 @@ CREATE TABLE reports (
|
|||||||
content text
|
content text
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE study_space_hours (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
study_space_id UUID REFERENCES study_spaces(id) ON DELETE CASCADE,
|
||||||
|
day_of_week INT CHECK (day_of_week BETWEEN 0 AND 6), -- 0 = Sunday, 6 = Saturday
|
||||||
|
opens_at TIME NOT NULL,
|
||||||
|
closes_at TIME NOT NULL,
|
||||||
|
is_24_7 BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at timestamp with time zone DEFAULT now(),
|
||||||
|
updated_at timestamp with time zone DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
-- Triggers
|
-- Triggers
|
||||||
CREATE TRIGGER study_spaces_updated_at
|
CREATE TRIGGER study_spaces_updated_at
|
||||||
AFTER UPDATE ON study_spaces
|
AFTER UPDATE ON study_spaces
|
||||||
@@ -51,3 +63,7 @@ FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
|||||||
CREATE TRIGGER reports_updated_at
|
CREATE TRIGGER reports_updated_at
|
||||||
AFTER UPDATE ON reports
|
AFTER UPDATE ON reports
|
||||||
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER study_space_hours_updated_at
|
||||||
|
AFTER UPDATE ON study_space_hours
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION handle_updated_at();
|
||||||
|
|||||||
Reference in New Issue
Block a user