2021-11-11 23:37:42 +01:00
|
|
|
<script lang="ts">
|
2021-12-02 23:27:09 +01:00
|
|
|
import { getContext } from "svelte";
|
|
|
|
|
2022-02-13 15:08:09 +01:00
|
|
|
import { useNavigate, useLocation } from "svelte-navigator";
|
|
|
|
import { readable } from "svelte/store";
|
2021-11-11 23:37:42 +01:00
|
|
|
import type { Address, VALUE_TYPE } from "upend/types";
|
2022-02-13 15:08:09 +01:00
|
|
|
import type { BrowseContext } from "../../util/browse";
|
2021-12-02 23:27:09 +01:00
|
|
|
const location = useLocation();
|
2021-12-19 19:25:16 +01:00
|
|
|
const navigate = useNavigate();
|
2021-11-11 23:37:42 +01:00
|
|
|
|
2021-12-02 23:27:09 +01:00
|
|
|
export let to: {
|
2021-11-11 23:37:42 +01:00
|
|
|
entity?: Address;
|
|
|
|
attribute?: string;
|
|
|
|
value?: { t: VALUE_TYPE; c: string };
|
2021-12-02 23:27:09 +01:00
|
|
|
};
|
2022-03-19 23:15:51 +01:00
|
|
|
export let passthrough = false;
|
2021-11-11 23:37:42 +01:00
|
|
|
|
2022-02-13 15:08:09 +01:00
|
|
|
const context = getContext("browse") as BrowseContext | undefined;
|
2022-01-28 16:46:08 +01:00
|
|
|
const index = context ? context.index : readable(0);
|
2022-02-13 15:08:09 +01:00
|
|
|
const addresses = context ? context.addresses : readable([]);
|
2021-11-11 23:37:42 +01:00
|
|
|
|
2021-12-19 19:25:16 +01:00
|
|
|
function onClick() {
|
2022-01-13 19:33:48 +01:00
|
|
|
if (to.entity) {
|
|
|
|
if ($location.pathname.startsWith("/browse")) {
|
2022-02-13 15:08:09 +01:00
|
|
|
let newAddresses = $addresses.concat();
|
2022-01-13 19:33:48 +01:00
|
|
|
|
|
|
|
const routerTo =
|
|
|
|
"/browse/" +
|
2022-02-13 15:08:09 +01:00
|
|
|
newAddresses
|
2022-01-13 19:33:48 +01:00
|
|
|
.slice(0, $index + 1)
|
|
|
|
.concat([to.entity])
|
|
|
|
.join(",");
|
|
|
|
|
|
|
|
navigate(routerTo);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
navigate(`/browse/${to.entity}`);
|
|
|
|
}
|
2021-11-30 23:28:50 +01:00
|
|
|
}
|
2021-11-11 23:37:42 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-12-19 19:25:16 +01:00
|
|
|
<a
|
|
|
|
class="uplink"
|
2022-03-19 23:15:51 +01:00
|
|
|
class:passthrough
|
2021-12-19 19:25:16 +01:00
|
|
|
href="/#/browse/{to.entity}"
|
|
|
|
on:click|preventDefault={onClick}
|
|
|
|
>
|
2021-11-11 23:37:42 +01:00
|
|
|
<slot />
|
2021-12-19 19:25:16 +01:00
|
|
|
</a>
|
2021-11-30 20:59:53 +01:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
:global(.uplink) {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
2022-03-19 23:15:51 +01:00
|
|
|
:global(.uplink.passthrough) {
|
|
|
|
display: contents;
|
|
|
|
}
|
2021-11-30 20:59:53 +01:00
|
|
|
</style>
|