refactor: everything
This commit is contained in:
@@ -99,6 +99,33 @@
|
||||
})
|
||||
);
|
||||
|
||||
const sortedByOpenNow = $derived(
|
||||
filteredStudySpaces.toSorted((a, b) => {
|
||||
const now = new Date();
|
||||
const time = now.toTimeString().slice(0, 5);
|
||||
const today = now.getDay();
|
||||
let openUntil = [0, 0] as number[];
|
||||
for (const [index, day] of [a, b].entries()) {
|
||||
const timingsPerDay = collectTimings(day.study_space_hours);
|
||||
for (const timing of timingsPerDay[today]) {
|
||||
if (timing.open_today_status === true) {
|
||||
openUntil[index] = 24 * 60;
|
||||
break;
|
||||
} else if (timing.open_today_status === false) {
|
||||
break;
|
||||
} else {
|
||||
const opensFor = timeUntilClosing(timing.opens_at, timing.closes_at, time);
|
||||
if (opensFor) {
|
||||
openUntil[index] = opensFor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return openUntil[1] - openUntil[0];
|
||||
})
|
||||
);
|
||||
|
||||
const sortedStudySpaces = $derived(
|
||||
sortNear
|
||||
? filteredStudySpaces.toSorted((a, b) => {
|
||||
@@ -122,7 +149,7 @@
|
||||
);
|
||||
return aDistance - bDistance;
|
||||
})
|
||||
: filteredStudySpaces
|
||||
: sortedByOpenNow
|
||||
);
|
||||
|
||||
// Open now
|
||||
@@ -170,10 +197,18 @@
|
||||
<a href="/space/new/edit">
|
||||
<img src={crossUrl} alt="new" class="new-space" />
|
||||
</a>
|
||||
{/if}
|
||||
{#if adminMode}
|
||||
<span class="checkReports">
|
||||
<Button href="/space/reports" type="link" style="red">Check Reports</Button>
|
||||
</span>
|
||||
{/if}
|
||||
{#if session}
|
||||
<button class="fav-button" onclick={() => (showFavourites = !showFavourites)} type="button">
|
||||
{showFavourites ? "All spaces" : "My favourites"}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<div class="filterWrapper">
|
||||
<Button type="link" href="/filter?{searchParams}">
|
||||
<span class="search">
|
||||
@@ -185,11 +220,6 @@
|
||||
</Navbar>
|
||||
|
||||
<main>
|
||||
{#if adminMode}
|
||||
<div class="checkReports">
|
||||
<Button href="/space/reports" type="link" style="red">Check Reports</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{#each sortedStudySpaces as studySpace (studySpace.id)}
|
||||
{@const imgUrl =
|
||||
studySpace.study_space_images.length > 0
|
||||
@@ -256,7 +286,8 @@
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-size: 1.2rem;
|
||||
font-size: 1rem;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.fav-button {
|
||||
|
||||
Reference in New Issue
Block a user