From c87a80f9a53f5f5b7993a614a02d80adf83650ff Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 14 Dec 2023 16:50:54 -0800 Subject: [PATCH] feat: chat share --- src/lib/components/layout/Navbar.svelte | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/components/layout/Navbar.svelte b/src/lib/components/layout/Navbar.svelte index e6154a84..70e39eb7 100644 --- a/src/lib/components/layout/Navbar.svelte +++ b/src/lib/components/layout/Navbar.svelte @@ -2,10 +2,31 @@ import { v4 as uuidv4 } from 'uuid'; import { goto } from '$app/navigation'; - import { chatId } from '$lib/stores'; + import { chatId, db } from '$lib/stores'; + import toast from 'svelte-french-toast'; export let title: string = 'Ollama Web UI'; export let shareEnabled: boolean = false; + + const shareChat = async () => { + const chat = await $db.getChatById($chatId); + console.log('share', chat); + toast.success('Redirecting you to OllamaHub'); + + const url = 'https://ollamahub.com'; + + const tab = await window.open(`${url}/chats/upload`, '_blank'); + window.addEventListener( + 'message', + (event) => { + if (event.origin !== url) return; + if (event.data === 'loaded') { + tab.postMessage(JSON.stringify(chat), '*'); + } + }, + false + ); + };