upend/webui/src/components/display/UpLink.svelte

49 lines
1 KiB
Svelte
Raw Normal View History

2021-11-11 23:37:42 +01:00
<script lang="ts">
import { getContext } from "svelte";
2021-12-19 19:25:16 +01:00
import { useNavigate, useLocation, useParams } from "svelte-navigator";
import type { Writable } from "svelte/store";
2021-11-11 23:37:42 +01:00
import type { Address, VALUE_TYPE } from "upend/types";
const params = useParams();
const location = useLocation();
2021-12-19 19:25:16 +01:00
const navigate = useNavigate();
2021-11-11 23:37:42 +01:00
export let to: {
2021-11-11 23:37:42 +01:00
entity?: Address;
attribute?: string;
value?: { t: VALUE_TYPE; c: string };
};
2021-11-11 23:37:42 +01:00
const { index } = getContext("browse") as { index: Writable<number> };
2021-11-11 23:37:42 +01:00
2021-12-19 19:25:16 +01:00
function onClick() {
2021-11-30 23:28:50 +01:00
if ($location.pathname.startsWith("/browse") && to.entity) {
let addresses = $params.addresses.split(",");
2021-12-19 19:25:16 +01:00
const routerTo =
"/browse/" +
addresses
.slice(0, $index + 1)
.concat([to.entity])
.join(",");
2021-12-19 19:25:16 +01:00
navigate(routerTo);
return true;
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"
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>
<style lang="scss">
:global(.uplink) {
text-decoration: none;
}
</style>