mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-17 11:02:06 +00:00
fix: remediate branch review findings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { PUBLIC_USE_LOCAL_POKEMON_SPRITE_FOLDER } from '$env/static/public';
|
||||
import { inView } from '$lib/actions/inView';
|
||||
import { resolveSpriteUrl } from '$lib/utils/spriteUrl';
|
||||
|
||||
export let pokemonName: string;
|
||||
export let pokedexNumber: string | number;
|
||||
@@ -12,46 +13,7 @@
|
||||
let imagePath = null as string | null;
|
||||
let isInView = false;
|
||||
|
||||
function isFemaleForm(value?: string) {
|
||||
return /^female\b/i.test((value ?? '').trim());
|
||||
}
|
||||
|
||||
function buildFallbackKey() {
|
||||
const strippedPokedexNumber = pokedexNumber.toString().replace(/^0+/, '') || '0';
|
||||
if (!form) return strippedPokedexNumber;
|
||||
|
||||
let formValue = form.trim();
|
||||
formValue = formValue.replace(/^female[-\s]*/i, '');
|
||||
formValue = formValue
|
||||
.replace(/\s*\(.*?\)/g, '')
|
||||
.replace(/\s*\[.*?\]/g, '')
|
||||
.trim();
|
||||
if (!formValue || formValue.toLowerCase() === 'male') return strippedPokedexNumber;
|
||||
|
||||
formValue = formValue
|
||||
.toLowerCase()
|
||||
.replace(/%/g, '')
|
||||
.replace(/\balolan\b/g, 'alola')
|
||||
.replace(/\bgalarian\b/g, 'galar')
|
||||
.replace(/\bhisuian\b/g, 'hisui')
|
||||
.replace(/\bpaldean\b/g, 'paldea')
|
||||
.replace(/\bform(e)?$/, '')
|
||||
.replace(/\bability$/, '')
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/(^-|-$)/g, '')
|
||||
.replace(/2/g, 'two')
|
||||
.replace(/3/g, 'three')
|
||||
.replace(/4/g, 'four');
|
||||
|
||||
return formValue ? `${strippedPokedexNumber}-${formValue}` : strippedPokedexNumber;
|
||||
}
|
||||
|
||||
$: {
|
||||
const rootFolderBase =
|
||||
PUBLIC_USE_LOCAL_POKEMON_SPRITE_FOLDER === 'true'
|
||||
? '/sprites-small/home'
|
||||
: 'https://raw.githubusercontent.com/jcreek/LivingDexTracker/master/static/sprites-small/home';
|
||||
const resolvedSpriteKey = spriteKey?.trim() || buildFallbackKey();
|
||||
if (!spriteKey?.trim()) {
|
||||
console.warn('Missing sprite key for pokemon entry', {
|
||||
pokemonName,
|
||||
@@ -60,14 +22,11 @@
|
||||
});
|
||||
}
|
||||
|
||||
let rootFolder = rootFolderBase;
|
||||
if (shiny) {
|
||||
rootFolder += '/shiny';
|
||||
}
|
||||
if (isFemaleForm(form)) {
|
||||
rootFolder += '/female';
|
||||
}
|
||||
imagePath = `${rootFolder}/${resolvedSpriteKey}.webp`;
|
||||
imagePath = resolveSpriteUrl(
|
||||
{ pokedexNumber: Number(pokedexNumber), form, spriteKey },
|
||||
!!shiny,
|
||||
PUBLIC_USE_LOCAL_POKEMON_SPRITE_FOLDER === 'true'
|
||||
);
|
||||
}
|
||||
|
||||
$: if (loadingStrategy !== 'inView') {
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { clearOfflineData } from '$lib/stores/offlineSync';
|
||||
const dispatch = createEventDispatcher();
|
||||
let errorMessage = '';
|
||||
let isSigningOut = false;
|
||||
|
||||
function emitSignedOutEvent() {
|
||||
dispatch('signedOut', {});
|
||||
@@ -12,15 +15,32 @@
|
||||
export let supabase: SupabaseClient;
|
||||
|
||||
async function signOut() {
|
||||
// `.then(() => {...})` resolved to undefined, so destructuring `error` off it threw a
|
||||
// TypeError on every sign-out - after the event had already been emitted.
|
||||
const { error } = await supabase.auth.signOut();
|
||||
if (error) console.error('Sign out failed', error);
|
||||
emitSignedOutEvent();
|
||||
// Signing out used to leave the user sitting on the protected page they were on, still
|
||||
// showing its content. Send them to the public home page and re-run the server loads.
|
||||
await goto('/', { invalidateAll: true });
|
||||
errorMessage = '';
|
||||
isSigningOut = true;
|
||||
try {
|
||||
const { error } = await supabase.auth.signOut();
|
||||
if (error) {
|
||||
errorMessage = `Sign out failed: ${error.message || 'Please try again.'}`;
|
||||
dispatch('signOutFailed', { message: errorMessage });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await clearOfflineData();
|
||||
} catch (cacheError) {
|
||||
console.error('Signed out, but failed to clear offline data', cacheError);
|
||||
}
|
||||
emitSignedOutEvent();
|
||||
await goto('/', { invalidateAll: true });
|
||||
} catch (error) {
|
||||
console.error('Sign out failed', error);
|
||||
errorMessage = 'Sign out failed. Please try again.';
|
||||
dispatch('signOutFailed', { message: errorMessage });
|
||||
} finally {
|
||||
isSigningOut = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={signOut}>Sign Out</button>
|
||||
<button on:click={signOut} disabled={isSigningOut}>
|
||||
{isSigningOut ? 'Signing Out…' : 'Sign Out'}
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user