|
| 1 | +<script lang="ts"> |
| 2 | + import type { LogEvent } from '$lib/types'; |
| 3 | + import { capitalizeFirstLetter, cn, parseTimestamp } from '$lib/utils'; |
| 4 | +
|
| 5 | + let { |
| 6 | + events, |
| 7 | + activeEventIndex = $bindable(), |
| 8 | + ...restProps |
| 9 | + }: { events: LogEvent[]; activeEventIndex: number } = $props(); |
| 10 | +
|
| 11 | + const commonClasses = 'w-full h-full bg-white'; |
| 12 | + const commonLogClasses = |
| 13 | + 'flex cursor-pointer gap-2 rounded-md p-2 transition-colors hover:bg-gray-100'; |
| 14 | + const activeLogClass = 'bg-gray-100'; |
| 15 | + const actionClasses = { |
| 16 | + upload: 'text-green-600', |
| 17 | + fetch: 'text-blue-800', |
| 18 | + webhook: 'text-red-500' |
| 19 | + }; |
| 20 | +</script> |
| 21 | + |
| 22 | +<section class={cn(commonClasses, restProps.class)}> |
| 23 | + <h2 class="pb-4 pl-8 text-xl">Logs</h2> |
| 24 | + {#each events as event, i} |
| 25 | + <article |
| 26 | + {...restProps} |
| 27 | + class={cn(commonLogClasses, i === activeEventIndex && activeLogClass)} |
| 28 | + onclick={() => { |
| 29 | + activeEventIndex = i; |
| 30 | + }} |
| 31 | + > |
| 32 | + <p class="font-light text-black/60">[{parseTimestamp(event.timestamp)}]</p> |
| 33 | + <div> |
| 34 | + <span class={actionClasses[event.action]}> |
| 35 | + {capitalizeFirstLetter(event.action)} |
| 36 | + {event.action === 'webhook' ? 'triggered' : ''} |
| 37 | + </span> |
| 38 | + {#if event.action === 'upload'} |
| 39 | + → {event.to} |
| 40 | + {:else if event.action === 'fetch'} |
| 41 | + ← {event.from} |
| 42 | + {:else if event.action === 'webhook'} |
| 43 | + ({event.from} → {event.to}) |
| 44 | + {/if} |
| 45 | + {#if event.action === 'upload' || event.action === 'fetch'} |
| 46 | + <br /> |
| 47 | + ({event.message}) |
| 48 | + {/if} |
| 49 | + </div> |
| 50 | + </article> |
| 51 | + {/each} |
| 52 | +</section> |
0 commit comments