aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/components/Settings/Bookmarks.vue
blob: 68fa86b0d8816befbc67c4e9be183727cf0f6542 (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
<script setup lang="ts">
import { apiCall, useWait } from '@vnuge/vnlib.browser';
import { useStore } from '../../store';
import { useObjectUrl, set } from '@vueuse/core';
import { ref } from 'vue';

const { bookmarks } = useStore();

const blobUrl = ref<Blob>();
const downloadAnchor = ref();
const obj = useObjectUrl(blobUrl);
const { waiting } = useWait()

const downloadBookmarks = () => {
    apiCall(async () => {
        const htmlData = await bookmarks.api.downloadAll();
        const blob = new Blob([htmlData], { type: 'text/html' });
        set(blobUrl, blob);
        downloadAnchor.value?.click();
    });
}

</script>
<template>
    <div class="flex flex-row justify-start">
        <div class="">
            <button class="flex items-center btn light" :disabled="waiting" @click="downloadBookmarks()">
                Download
            </button>
        </div>
    </div>
    <a ref="downloadAnchor" :href="obj" download="bookmarks.html" class="hidden"></a>
</template>