Skip to content

Commit

Permalink
parseFloat/parseInt for ratings parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrubinger committed Dec 15, 2022
1 parent 268902b commit 286de87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/lib/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
function validImage(url) {
return url.includes('https://');
}
let starsRatingMaskWidth = !!ratings ? (ratings / 5) * 100 : 0;
</script>

<div class="cardroot" class:debug={dev}>
Expand All @@ -33,7 +35,7 @@
<span class="stars stars-1">
{#each Array.from({ length: 5 }) as star}★{/each}
</span>
<span class="stars stars-2" style:width="{(ratings / 5) * 100}%">
<span class="stars stars-2" style:width="{starsRatingMaskWidth}%">
<span class="inner">
{#each Array.from({ length: 5 }) as star}★{/each}
</span>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/og/extract-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export function extractSearchParams(searchParams) {
title: searchParams.get('title') ?? undefined,
image: searchParams.get('image') ?? undefined,
variants: searchParams.get('variants') === 'true' ? true : false,
ratings: searchParams.get('ratings') ?? undefined,
ratings_count: searchParams.get('ratings_count') ?? undefined,
ratings: searchParams.get('ratings') && searchParams.get('ratings') !== 'undefined' ? parseFloat(searchParams.get('ratings')) : undefined,
ratings_count: searchParams.get('ratings_count') && searchParams.get('ratings_count') !== 'undefined' ? parseInt(searchParams.get('ratings_count')) : undefined,
};
return renderparams;
}

1 comment on commit 286de87

@vercel
Copy link

@vercel vercel bot commented on 286de87 Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.