-
Notifications
You must be signed in to change notification settings - Fork 2
Event sort #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Event sort #34
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
724ab46
table Veiw
GardKalland 046f5ab
added back delete
GardKalland 1c4f848
format
GardKalland 5e2f924
event button
GardKalland 82f9824
changed styling✨
GardKalland bb11759
sort Active shift
GardKalland 65a2dc1
New UI✨
GardKalland 2e2bf43
New UI✨
GardKalland 073e4bc
format
GardKalland 5f97f02
format
GardKalland 989af39
fixed UI
GardKalland 668918a
fixed new event
GardKalland 88fc454
Merge branch 'main' of github.com:programmerbar/mono into event_sort
GardKalland b8246c6
🧹Cleaning
GardKalland 8d7d7bb
🧹Cleaning
GardKalland 1ac803e
added unsaved message
GardKalland 8277884
styling
GardKalland 02ae704
removing multiple shift
GardKalland f7902c3
UI fix
GardKalland 76b5af1
Cant join past events
GardKalland 5cef44a
Mobile layout
GardKalland 9e11220
Diff redir
GardKalland d4b8b47
format
GardKalland 16f535f
format
GardKalland 51fbbc1
sort users by name
GardKalland 97b3c8e
format'
GardKalland 8bb9ac0
fixed colu
GardKalland 181ccf8
format
GardKalland 607b17a
diff mobile veiw
GardKalland 5aa63e6
removed date
GardKalland 950dff1
format
GardKalland 33f0ce1
format
GardKalland 0f84145
format
GardKalland 5c79350
lint fix
GardKalland d988aed
format
GardKalland 4b0fe34
Deleted file
GardKalland 99e20d1
styling
GardKalland 77b4a52
styling
GardKalland 14cadb4
fixed time check
GardKalland 0eb0cd6
styling
GardKalland 28843e2
format
GardKalland ace195d
fixed feedback
GardKalland 71d2cd8
effect to derived
GardKalland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| <script lang="ts"> | ||
| import { formatDate } from '$lib/date'; | ||
| import { SquarePen } from '@lucide/svelte'; | ||
| import { getUser } from '$lib/context/user.context'; | ||
| import Button from '../ui/Button.svelte'; | ||
| import Input from '$lib/components/ui/Input.svelte'; | ||
|
|
||
| type Event = { | ||
| id: string; | ||
| name: string; | ||
| date: Date; | ||
| shifts: { | ||
| id: string; | ||
| startAt: Date; | ||
| endAt: Date; | ||
| members: ['']; | ||
| }[]; | ||
| }; | ||
|
|
||
| const { events, outdated } = $props(); | ||
|
|
||
| let search = $state(''); | ||
| let activeTab = $state('upcoming'); | ||
| let user = getUser(); | ||
|
|
||
| function hasActiveShifts(event: Event) { | ||
| const now = new Date(); | ||
| return event.shifts.some((shift) => { | ||
| const startTime = new Date(shift.startAt); | ||
| const endTime = new Date(shift.endAt); | ||
| return startTime <= now && now < endTime; | ||
| }); | ||
| } | ||
|
|
||
| function hasUpcomingShifts(event: Event) { | ||
| const now = new Date(); | ||
| const hasActive = hasActiveShifts(event); | ||
| if (hasActive) return false; | ||
|
|
||
| return event.shifts.some((shift) => { | ||
| const startTime = new Date(shift.startAt); | ||
| return now < startTime; | ||
| }); | ||
| } | ||
|
|
||
| function hasActiveOrUpcoming(event: Event) { | ||
| return hasActiveShifts(event) || hasUpcomingShifts(event); | ||
| } | ||
|
|
||
| const upcomingEvents = $derived( | ||
| [...events, ...outdated.filter((event: Event) => hasActiveOrUpcoming(event))].sort((a, b) => { | ||
| if (hasActiveShifts(a)) return -1; | ||
| if (hasActiveShifts(b)) return 1; | ||
| return 0; | ||
| }) | ||
| ); | ||
|
|
||
| const pastEvnts = $derived(outdated.filter((event: Event) => !hasActiveOrUpcoming(event))); | ||
|
|
||
| const activeEvnts = $derived(activeTab === 'upcoming' ? upcomingEvents : pastEvnts); | ||
|
|
||
| let filteredEvents = $derived( | ||
| activeEvnts.filter((event: Event) => event.name.toLowerCase().includes(search.toLowerCase())) | ||
| ); | ||
|
|
||
| function countShifts(event: Event) { | ||
| return event.shifts.length; | ||
| } | ||
|
|
||
| function getEventStatus(event: Event) { | ||
| if (hasActiveShifts(event)) { | ||
| return 'Aktiv'; | ||
| } else if (hasUpcomingShifts(event)) { | ||
| return 'Kommende'; | ||
| } else { | ||
| return 'Ferdig'; | ||
| } | ||
| } | ||
|
|
||
| function getStatusClass(status: string) { | ||
| switch (status) { | ||
| case 'Kommende': | ||
| return 'text-blue-500 font-medium'; | ||
| case 'Aktiv': | ||
| return 'text-green-500 font-medium'; | ||
| case 'Ferdig': | ||
| return 'text-gray-500 font-medium'; | ||
| default: | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| let isMobile = $state(false); | ||
|
|
||
| const handleResize = () => { | ||
| isMobile = window.innerWidth < 568; | ||
| }; | ||
|
|
||
| $effect(() => { | ||
| handleResize(); | ||
| }); | ||
| </script> | ||
|
|
||
| <svelte:window onresize={handleResize} /> | ||
| <div class="border-gray overflow-hidden rounded-2xl border-2 bg-background shadow-lg"> | ||
| <div class="flex flex-wrap gap-2 border-b-2 bg-gray-200 p-2"> | ||
| <button | ||
| class="min-w-[200px] flex-1 cursor-pointer rounded-lg px-6 py-3 font-medium text-gray-500 transition-all duration-200 ease-in-out {activeTab === | ||
| 'upcoming' | ||
| ? 'bg-gray-300 font-semibold' | ||
| : 'hover:bg-gray-250 hover:text-blue-500'}" | ||
| onclick={() => (activeTab = 'upcoming')} | ||
| > | ||
| Arrangementer | ||
| </button> | ||
|
|
||
| <button | ||
| class="min-w-[200px] flex-1 cursor-pointer rounded-lg px-6 py-3 font-medium text-gray-500 transition-all duration-200 ease-in-out {activeTab === | ||
| 'past' | ||
| ? 'bg-gray-300 font-semibold' | ||
| : 'hover:bg-gray-250 hover:text-blue-500'}" | ||
| onclick={() => (activeTab = 'past')} | ||
| > | ||
| Tidligere arrangementer | ||
| </button> | ||
| </div> | ||
|
|
||
| <div class="flex {isMobile ? 'flex-col' : 'flex-row items-center'} gap-2 p-2"> | ||
| {#if $user?.role === 'board'} | ||
| <a href="arrangementer/ny" class={isMobile ? 'order-first w-full' : 'order-last'}> | ||
| <Button type="button" intent="primary" class={isMobile ? 'w-full' : ''}> | ||
| Nytt arrangement | ||
| </Button> | ||
| </a> | ||
| {/if} | ||
|
|
||
| <Input | ||
| type="search" | ||
| placeholder="Søk etter arrangementer..." | ||
| bind:value={search} | ||
| class="w-full flex-1 border-2 | ||
| {isMobile || !($user?.role === 'board') ? 'pr-4' : 'pr-32'}" | ||
| /> | ||
| </div> | ||
|
|
||
| {#if filteredEvents.length === 0} | ||
| <div class="mx-4 my-4 px-8 py-12 text-center font-medium text-gray-500"> | ||
| Ingen {activeTab === 'upcoming' ? 'kommende' : 'tidligere'} arrangementer å vise. | ||
| </div> | ||
| {:else} | ||
| <div class="overflow-x-auto p-2"> | ||
| <table class="w-full table-fixed"> | ||
| {#if isMobile} | ||
| <colgroup> | ||
| <col class="w-[60%]" /> | ||
| <col class="w-[40%]" /> | ||
| </colgroup> | ||
| {:else} | ||
| <colgroup> | ||
| <col class="w-[35%]" /> | ||
| <col class="w-[20%]" /> | ||
| <col class="w-[20%]" /> | ||
| <col class="w-[15%]" /> | ||
| </colgroup> | ||
| {/if} | ||
| <thead> | ||
| <tr class="border-b-2 border-gray-200"> | ||
| <th class="p-4 text-left">Arrangement</th> | ||
| {#if isMobile} | ||
| <th class="p-4 text-left">Status</th> | ||
| {:else} | ||
| <th class="p-4 text-left">Dato</th> | ||
| <th class="p-4 text-left">Antall vakter</th> | ||
| <th class="p-4 text-left">Status</th> | ||
| <th class="p-4 text-left" aria-label="Handlinger"></th> | ||
| {/if} | ||
| </tr> | ||
| </thead> | ||
| <tbody class="whitespace-nowrap break-words border-b border-gray-100"> | ||
| {#each filteredEvents as event (event.id)} | ||
| {@const status = getEventStatus(event)} | ||
| <tr class="relative cursor-pointer hover:bg-gray-50"> | ||
| <td class="overflow-hidden overflow-ellipsis p-4"> | ||
| <a href="arrangementer/{event.id}" class="absolute inset-0 z-0" aria-hidden="true"> | ||
| </a> | ||
| {event.name} | ||
| </td> | ||
| {#if isMobile} | ||
| <td class="overflow-hidden overflow-ellipsis p-4 {getStatusClass(status)}"> | ||
| {status} | ||
| </td> | ||
| {:else} | ||
| <td class="overflow-hidden overflow-ellipsis p-4"> | ||
| {formatDate(event.date)} | ||
| </td> | ||
| <td class="overflow-hidden overflow-ellipsis p-4"> | ||
| {countShifts(event)} | ||
| </td> | ||
| <td class="overflow-hidden overflow-ellipsis p-4 {getStatusClass(status)}"> | ||
| {status} | ||
| </td> | ||
| {#if !isMobile} | ||
| <td class="p-4"> | ||
| {#if $user?.role === 'board'} | ||
| <a | ||
| href="arrangementer/{event.id}/edit" | ||
| class="relative z-10 inline-flex text-gray-400 opacity-70 transition-all duration-200 ease-in-out hover:text-blue-500 hover:opacity-100" | ||
| aria-label="Rediger arrangement" | ||
| > | ||
| <SquarePen size={18} /> | ||
| </a> | ||
| {/if} | ||
| </td> | ||
| {/if} | ||
| {/if} | ||
| </tr> | ||
| {/each} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| {/if} | ||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.