Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from pvdthings/issue/12
Browse files Browse the repository at this point in the history
Issue 12
  • Loading branch information
dillonfagan authored May 16, 2023
2 parents 2bb9f6c + 46cffc7 commit 9661e4a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/lib/Foundation.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script context="module">
export { default as Button } from "./foundation/Button.svelte";
export { default as Card } from "./foundation/Card.svelte";
export { default as Column } from "./foundation/Column.svelte";
export { default as Link } from "./foundation/Link.svelte";
export { default as Row } from "./foundation/Row.svelte";
Expand Down
3 changes: 0 additions & 3 deletions src/lib/foundation/Card.svelte

This file was deleted.

15 changes: 9 additions & 6 deletions src/lib/language/translations.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
export default {
en: {
"Button.Home": "Home",
"Button.Donate": "Donate",
"Button.WishList": "Wish List",
"Chooser.CategoryPrompt": "Choose a category:",
"Input.Search": "Search...",
"Thing.Tags.Available": "Available",
"A project by": "A project by",
"No Results": "No Results"
"No Results": "No Results",
"Donate": "Donate",
"Click to Donate": "Click to Donate",
"Available": "Available",
"Unavailable": "Unavailable"
},
es: {
"Button.Home": "Inicio",
"Button.Donate": "Donar",
"Button.WishList": "Donaciones",
"Chooser.CategoryPrompt": "Elija una categoría:",
"Input.Search": "Buscar...",
"Thing.Tags.Available": "Disponible",
"A project by": "Un proyecto de",
"No Results": "No hay resultados",
"Donate": "Donar",
"Click to Donate": "Clic para donar",
"Available": "Disponible",
"Unavailable": "Indisponible",
"All": "Todas",
"DIY": "Bricolaje",
"Media": "Media",
Expand Down
4 changes: 0 additions & 4 deletions src/lib/layout/Footer.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import { Column, Link, Row, Text } from "$lib/Foundation.svelte";
import { t } from "$lib/language/translate";
</script>

<footer class="bg-bg py-10 relative z-40">
Expand Down Expand Up @@ -42,8 +41,5 @@
</svg>
</a>
</Row>
<Text body light center>
{$t("A project by")} <Link to="https://starboard.coop">Starboard Co-op</Link>
</Text>
</Column>
</footer>
1 change: 0 additions & 1 deletion src/lib/things/Scroller.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const style = wrap ? "grid grid-cols-3 md:grid-cols-5 gap-x-4 gap-y-6 place-content-between" : "flex flex-row overflow-auto";
export let things = [];
things = things.sort((a, b) => b.stock - a.stock);
</script>

<div class={style}>
Expand Down
55 changes: 40 additions & 15 deletions src/lib/things/Thing.svelte
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>
3 changes: 2 additions & 1 deletion src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const load = async ({ fetch }) => {
const result = await fetch('https://starboardcoop-things-api.glitch.me/things');
const host = process.env.API_HOST ?? 'http://localhost:8088';
const result = await fetch(`${host}/things`);
const data = await result.json();
data.things = data.things.filter(thing => thing.categories);

Expand Down

1 comment on commit 9661e4a

@vercel
Copy link

@vercel vercel bot commented on 9661e4a May 16, 2023

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

Please sign in to comment.