Add disclaimer and share (#76)
Browse files* disclaimer and share
* ✨ Share from multiple routes
* Update src/lib/components/chat/ChatWindow.svelte
---------
Co-authored-by: coyotte508 <coyotte508@gmail.com>
Files changed (7)
7 unmodified lines89101112132 unmodified lines161718192021224 unmodified lines2728293031323316 unmodified lines50515253547 unmodified linesimport ChatMessages from "./ChatMessages.svelte";import ChatInput from "./ChatInput.svelte";export let messages: Message[] = [];export let disabled: boolean = false;2 unmodified lineslet message: string;const dispatch = createEventDispatcher<{ message: string }>();</script><div class="relative h-screen">4 unmodified lines</nav><ChatMessages {loading} {pending} {messages} on:message /><divclass="flex max-md:border-t dark:border-gray-800 items-center max-md:dark:bg-gray-900 max-md:bg-white bg-gradient-to-t from-white dark:from-gray-900 to-transparent justify-center absolute inset-x-0 max-w-3xl xl:max-w-4xl mx-auto px-5 bottom-0 py-4 md:py-8 w-full"><formon:submit|preventDefault={() => {16 unmodified lines</button></div></form></div></div>7 unmodified lines8910111213142 unmodified lines171819202122234 unmodified lines2829303132333416 unmodified lines515253545556575859606162636465666768697 unmodified linesimport ChatMessages from "./ChatMessages.svelte";import ChatInput from "./ChatInput.svelte";import CarbonExport from "~icons/carbon/export";export let messages: Message[] = [];export let disabled: boolean = false;2 unmodified lineslet message: string;const dispatch = createEventDispatcher<{ message: string; share: void }>();</script><div class="relative h-screen">4 unmodified lines</nav><ChatMessages {loading} {pending} {messages} on:message /><divclass="flex flex-col max-md:border-t dark:border-gray-800 items-center max-md:dark:bg-gray-900 max-md:bg-white bg-gradient-to-t from-white to-white/0 dark:from-gray-900 dark:to-gray-900/0 justify-center absolute inset-x-0 max-w-3xl xl:max-w-4xl mx-auto px-5 bottom-0 py-4 md:py-8 w-full"><formon:submit|preventDefault={() => {16 unmodified lines</button></div></form><div class="flex text-xs text-gray-400/80 mt-2 justify-between self-stretch px-1"><p>Model: OpenAssistant/oasst-sft-1-pythia-12b · Generated content may be inaccurate or false.</p>{#if messages.length}<buttonclass="flex items-center hover:underline hover:text-gray-400"type="button"on:click={() => dispatch("share")}><CarbonExport class="text-[.6rem] mr-1.5 text-yellow-500" />Share this conversation</button>{/if}</div></div></div>
1234567891011121314151617181920212223242526272829303132import { base } from "$app/paths";
export async function shareConversation(id: string, title: string) { try { const res = await fetch(`${base}/conversation/${id}/share`, { method: "POST", headers: { "Content-Type": "application/json", }, });
if (!res.ok) { alert("Error while sharing conversation: " + (await res.text())); return; }
const { url } = await res.json();
if (navigator.share) { navigator.share({ title, text: "Share this chat with others", url, }); } else { prompt("Share this link with your friends:", url); } } catch (err) { console.error(err); alert("Error while sharing conversation: " + err); }}6 unmodified lines7891011129 unmodified lines222324252627282930313233343536373839404142434445464748495051525354555657586 unmodified linesimport CarbonTrashCan from "~icons/carbon/trash-can";import CarbonExport from "~icons/carbon/export";import { base } from "$app/paths";import { UrlDependency } from "$lib/types/UrlDependency";export let data: LayoutData;9 unmodified lines}}async function shareConversation(id: string, title: string) {try {const res = await fetch(`${base}/conversation/${id}/share`, {method: "POST",headers: {"Content-Type": "application/json",},});if (!res.ok) {alert("Error while sharing conversation: " + (await res.text()));return;}const { url } = await res.json();if (navigator.share) {navigator.share({title,text: "Share this chat with others",url,});} else {prompt("Share this link with your friends:", url);}} catch (err) {console.error(err);alert("Error while sharing conversation: " + err);}}async function deleteConversation(id: string) {try {const res = await fetch(`${base}/conversation/${id}`, {6 unmodified lines789101112139 unmodified lines2324252627286 unmodified linesimport CarbonTrashCan from "~icons/carbon/trash-can";import CarbonExport from "~icons/carbon/export";import { base } from "$app/paths";import { shareConversation } from "$lib/shareConversation";import { UrlDependency } from "$lib/types/UrlDependency";export let data: LayoutData;9 unmodified lines}}async function deleteConversation(id: string) {try {const res = await fetch(`${base}/conversation/${id}`, {
15 unmodified lines161718192015 unmodified linesreturn {messages: conversation.messages,};};15 unmodified lines16171819202115 unmodified linesreturn {messages: conversation.messages,title: conversation.title,};};
9 unmodified lines101112131415108 unmodified lines1241251261279 unmodified linesimport { trimSuffix } from "$lib/utils/trimSuffix";import { PUBLIC_SEP_TOKEN } from "$env/static/public";import { trimPrefix } from "$lib/utils/trimPrefix";import { UrlDependency } from "$lib/types/UrlDependency";export let data: PageData;108 unmodified lines});</script><ChatWindow {loading} {pending} {messages} on:message={(message) => writeMessage(message.detail)} />9 unmodified lines10111213141516108 unmodified lines1251261271281291301311321331349 unmodified linesimport { trimSuffix } from "$lib/utils/trimSuffix";import { PUBLIC_SEP_TOKEN } from "$env/static/public";import { trimPrefix } from "$lib/utils/trimPrefix";import { shareConversation } from "$lib/shareConversation";import { UrlDependency } from "$lib/types/UrlDependency";export let data: PageData;108 unmodified lines});</script><ChatWindow{loading}{pending}{messages}on:message={(message) => writeMessage(message.detail)}on:share={() => shareConversation($page.params.id, data.title)}/>
12 unmodified lines131415161712 unmodified linesreturn {messages: conversation.messages,};};12 unmodified lines13141516171812 unmodified linesreturn {messages: conversation.messages,title: conversation.title,};};
38 unmodified lines39404142434438 unmodified linesloading = false;}}</script><ChatWindow on:message={(ev) => createConversation(ev.detail)} messages={data.messages} {loading} />38 unmodified lines3940414243444546474849505152535455565758596061626338 unmodified linesloading = false;}}async function shareConversation() {const url = `${window.location.origin}${window.location.pathname}`;if (navigator.share) {navigator.share({title: data.title,text: "Share this chat with others",url,});} else {prompt("Share this link with your friends:", url);}}</script><ChatWindowon:message={(ev) => createConversation(ev.detail)}on:share={shareConversation}messages={data.messages}{loading}/>
src/lib/components/chat/ChatWindow.svelte+17-2
src/lib/shareConversation.tsAdded+32
src/routes/+layout.svelte+1-31
src/routes/conversation/[id]/+page.server.ts+1
src/routes/conversation/[id]/+page.svelte+8-1
src/routes/r/[id]/+page.server.ts+1
src/routes/r/[id]/+page.svelte+20-1