1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 12:59:36 +02:00

client sorting

This commit is contained in:
Sean Morley 2024-07-13 10:42:42 -04:00
parent 82db6f1789
commit f5fc2f5add
2 changed files with 36 additions and 9 deletions

View file

@ -363,6 +363,11 @@ export const actions: Actions = {
const planned = formData.get('planned'); const planned = formData.get('planned');
const featured = formData.get('featured'); const featured = formData.get('featured');
const order_direction = formData.get('order_direction') as string;
const order_by = formData.get('order_by') as string;
console.log(order_direction, order_by);
let adventures: Adventure[] = []; let adventures: Adventure[] = [];
if (!event.locals.user) { if (!event.locals.user) {
@ -399,7 +404,7 @@ export const actions: Actions = {
console.log(filterString); console.log(filterString);
let visitedFetch = await fetch( let visitedFetch = await fetch(
`${serverEndpoint}/api/adventures/filtered?types=${filterString}`, `${serverEndpoint}/api/adventures/filtered?types=${filterString}&order_by=${order_by}&order_direction=${order_direction}`,
{ {
headers: { headers: {
Cookie: `${event.cookies.get('auth')}` Cookie: `${event.cookies.get('auth')}`

View file

@ -252,22 +252,44 @@
<button type="submit" class="btn btn-primary mt-4">Filter</button> <button type="submit" class="btn btn-primary mt-4">Filter</button>
<div class="divider"></div> <div class="divider"></div>
<h3 class="text-center font-semibold text-lg mb-4">Sort</h3> <h3 class="text-center font-semibold text-lg mb-4">Sort</h3>
<label for="name-asc">Name ASC</label> <p>Order Direction</p>
<label for="asc">Ascending</label>
<input <input
type="radio" type="radio"
name="name" name="order_direction"
id="name-asc" id="asc"
class="radio radio-primary" class="radio radio-primary"
checked checked
on:click={() => sort({ attribute: 'name', order: 'asc' })} value="asc"
/> />
<label for="name-desc">Name DESC</label> <label for="desc">Descending</label>
<input <input
type="radio" type="radio"
name="name" name="order_direction"
id="name-desc" id="desc"
value="desc"
class="radio radio-primary"
/>
<br />
<p>Order By</p>
<label for="name">Name</label>
<input
type="radio"
name="order_by"
id="name"
class="radio radio-primary"
checked
value="name"
/>
<label for="date">Date</label>
<input type="radio" value="date" name="order_by" id="date" class="radio radio-primary" />
<label for="rating">Rating</label>
<input
type="radio"
value="rating"
name="order_by"
id="rating"
class="radio radio-primary" class="radio radio-primary"
on:click={() => sort({ attribute: 'name', order: 'desc' })}
/> />
</form> </form>
<div class="divider"></div> <div class="divider"></div>