114 lines
2.6 KiB
Svelte
114 lines
2.6 KiB
Svelte
<script lang="ts">
|
|
import { useNavigate, useParams } from "svelte-navigator";
|
|
import Inspect from "../components/Inspect.svelte";
|
|
import IconButton from "../components/utils/IconButton.svelte";
|
|
import { normUrl as normURL } from "../util/history";
|
|
import { updateTitle } from "../util/title";
|
|
const navigate = useNavigate();
|
|
const params = useParams();
|
|
|
|
let root: HTMLDivElement;
|
|
let editable: boolean[] = [];
|
|
let identities: string[] = [];
|
|
$: addresses = $params.addresses.split(",");
|
|
|
|
function visit(idx: number) {
|
|
window.open(normURL(`/browse/${addresses[idx]}`), "_blank");
|
|
}
|
|
|
|
function close(idx: number) {
|
|
let _addresses = addresses.concat();
|
|
_addresses.splice(idx, 1);
|
|
navigate(`/browse/${_addresses.join(",")}`);
|
|
}
|
|
|
|
$: {
|
|
addresses;
|
|
|
|
root?.scrollTo({
|
|
left: root.scrollWidth,
|
|
behavior: "smooth",
|
|
});
|
|
}
|
|
|
|
function onIdentified(index: number, ev: CustomEvent<string[]>) {
|
|
for (let i = 0; i < addresses.length; i++) {
|
|
if (!identities[i]) {
|
|
identities[i] = "?";
|
|
}
|
|
identities[index] = ev.detail.join("/");
|
|
}
|
|
identities = identities;
|
|
}
|
|
|
|
$: updateTitle("Browse", identities.join(" / "));
|
|
</script>
|
|
|
|
<div class="browser" bind:this={root}>
|
|
{#each addresses as address, index}
|
|
<div class="view" data-address={address}>
|
|
<header>
|
|
<IconButton
|
|
name="pencil"
|
|
on:click={() => (editable[index] = !editable[index])}
|
|
/>
|
|
<IconButton
|
|
name="bookmark"
|
|
on:click={() => visit(index)}
|
|
disabled={addresses.length === 1}
|
|
/>
|
|
<IconButton
|
|
name="x-circle"
|
|
on:click={() => close(index)}
|
|
disabled={addresses.length === 1}
|
|
/>
|
|
</header>
|
|
<Inspect
|
|
{address}
|
|
editable={editable[index] || false}
|
|
{index}
|
|
on:resolved={(ev) => onIdentified(index, ev)}
|
|
/>
|
|
</div>
|
|
{/each}
|
|
</div>
|
|
|
|
<style scoped lang="scss">
|
|
.browser {
|
|
display: flex;
|
|
overflow-x: auto;
|
|
gap: 1rem;
|
|
padding: 0 1rem;
|
|
|
|
// header margin magic
|
|
height: calc(100% - 3.5rem - 1rem - 1px);
|
|
margin-top: 1rem;
|
|
margin-bottom: var(--footer-height);
|
|
}
|
|
|
|
.view {
|
|
min-width: 30em;
|
|
max-width: 30em;
|
|
|
|
display: flex;
|
|
flex-direction: column;
|
|
|
|
background: var(--background-lighter);
|
|
color: var(--foreground-lighter);
|
|
border: 1px solid var(--foreground-lightest);
|
|
border-radius: 0.5em;
|
|
padding: 1rem;
|
|
|
|
header {
|
|
font-size: 20px;
|
|
position: relative;
|
|
min-height: 1em;
|
|
|
|
display: flex;
|
|
justify-content: space-between;
|
|
|
|
flex: none;
|
|
}
|
|
}
|
|
</style>
|