Compare commits

...

11 Commits

Author SHA1 Message Date
Ling, Alex
4a3fd0df2a Merge branch 'refactor/favs' into 'master'
feat: admin display

See merge request gk1623/drp-48!34

Co-authored-by: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com>
2025-06-17 12:08:20 +00:00
Barf-Vader
8abcd3a979 feat:admin mode display 2025-06-17 13:03:58 +01:00
Barf-Vader
ade34ac7ca feat: hide favs for admin 2025-06-17 12:33:35 +01:00
Ling, Alex
3edae91e12 Merge branch 'refactor/favs' into 'master'
feat: fixed refactor 🤡

See merge request gk1623/drp-48!33

Co-authored-by: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com>
2025-06-17 00:09:21 +00:00
Barf-Vader
fcd11be506 feat: fixed refactor 🤡 2025-06-17 01:04:18 +01:00
670ecf3526 fix: what 2025-06-17 00:46:51 +01:00
e3e5e9eb69 fix: attempt at fixing image re-arranging 2025-06-17 00:31:21 +01:00
Ling, Alex
d086700d6d Merge branch 'refactor/favs' into 'master'
feat: delete

See merge request gk1623/drp-48!32

Co-authored-by: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com>
2025-06-16 22:30:30 +00:00
Barf-Vader
03bca19527 fix: Types 2025-06-16 23:25:42 +01:00
Barf-Vader
0239f86985 feat: delete 2025-06-16 22:40:54 +01:00
Ling, Alex
e518f63714 Merge branch 'refactor/favs' into 'master'
refactor: everything

See merge request gk1623/drp-48!31

Co-authored-by: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com>
2025-06-16 20:36:42 +00:00
4 changed files with 71 additions and 10 deletions

View File

@@ -85,9 +85,17 @@ export function haversineDistance(
return radius * 2 * Math.asin(Math.sqrt(e1)); return radius * 2 * Math.asin(Math.sqrt(e1));
} }
export function collectTimings(study_space_hours: Table<"study_space_hours">[]) { export function collectTimings(
study_space_hours: Omit<
Table<"study_space_hours">,
"id" | "created_at" | "updated_at" | "study_space_id"
>[]
) {
// Collect all timing entries // Collect all timing entries
const timingsPerDay: Record<number, Table<"study_space_hours">[]> = { const timingsPerDay: Record<
number,
Omit<Table<"study_space_hours">, "id" | "created_at" | "updated_at" | "study_space_id">[]
> = {
0: [], 0: [],
1: [], 1: [],
2: [], 2: [],

View File

@@ -190,6 +190,8 @@
function minsToReadableHours(mins: number) { function minsToReadableHours(mins: number) {
return `${Math.floor(mins / 60)} hrs, ${mins % 60} mins`; return `${Math.floor(mins / 60)} hrs, ${mins % 60} mins`;
} }
$inspect(sortedStudySpaces);
</script> </script>
<Navbar> <Navbar>
@@ -221,16 +223,14 @@
<main> <main>
{#each sortedStudySpaces as studySpace (studySpace.id)} {#each sortedStudySpaces as studySpace (studySpace.id)}
{@const imgUrl = <SpaceCard
studySpace.study_space_images.length > 0 alt="Photo of {studySpace.description}"
href="/space/{studySpace.id}"
imgSrc={studySpace.study_space_images.length > 0
? supabase.storage ? supabase.storage
.from("files_bucket") .from("files_bucket")
.getPublicUrl(studySpace.study_space_images[0].image_path).data.publicUrl .getPublicUrl(studySpace.study_space_images[0].image_path).data.publicUrl
: defaultImg} : defaultImg}
<SpaceCard
alt="Photo of {studySpace.description}"
href="/space/{studySpace.id}"
imgSrc={imgUrl}
space={studySpace} space={studySpace}
isFavourite={favouriteIds.includes(studySpace.id)} isFavourite={favouriteIds.includes(studySpace.id)}
onToggleFavourite={session ? () => handleToggleFavourite(studySpace.id) : undefined} onToggleFavourite={session ? () => handleToggleFavourite(studySpace.id) : undefined}
@@ -256,6 +256,9 @@
<Button href="/auth" type="link">Login / Signup</Button> <Button href="/auth" type="link">Login / Signup</Button>
{/if} {/if}
</footer> </footer>
{#if adminMode}
<div class="adminMode">You are in admin mode</div>
{/if}
<style> <style>
main { main {
@@ -326,4 +329,24 @@
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
} }
.adminMode {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
position: sticky;
left: 0;
gap: 0.5rem;
padding: 0.75rem;
font-size: 1rem;
background-color: #182125;
bottom: 0;
border-radius: 0.5rem;
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.1);
color: #eaffeb;
border: 2px solid #eaffeb;
z-index: 1000;
}
</style> </style>

View File

@@ -87,6 +87,12 @@
isFavourite = true; isFavourite = true;
} }
} }
async function deleteSpace() {
if (!confirm("Are you sure you want to delete this study space?")) return;
await supabase.from("study_spaces").delete().eq("id", space.id);
window.location.href = "/";
}
</script> </script>
<Navbar> <Navbar>
@@ -192,7 +198,10 @@
<div class="actions"> <div class="actions">
{#if adminMode} {#if adminMode}
<Button href="/space/{space.id}/edit" type="link">Edit</Button> <div class="buttonContainer">
<Button href="/space/{space.id}/edit" type="link">Edit</Button>
<Button type="button" style="red" onclick={deleteSpace}>Delete</Button>
</div>
{:else} {:else}
<Button onclick={() => (isReportVisible = true)} style="red">Report</Button> <Button onclick={() => (isReportVisible = true)} style="red">Report</Button>
{/if} {/if}
@@ -355,4 +364,9 @@
width: 3.75rem; width: 3.75rem;
height: 3.75rem; height: 3.75rem;
} }
.buttonContainer {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.5rem;
}
</style> </style>

View File

@@ -14,7 +14,8 @@
volumeTags, volumeTags,
gmapsLoader, gmapsLoader,
daysOfWeek, daysOfWeek,
timeToMins timeToMins,
collectTimings
} 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";
@@ -61,6 +62,20 @@
function checkTimings() { function checkTimings() {
let cannotExist = [] as number[]; let cannotExist = [] as number[];
let hasAllDays = Object.values(collectTimings(studySpaceData.opening_times)).every(
(item) => !(Array.isArray(item) && item.length === 0)
);
if (
(allDays.closes_at === "" || allDays.opens_at === "") &&
allDays.open_today_status === null &&
studySpaceData.opening_times.length > 0 &&
!hasAllDays
) {
alert(`No opening time provided for all other days.`);
return false;
}
const opensAtMinsAll = timeToMins(allDays.opens_at); const opensAtMinsAll = timeToMins(allDays.opens_at);
const closesAtMinsAll = timeToMins(allDays.closes_at); const closesAtMinsAll = timeToMins(allDays.closes_at);
if (opensAtMinsAll >= closesAtMinsAll) { if (opensAtMinsAll >= closesAtMinsAll) {
@@ -200,6 +215,7 @@
// Nothing is provided // Nothing is provided
if ( if (
(allDays.closes_at != "" && allDays.opens_at != "") || (allDays.closes_at != "" && allDays.opens_at != "") ||
studySpaceData.opening_times.length === 7 ||
allDays.open_today_status != null allDays.open_today_status != null
) { ) {
const { error: hoursErr } = await supabase const { error: hoursErr } = await supabase