This repository has been archived by the owner on May 28, 2024. It is now read-only.
forked from zackkrida/things-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from pvdthings/issue/12
Issue 12
- Loading branch information
Showing
7 changed files
with
51 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
<script> | ||
import { Card, Text } from "$lib/Foundation.svelte"; | ||
import BoxIcon from "$lib/icons/box.svg"; | ||
import { t } from "$lib/language/translate"; | ||
export let thing; | ||
let className = ""; | ||
export { className as class }; | ||
let innerWidth = 0; | ||
$: isMobile = innerWidth < 600; | ||
$: fontSize = thing.name.length > 13 || isMobile ? 'text-sm' : 'text-base'; | ||
const donateURL = `https://airtable.com/shrwMSrzvSLpQgQWC?prefill_Description=${encodeURIComponent(thing.name)}`; | ||
const hasZeroStock = thing.stock < 1; | ||
const noneAvailable = !hasZeroStock && (!thing.available || thing.available < 1); | ||
const backgroundColor = noneAvailable | ||
? 'bg-red-300' | ||
: hasZeroStock | ||
? 'bg-yellow-300' | ||
: 'bg-green-400'; | ||
const getShortName = () => { | ||
if (thing.name.length < 30) return thing.name; | ||
return thing.name.substring(0, 29) + '...'; | ||
}; | ||
const onClick = () => { | ||
if (!hasZeroStock) return; | ||
window.open(donateURL, '_blank').focus(); | ||
}; | ||
</script> | ||
|
||
<div class="flex flex-col {className}"> | ||
<Card> | ||
<img src={thing.image ?? BoxIcon} alt={thing.name} class="h-full w-full object-contain" /> | ||
</Card> | ||
<div class="pl-1 pt-2 flex flex-col gap-2 justify-between flex-grow"> | ||
<Text display bold smallauto>{thing.name}</Text> | ||
<div class="flex flex-col lg:flex-row gap-2"> | ||
{#if thing.stock > 0} | ||
<div class="px-2 py-1 rounded bg-green-300 w-max font-medium text-sm">{$t("Thing.Tags.Available")}</div> | ||
{:else} | ||
<a class="px-2 py-1 rounded brutal hover:hovers-static bg-primary w-max font-bold font-display text-sm" href={donateURL} target="_blank" rel="noreferrer">{$t("Button.Donate")}</a> | ||
{/if} | ||
<svelte:window bind:innerWidth /> | ||
|
||
<!-- svelte-ignore a11y-click-events-have-key-events --> | ||
<div class="flex flex-col justify-between bg-white rounded-md overflow-hidden brutal hovers-static {hasZeroStock && 'cursor-pointer'}" on:click={onClick}> | ||
<div class="p-2"> | ||
<img src={thing.image ?? BoxIcon} alt={thing.name} class="w-full aspect-square object-contain rounded" /> | ||
<div class="mt-3"> | ||
<div class="{fontSize} uppercase font-bold font-sans text-center">{getShortName()}</div> | ||
</div> | ||
</div> | ||
<div class="{backgroundColor} py-1 text-center font-medium border-t border-black"> | ||
{#if hasZeroStock} | ||
{isMobile ? $t('Donate') : $t('Click to Donate')} | ||
{:else if noneAvailable} | ||
{isMobile ? `${thing.available} / ${thing.stock}` : $t('Unavailable')} | ||
{:else} | ||
{isMobile | ||
? `${thing.available} / ${thing.stock}` | ||
: `${thing.available} / ${thing.stock} ${$t('Available')}`} | ||
{/if} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9661e4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
app – ./
app-pvdthings.vercel.app
app-nine-delta.vercel.app
app-git-main-pvdthings.vercel.app