Skip to content

Commit

Permalink
feat: add prototype of browse scores
Browse files Browse the repository at this point in the history
  • Loading branch information
21CSM committed Oct 9, 2024
1 parent 7fb8c7c commit 5817a1f
Show file tree
Hide file tree
Showing 12 changed files with 853 additions and 221 deletions.
30 changes: 30 additions & 0 deletions src/lib/components/score/ScoreCard.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
import type { Score } from '$lib/types';
import TagBadge from './TagBadge.svelte';
export let score: Score;
export let onClick: (id: string) => void;
</script>

<div
class="card card-hover overflow-hidden cursor-pointer"
on:click={() => onClick(score.id)}
on:keydown={(e) => e.key === 'Enter' && onClick(score.id)}
tabindex="0"
role="button"
>
<img src={score.thumbnailUrl} alt={score.title} class="w-full h-48 object-cover" />
<div class="p-4">
<h3 class="h3 mb-2 truncate">{score.title}</h3>
<div class="flex flex-wrap gap-1 mb-2">
{#if score.tags && score.tags.length > 0}
{#each score.tags as tag}
<TagBadge {tag} />
{/each}
{:else}
<span class="text-sm text-gray-500">No tags</span>
{/if}
</div>
<p class="text-sm text-gray-500 mt-2">Last modified: {score.lastModified}</p>
</div>
</div>
25 changes: 25 additions & 0 deletions src/lib/components/score/ScoreSearch.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import IconMagnify from '~icons/mdi/magnify';
export let value = '';
const dispatch = createEventDispatcher();
function handleInput(event: Event) {
const target = event.target as HTMLInputElement;
dispatch('input', target.value);
}
</script>

<div class="relative flex-grow">
<input
type="text"
placeholder="Search scores..."
class="input pl-10 pr-4 py-2 w-full h-10"
{value}
on:input={handleInput}
/>
<IconMagnify
class="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-surface-500"
/>
</div>
12 changes: 12 additions & 0 deletions src/lib/components/score/TagBadge.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts">
import { getTagColor, getContrastColor } from '$lib/utils/colorUtils';
export let tag: string;
$: bgColor = getTagColor(tag);
$: textColor = getContrastColor(bgColor);
</script>

<span class="badge text-xs" style="background-color: {bgColor}; color: {textColor};">
{tag}
</span>
33 changes: 33 additions & 0 deletions src/lib/components/score/TagFilter.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import IconFilterOutline from '~icons/mdi/filter-outline';
import IconChevronDown from '~icons/mdi/chevron-down';
export let tags: string[];
export let selectedTag = 'All';
const dispatch = createEventDispatcher();
function handleChange(event: Event) {
const target = event.target as HTMLSelectElement;
dispatch('change', target.value);
}
</script>

<div class="relative w-48">
<select
bind:value={selectedTag}
on:change={handleChange}
class="select pl-10 pr-8 py-2 w-full h-10 appearance-none"
>
{#each tags as tag}
<option value={tag}>{tag}</option>
{/each}
</select>
<IconFilterOutline
class="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-surface-500"
/>
<IconChevronDown
class="absolute right-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-surface-500"
/>
</div>
Loading

0 comments on commit 5817a1f

Please sign in to comment.