Name Message Date
📄 +page.svelte History page 1 month ago
📄 src/routes/history/+page.svelte
<script lang="ts">
  import { historyStore } from "$lib/history";

  function formatDate(iso: string): string {
    return new Date(iso).toLocaleDateString(undefined, {
      month: "short",
      day: "numeric",
      year: "numeric",
    });
  }

  function formatTime(iso: string): string {
    return new Date(iso).toLocaleTimeString(undefined, {
      hour: "2-digit",
      minute: "2-digit",
    });
  }
</script>

{#if $historyStore.length === 0}
  <p class="empty">No birds detected yet.</p>
{:else}
  <ol>
    {#each $historyStore as entry (entry.detectedAt + entry.scientificName)}
      <li>
        <span class="name">{entry.commonName}</span>
        <span class="when">
          <span>{formatDate(entry.detectedAt)}</span>
          <span>{formatTime(entry.detectedAt)}</span>
        </span>
      </li>
    {/each}
  </ol>
{/if}

<style>
  .empty {
    padding: 2rem 1rem;
    opacity: 0.5;
    text-align: center;
  }

  ol {
    list-style: none;
    padding: 1rem;
    padding-top: 2rem;
    padding-bottom: calc(
      var(--nav-height) + env(safe-area-inset-bottom) + 1rem
    );
    display: flex;
    flex-direction: column;
    gap: 0.5rem;

    li {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0.75rem 1rem;
      border-radius: 0.5rem;
      background: var(--nav-bg);

      .name {
        font-weight: 500;
      }

      .when {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.1rem;
        font-variant-numeric: tabular-nums;
        opacity: 0.7;
        font-size: 0.85rem;
      }
    }
  }
</style>