| 
5 | 5 | 	import type { PetPanelData } from '$lib/types/Pet.js';  | 
6 | 6 | 
  | 
7 | 7 | 	let pets: PetPanelData[] = [];  | 
 | 8 | +	// Derived lists  | 
 | 9 | +	$: activePets = pets.filter((p) => !p.archived);  | 
 | 10 | +	$: archivedPets = pets.filter((p) => p.archived);  | 
8 | 11 | 	let selectedPetId: string | null = null;  | 
9 | 12 | 	let showCreateForm = false;  | 
10 | 13 | 	let imageInput: HTMLInputElement;  | 
 | 
139 | 142 | 		}  | 
140 | 143 | 	}  | 
141 | 144 | 
  | 
 | 145 | +	// Keyboard activate handler for elements with role="button"  | 
 | 146 | +	function handleActivate(e: KeyboardEvent, action: () => void) {  | 
 | 147 | +		if (e.key === 'Enter' || e.key === ' ') {  | 
 | 148 | +			e.preventDefault();  | 
 | 149 | +			action();  | 
 | 150 | +		}  | 
 | 151 | +	}  | 
 | 152 | +
  | 
142 | 153 | 	function validateForm() {  | 
143 | 154 | 		formErrors = {};  | 
144 | 155 | 
  | 
 | 
197 | 208 | 		selectedPetHelpers.select(petId);  | 
198 | 209 | 	}  | 
199 | 210 | 
  | 
200 |  | -	function handleActivate(e: KeyboardEvent, action: () => void) {  | 
201 |  | -		if (e.key === 'Enter' || e.key === ' ') {  | 
202 |  | -			e.preventDefault();  | 
203 |  | -			action();  | 
204 |  | -		}  | 
205 |  | -	}  | 
 | 211 | +	function archivePet(petId: string) {  | 
 | 212 | +        petHelpers.archive(petId);  | 
 | 213 | +        if (selectedPetId === petId) {  | 
 | 214 | +            selectedPetHelpers.clear();  | 
 | 215 | +        }  | 
 | 216 | +    }  | 
 | 217 | +
  | 
 | 218 | +    function unarchivePet(petId: string) {  | 
 | 219 | +        petHelpers.unarchive(petId);  | 
 | 220 | +    }  | 
206 | 221 | </script>  | 
207 | 222 | 
 
  | 
208 | 223 | <div class="pet-panel h-full" style="background: var(--petalytics-bg);">  | 
 | 
338 | 353 | 			<span class="ml-2" style="color: var(--petalytics-gold);">active_pets</span>  | 
339 | 354 | 		</div>  | 
340 | 355 | 
 
  | 
341 |  | -		{#if pets.length === 0}  | 
 | 356 | +		{#if activePets.length === 0}  | 
342 | 357 | 			<div class="px-2 py-4" style="color: var(--petalytics-subtle);">no pets yet — use add_pet to create one</div>  | 
343 | 358 | 		{:else}  | 
344 |  | -					{#each pets as pet}  | 
 | 359 | +				{#each activePets as pet}  | 
345 | 360 | 						<div class="cli-row px-2 py-1" role="button" tabindex="0" data-selected={selectedPetId === pet.id} onclick={() => selectPet(pet.id)} onkeydown={(e) => handleActivate(e, () => selectPet(pet.id))}>  | 
 | 361 | + 						<span class="label" style="color: var(--petalytics-text);">{pet.name}</span>  | 
 | 362 | + 						<span class="value" style="color: var(--petalytics-subtle);">  | 
 | 363 | + 							{pet.species || 'pet'} | {pet.breed || '—'} | {pet.age}{pet.ageUnit === 'months' ? 'm' : pet.ageUnit === 'weeks' ? 'w' : 'y'}  | 
 | 364 | + 						</span>  | 
 | 365 | + 					</div>  | 
 | 366 | +						<div class="px-2 pb-2 flex justify-end">  | 
 | 367 | +                            <button class="arrow-btn" onclick={() => archivePet(pet.id)}>archive</button>  | 
 | 368 | +                        </div>  | 
 | 369 | +					{/each}  | 
 | 370 | + 		{/if}  | 
 | 371 | + | 
 | 372 | +		<!-- Archived list -->  | 
 | 373 | +		<div class="my-3"><div class="border-t" style="border-color: var(--petalytics-border);"></div></div>  | 
 | 374 | +		<div class="cli-row px-2 py-1">  | 
 | 375 | +			<span style="color: var(--petalytics-subtle);">#</span>  | 
 | 376 | +			<span class="ml-2" style="color: var(--petalytics-gold);">archived_pets</span>  | 
 | 377 | +		</div>  | 
 | 378 | +		{#if archivedPets.length === 0}  | 
 | 379 | +			<div class="px-2 py-2" style="color: var(--petalytics-subtle);">none</div>  | 
 | 380 | +		{:else}  | 
 | 381 | +			{#each archivedPets as pet}  | 
 | 382 | +				<div class="cli-row px-2 py-1">  | 
346 | 383 | 					<span class="label" style="color: var(--petalytics-text);">{pet.name}</span>  | 
347 | 384 | 					<span class="value" style="color: var(--petalytics-subtle);">  | 
348 | 385 | 						{pet.species || 'pet'} | {pet.breed || '—'} | {pet.age}{pet.ageUnit === 'months' ? 'm' : pet.ageUnit === 'weeks' ? 'w' : 'y'}  | 
349 | 386 | 					</span>  | 
350 | 387 | 				</div>  | 
 | 388 | +				<div class="px-2 pb-2 flex justify-end">  | 
 | 389 | +					<button class="arrow-btn" onclick={() => unarchivePet(pet.id)}>unarchive</button>  | 
 | 390 | +				</div>  | 
351 | 391 | 			{/each}  | 
352 | 392 | 		{/if}  | 
353 | 393 | 	</div>  | 
 | 
0 commit comments