-
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 #65 from pvdthings/dev
Web: Thing Details - Iteration 1
- Loading branch information
Showing
38 changed files
with
457 additions
and
99 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 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { fetchThing } = require("../../../services/things"); | ||
|
||
async function getThingDetails(id) { | ||
const details = await fetchThing(id); | ||
|
||
return { | ||
id: details.id, | ||
name: details.name, | ||
spanishName: details.name_es, | ||
categories: details.categories, | ||
availableDate: details.availableDate, | ||
available: details.available, | ||
stock: details.stock, | ||
image: details.images?.length ? details.images[0].url : undefined, | ||
items: details.items.filter((i) => i.location !== 'Providence Public Library').map(item => ({ | ||
id: item.id, | ||
number: item.number, | ||
brand: item.brand, | ||
hidden: item.hidden, | ||
status: mapItemStatus(item) | ||
})) | ||
}; | ||
} | ||
|
||
function mapItemStatus(item) { | ||
if (item.available) { | ||
return 'available'; | ||
} | ||
|
||
return 'checkedOut'; | ||
} | ||
|
||
module.exports = { | ||
getThingDetails | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="absolute top-1/2 left-1/2 -translate-y-1/2 -translate-x-1/2"> | ||
<slot /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts"> | ||
import { style, type BadgeType } from "./type"; | ||
export let type: BadgeType = 'neutral'; | ||
</script> | ||
|
||
<div class="badge {style(type)} badge-lg"> | ||
<slot /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as Badge } from './Badge.svelte'; | ||
export * from './type'; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export type BadgeType = | ||
'neutral' | ||
| 'primary' | ||
| 'warning' | ||
| 'success' | ||
| 'error'; | ||
|
||
export function style(type: BadgeType) { | ||
switch (type) { | ||
case 'neutral': | ||
return 'badge-neutral'; | ||
case 'primary': | ||
return 'badge-primary'; | ||
case 'warning': | ||
return 'badge-warning'; | ||
case 'success': | ||
return 'badge-success' | ||
case 'error': | ||
return 'badge-error'; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script lang="ts"> | ||
import CloseIcon from "$lib/icons/x-mark.svg"; | ||
let className: string; | ||
export { className as class }; | ||
</script> | ||
|
||
<button class="btn btn-circle btn-ghost outline-none {className}" on:click> | ||
<img src={CloseIcon} alt="Close" height="24" width="24" /> | ||
</button> |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="divider" /> |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<span class="loading loading-spinner loading-lg text-indigo-500" /> |
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,3 +1,38 @@ | ||
<div class="flex flex-col w-screen h-screen overflow-hidden"> | ||
<slot /> | ||
<script lang="ts"> | ||
import { setContext } from "svelte"; | ||
let drawerToggle: HTMLLabelElement; | ||
let drawerContent: any; | ||
let drawerContentProps: any; | ||
const drawer = { | ||
open: (content: any, props = {}) => { | ||
drawerContent = content; | ||
drawerContentProps = props; | ||
drawerToggle.click(); | ||
}, | ||
close: () => { | ||
drawerToggle.click(); | ||
drawerContent = null; | ||
drawerContentProps = null; | ||
} | ||
}; | ||
setContext('shell', { | ||
drawer | ||
}); | ||
</script> | ||
|
||
<div class="drawer drawer-end"> | ||
<input id="drawer-toggle" type="checkbox" class="drawer-toggle" /> | ||
<div class="flex flex-col h-dvh w-screen overflow-hidden drawer-content"> | ||
<label bind:this={drawerToggle} for="drawer-toggle" /> | ||
<slot /> | ||
</div> | ||
<div class="drawer-side z-50"> | ||
<label for="drawer-toggle" aria-label="close sidebar" class="drawer-overlay"></label> | ||
<div class="bg-base-200 text-base-content flex flex-col h-dvh w-screen overflow-hidden md:w-80 lg:w-96 relative"> | ||
<svelte:component this={drawerContent} {...drawerContentProps} /> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getContext } from "svelte"; | ||
|
||
export type ShellContext = { | ||
drawer: DrawerContext; | ||
}; | ||
|
||
export type DrawerContext = { | ||
open: (content: any, props: any) => void; | ||
close: () => void; | ||
}; | ||
|
||
export function getShellContext(): ShellContext { | ||
return getContext('shell'); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="flex flex-wrap gap-2"> | ||
<slot /> | ||
</div> |
17 changes: 17 additions & 0 deletions
17
apps/web/src/lib/components/things/Details/BookmarkButton.svelte
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
import type { ThingID } from "$lib/models/Thing"; | ||
import { bookmarks } from "$lib/stores/bookmarks"; | ||
export let id: ThingID; | ||
$: bookmarked = bookmarks.isBookmarked(id); | ||
$: iconVariant = $bookmarked ? 'ph-fill' : 'ph-bold'; | ||
const toggle = () => { | ||
bookmarks.addRemove(id); | ||
}; | ||
</script> | ||
|
||
<button on:click={toggle} class="fixed bottom-4 right-4 btn btn-circle btn-lg btn-primary shadow-lg z-50"> | ||
<span class="{iconVariant} ph-bookmark-simple text-white text-4xl" /> | ||
</button> |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<script lang="ts"> | ||
import BoxIcon from '$lib/icons/box.svg'; | ||
import CloseButton from '$lib/components/CloseButton.svelte'; | ||
import { getShellContext } from '$lib/components/Shell/ShellContext'; | ||
import InventoryItem from './InventoryItem.svelte'; | ||
import BookmarkButton from './BookmarkButton.svelte'; | ||
import { bookmarks } from '$lib/stores/bookmarks'; | ||
import { locale, t } from '$lib/language/translate'; | ||
import Divider from "$lib/components/Divider.svelte"; | ||
import Wrap from "$lib/components/Wrap.svelte"; | ||
import Title from "./Title.svelte"; | ||
import List from "./List.svelte"; | ||
import Section from "./Section.svelte"; | ||
import { Badge, type BadgeType } from "$lib/components/Badge"; | ||
import type { InventoryItemModel } from '$lib/models/ThingDetails'; | ||
export let id: string; | ||
export let name: string; | ||
export let image: string|undefined; | ||
export let stock: number; | ||
export let available: number; | ||
export let availableDate: string|undefined; | ||
export let categories: string[]; | ||
export let items: InventoryItemModel[]; | ||
const { drawer } = getShellContext(); | ||
$: stockBadgeVariant = (available ? 'success' : 'error') as BadgeType; | ||
$: bookmarked = bookmarks.isBookmarked(id); | ||
$: isBookmarked = $bookmarked; | ||
</script> | ||
|
||
<BookmarkButton {id} /> | ||
<section class="flex-grow-0 flex-shrink-0 h-48 md:h-64 border-b border-base-300 overflow-hidden relative shadow-sm"> | ||
<img | ||
src={image ?? BoxIcon} | ||
alt={name} | ||
class="object-center object-contain bg-white h-full w-full" | ||
/> | ||
<CloseButton class="absolute top-4 right-4" on:click={drawer.close} /> | ||
</section> | ||
<div class="p-4 flex flex-col flex-grow overflow-y-scroll"> | ||
<section> | ||
<Title>{name}</Title> | ||
<Wrap> | ||
<Badge type={stockBadgeVariant}>{available} / {stock}</Badge> | ||
{#if !available && availableDate} | ||
<Badge>{$t('Due Back')} {new Date(availableDate).toLocaleDateString($locale)}</Badge> | ||
{/if} | ||
{#if isBookmarked} | ||
<Badge type='primary'>{$t('Bookmarked')}</Badge> | ||
{/if} | ||
</Wrap> | ||
</section> | ||
<Divider /> | ||
<Section title={$t('Categories')}> | ||
<Wrap> | ||
{#if categories.length} | ||
{#each categories as category} | ||
<Badge>{$t(category)}</Badge> | ||
{/each} | ||
{:else} | ||
<div>None</div> | ||
{/if} | ||
</Wrap> | ||
</Section> | ||
<Divider /> | ||
<Section title={$t('Inventory')}> | ||
{@const availableItems = items.filter((i) => i.status === 'available' && !i.hidden)} | ||
{@const unavailableItems = items.filter((i) => i.status === 'checkedOut' || i.hidden)} | ||
|
||
{#if availableItems.length} | ||
<List title={$t('Available')}> | ||
{#each availableItems as item} | ||
<InventoryItem number={item.number} brand={item.brand} status={item.status} /> | ||
{/each} | ||
</List> | ||
{/if} | ||
|
||
{#if unavailableItems.length} | ||
<List title={$t('Unavailable')}> | ||
{#each unavailableItems as item} | ||
<InventoryItem number={item.number} brand={item.brand} status={item.status} /> | ||
{/each} | ||
</List> | ||
{/if} | ||
</Section> | ||
</div> |
Oops, something went wrong.