summaryrefslogtreecommitdiff
path: root/src/components/jet/action/FlowAction.svelte
blob: 3e55e82ae81fdf1fa2afac2a0ee5f63a9aba1f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script lang="ts">
    import type { HTMLAnchorAttributes } from 'svelte/elements';
    import type { FlowAction } from '@jet-app/app-store/api/models';
    import { getJetPerform } from '~/jet';

    type AllowedAnchorAttributes = Omit<
        HTMLAnchorAttributes,
        // The `href` attribute is not allowed because it will be provided
        // by the `FlowAction`
        'href'
    >;

    interface $$Props extends AllowedAnchorAttributes {
        destination: FlowAction;
    }

    const perform = getJetPerform();

    export let destination: FlowAction;

    // Web cannot support internal protocols, so this guard prevents
    // them from showing up in anchor tags.
    $: pageUrl = destination.pageUrl?.includes('x-as3-internal:')
        ? '#'
        : destination?.pageUrl;

    function onClick(event: MouseEvent) {
        event.preventDefault();

        perform(destination);
    }
</script>

<a
    {...$$restProps}
    href={pageUrl}
    data-test-id="internal-link"
    on:click={onClick}
>
    <slot />
</a>