Skip to content

Commit

Permalink
fetch a single container
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmckenz committed Mar 12, 2024
1 parent 6124a21 commit d599c3d
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 2 deletions.
82 changes: 82 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"smui-theme-dark": "smui-theme compile static/smui-dark.css -i src/theme/dark"
},
"devDependencies": {
"@smui/button": "^7.0.0-beta.16",
"@smui/data-table": "^7.0.0-beta.16",
"@smui/textfield": "^7.0.0-beta.16",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<p>Step 4: Use Svelte MUI to display data</p>
<button on:click={() => {goto('/fromapi_mui')}}>Show Containers in nice table</button>

<p>Step 5: Use a "form" to collect user data and make an API request</p>
<button on:click={() => {goto('/fetchContainer')}}>Fetch A Container</button>


<style>
.note {
font-style: italic;
Expand Down
60 changes: 60 additions & 0 deletions src/routes/fetchContainer/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script>
import Button, { Label } from '@smui/button';
import DataTable, { Head, Body, Row, Cell } from '@smui/data-table';
import Textfield from '@smui/textfield';
import HelperText from '@smui/textfield/helper-text';
let container;
let containerNumber = '';
const fetchContainer = async (containerName) => {
const res = await fetch(`http://localhost:3000/container/${containerName}`);
const data = await res.json();
return data.containers[0];
};
</script>

<h1>View a Container</h1>

<Textfield variant="filled" bind:value={containerNumber} label="Container Number to View">
<HelperText slot="helper">May include letters</HelperText>
</Textfield>

<Button
variant="raised"
on:click={async () => {
container = await fetchContainer(containerNumber);
console.log(container);
}}><Label>Fetch Container {containerNumber}</Label></Button
>
<br />
{#if container}
<DataTable table$aria-label="Container Details" style="max-width: 100%;">
<Head>
<Row>
<Cell>Attribute</Cell>
<Cell>Value</Cell>
</Row>
</Head>
<Body>
<Row>
<Cell>Container Number</Cell>
<Cell>{container.containerNumber}</Cell>
</Row>
<Row>
<Cell>Container Size</Cell>
<Cell numeric>{container.containerSize}</Cell>
</Row>
<Row>
<Cell>Date of Shipment</Cell>
<Cell>{container.dateContainerShipped}</Cell>
</Row>
<Row>
<Cell>Name of Ship</Cell>
<Cell>{container.nameOfShip}</Cell>
</Row>
</Body>
</DataTable>
{:else}
<p>No container fetched</p>
{/if}
2 changes: 1 addition & 1 deletion static/smui-dark.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/smui.css

Large diffs are not rendered by default.

0 comments on commit d599c3d

Please sign in to comment.