|
1 | 1 | <script lang="ts">
|
2 |
| - import 'bootstrap/dist/css/bootstrap.min.css'; |
3 |
| - import { Col, Container, Row } from 'sveltestrap'; |
4 |
| - import { Nav, Navbar, NavbarBrand, NavItem, NavLink } from 'sveltestrap'; |
| 2 | + import { Col, Container, Icon, Row, Styles } from 'sveltestrap'; |
| 3 | + import { browser } from '$app/environment'; |
5 | 4 | import { setContext } from 'svelte';
|
6 |
| - import { SHLClient } from '../managementClient'; |
7 | 5 | import { writable } from 'svelte/store';
|
| 6 | + import { |
| 7 | + ButtonDropdown, |
| 8 | + DropdownItem, |
| 9 | + DropdownMenu, |
| 10 | + DropdownToggle, |
| 11 | + Navbar, |
| 12 | + NavbarBrand |
| 13 | + } from 'sveltestrap'; |
| 14 | + import { SHLClient, type SHLAdminParams } from '../managementClient'; |
| 15 | +
|
| 16 | + const LOCAL_STORAGE_KEY = 'shlips_store'; |
| 17 | + let shlStore = writable<SHLAdminParams[]>( |
| 18 | + browser && window.localStorage[LOCAL_STORAGE_KEY] |
| 19 | + ? JSON.parse(window.localStorage[LOCAL_STORAGE_KEY]) |
| 20 | + : [] |
| 21 | + ); |
| 22 | +
|
| 23 | + let selectedShl = writable<number | undefined>($shlStore.length > 0 ? 0 : undefined); |
| 24 | + setContext('selectedShl', selectedShl); |
| 25 | +
|
| 26 | + $: { |
| 27 | + if (browser && $shlStore) window.localStorage[LOCAL_STORAGE_KEY] = JSON.stringify($shlStore); |
| 28 | + } |
| 29 | +
|
| 30 | + setContext('shlStore', shlStore); |
| 31 | +
|
8 | 32 | let shlClient = new SHLClient();
|
9 | 33 | setContext('shlClient', shlClient);
|
10 | 34 |
|
|
13 | 37 | </script>
|
14 | 38 |
|
15 | 39 | <Container class="main" fluid>
|
| 40 | + <Styles /> |
16 | 41 | <Row>
|
17 | 42 | <Col>
|
18 | 43 | <Navbar>
|
19 | 44 | <NavbarBrand href="/">SMART Health Links for IPS</NavbarBrand>
|
20 |
| - <Nav class="ms-auto" navbar> |
21 |
| - <NavItem> |
22 |
| - <NavLink |
| 45 | + <ButtonDropdown size="sm"> |
| 46 | + <DropdownToggle color="primary" caret>Actions...</DropdownToggle> |
| 47 | + <DropdownMenu> |
| 48 | + <DropdownItem on:click={() => ($selectedShl = undefined)}>Add New SHLink</DropdownItem> |
| 49 | + <DropdownItem on:click={() => $reset++}>Reset Demo</DropdownItem> |
| 50 | + {#if $shlStore.length > 0} |
| 51 | + <DropdownItem divider /> |
| 52 | + <DropdownItem header>Stored SHLinks</DropdownItem> |
| 53 | + {#each $shlStore as shl, i} |
| 54 | + <DropdownItem |
| 55 | + on:click={() => { |
| 56 | + if ($selectedShl !== undefined) { |
| 57 | + if (i < $selectedShl) { |
| 58 | + $selectedShl--; |
| 59 | + } |
| 60 | + } |
| 61 | + const newStore = [...$shlStore]; |
| 62 | + newStore.splice(i, 1); |
| 63 | + $shlStore = newStore; |
| 64 | + if ($shlStore.length == 0) { |
| 65 | + $selectedShl = undefined; |
| 66 | + } |
| 67 | + }}><Icon name="trash" /> {shl.label || `SHLink ${i + 1}`}</DropdownItem |
| 68 | + > |
| 69 | + {/each} |
| 70 | + {/if} |
| 71 | + </DropdownMenu> |
| 72 | + </ButtonDropdown> |
| 73 | + <!-- <NavLink |
23 | 74 | on:click={() => {
|
24 | 75 | $reset++;
|
25 | 76 | }}>Reset SHL</NavLink
|
26 |
| - > |
27 |
| - </NavItem> |
28 |
| - </Nav> |
| 77 | + > --> |
29 | 78 | </Navbar>
|
30 | 79 | </Col>
|
31 | 80 | </Row>
|
|
0 commit comments