From 160e63e509ef5f6558a985a5b366e36d69ee4f4a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 24 Oct 2024 00:00:49 -0700 Subject: [PATCH] refac: feedback history share support --- src/lib/components/admin/Evaluations.svelte | 75 +++++++++++++++++++- src/lib/components/icons/CloudArrowUp.svelte | 19 +++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/icons/CloudArrowUp.svelte diff --git a/src/lib/components/admin/Evaluations.svelte b/src/lib/components/admin/Evaluations.svelte index bbefcb639..3dd4d3ae4 100644 --- a/src/lib/components/admin/Evaluations.svelte +++ b/src/lib/components/admin/Evaluations.svelte @@ -20,6 +20,9 @@ import Badge from '../common/Badge.svelte'; import Pagination from '../common/Pagination.svelte'; import MagnifyingGlass from '../icons/MagnifyingGlass.svelte'; + import Share from '../icons/Share.svelte'; + import CloudArrowUp from '../icons/CloudArrowUp.svelte'; + import { toast } from 'svelte-sonner'; const i18n = getContext('i18n'); @@ -264,6 +267,33 @@ } }; + const shareHandler = async () => { + toast.success($i18n.t('Redirecting you to OpenWebUI Community')); + + // remove snapshot from feedbacks + const feedbacksToShare = feedbacks.map((f) => { + const { snapshot, user, ...rest } = f; + return rest; + }); + console.log(feedbacksToShare); + + const url = 'https://openwebui.com'; + const tab = await window.open(`${url}/leaderboard`, '_blank'); + + // Define the event handler function + const messageHandler = (event) => { + if (event.origin !== url) return; + if (event.data === 'loaded') { + tab.postMessage(JSON.stringify(feedbacksToShare), '*'); + + // Remove the event listener after handling the message + window.removeEventListener('message', messageHandler); + } + }; + + window.addEventListener('message', messageHandler, false); + }; + onMount(async () => { feedbacks = await getAllFeedbacks(localStorage.token); loaded = true; @@ -542,9 +572,52 @@ {/if} + + {#if feedbacks.length > 0} +
+
+ {$i18n.t('Help us create the best community leaderboard by sharing your feedback history!')} +
+ +
+ + + +
+
+ {/if} + {#if feedbacks.length > 10} {/if} -
+
{/if} diff --git a/src/lib/components/icons/CloudArrowUp.svelte b/src/lib/components/icons/CloudArrowUp.svelte new file mode 100644 index 000000000..bb54d861f --- /dev/null +++ b/src/lib/components/icons/CloudArrowUp.svelte @@ -0,0 +1,19 @@ + + + + +