forked from huggingface/chat-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add mobile menu * fix * Auto-naming convos by summarizing them (huggingface#58) * Auto-naming convos by summarizing them * Ok let's do it only on first message then * revamp * location.reload for now * avoid huge titles * fix messages width * add community feedback to nav * fix tokens keeping coming even when changing conversation (huggingface#62) * favicon * 🐛 Fix generating bug (huggingface#68) * 🐛 Fix redirect after delete * ✨ Remove endoftext (huggingface#70) * 🐛 Remove sanitized < (huggingface#71) * 🩹 Change 301 to 302 in case we want to use the route for something else * 🩹 Use passed fetch cc @julien-c When using @huggingface/infernece in the backend we'll need to make it support custom fetch as well * refactor mobile menu + improve accessibility * fix missing menu on md size + regression share button on hover * fix chat title truncate on mobile * fix layout max-width on mobile * use a single event dispatcher instead of 2 * add missing type="button" * remove duplicated wrapper after merge conflict --------- Co-authored-by: Victor Mustar <[email protected]> Co-authored-by: Julien Chaumond <[email protected]> Co-authored-by: Eliott C <[email protected]>
- Loading branch information
1 parent
229d4b4
commit 4dae10f
Showing
5 changed files
with
176 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script lang="ts"> | ||
import { navigating } from "$app/stores"; | ||
import { createEventDispatcher } from "svelte"; | ||
import { browser } from "$app/environment"; | ||
import { base } from "$app/paths"; | ||
import CarbonClose from "~icons/carbon/close"; | ||
import CarbonAdd from "~icons/carbon/add"; | ||
import CarbonTextAlignJustify from "~icons/carbon/text-align-justify"; | ||
export let isOpen = false; | ||
export let title: string; | ||
$: title = title || "New Chat"; | ||
let closeEl: HTMLButtonElement; | ||
let openEl: HTMLButtonElement; | ||
const dispatch = createEventDispatcher(); | ||
$: if ($navigating) { | ||
dispatch("toggle", false); | ||
} | ||
$: if (isOpen && closeEl) { | ||
closeEl.focus(); | ||
} else if (!isOpen && browser && document.activeElement === closeEl) { | ||
openEl.focus(); | ||
} | ||
</script> | ||
|
||
<nav class="md:hidden flex items-center h-12 border-b px-4 justify-between dark:border-gray-800"> | ||
<button | ||
type="button" | ||
class="flex items-center justify-center w-9 h-9 -ml-3 shrink-0" | ||
on:click={() => dispatch("toggle", true)} | ||
aria-label="Open menu" | ||
bind:this={openEl}><CarbonTextAlignJustify /></button | ||
> | ||
<span class="px-4 truncate">{title}</span> | ||
<a href={base || "/"} class="flex items-center justify-center w-9 h-9 -mr-3 shrink-0" | ||
><CarbonAdd /></a | ||
> | ||
</nav> | ||
<nav | ||
class="fixed inset-0 z-50 grid grid-rows-[auto,auto,1fr,auto] grid-cols-1 max-h-screen bg-white dark:bg-gray-900 bg-gradient-to-l from-gray-50 dark:from-gray-800/30 {isOpen | ||
? 'block' | ||
: 'hidden'}" | ||
> | ||
<div class="flex items-center px-4 h-12"> | ||
<button | ||
type="button" | ||
class="flex items-center justify-center ml-auto w-9 h-9 -mr-3" | ||
on:click={() => dispatch("toggle", false)} | ||
aria-label="Close menu" | ||
bind:this={closeEl}><CarbonClose /></button | ||
> | ||
</div> | ||
<slot /> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<script lang="ts"> | ||
import { base } from "$app/paths"; | ||
import { page } from "$app/stores"; | ||
import { createEventDispatcher } from "svelte"; | ||
import CarbonTrashCan from "~icons/carbon/trash-can"; | ||
import CarbonExport from "~icons/carbon/export"; | ||
import { switchTheme } from "$lib/switchTheme"; | ||
const dispatch = createEventDispatcher<{ | ||
shareConversation: { id: string; title: string }; | ||
deleteConversation: string; | ||
}>(); | ||
export let conversations: Array<{ | ||
id: string; | ||
title: string; | ||
}> = []; | ||
</script> | ||
|
||
<div class="flex-none sticky top-0 p-3 flex flex-col"> | ||
<a | ||
href={base || "/"} | ||
class="border px-12 py-2.5 rounded-lg shadow bg-white dark:bg-gray-700 dark:border-gray-600 text-center" | ||
> | ||
New Chat | ||
</a> | ||
</div> | ||
<div class="flex flex-col overflow-y-auto p-3 -mt-3 gap-1"> | ||
{#each conversations as conv} | ||
<a | ||
data-sveltekit-noscroll | ||
href="{base}/conversation/{conv.id}" | ||
class="group pl-3 pr-2 h-11 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-1.5 {conv.id === | ||
$page.params.id | ||
? 'bg-gray-100 dark:bg-gray-700' | ||
: ''}" | ||
> | ||
<div class="flex-1 truncate">{conv.title}</div> | ||
|
||
<button | ||
type="button" | ||
class="flex md:hidden md:group-hover:flex w-5 h-5 items-center justify-center rounded" | ||
title="Share conversation" | ||
on:click|preventDefault={() => | ||
dispatch("shareConversation", { id: conv.id, title: conv.title })} | ||
> | ||
<CarbonExport class="text-gray-400 hover:text-gray-500 dark:hover:text-gray-300 text-xs" /> | ||
</button> | ||
|
||
<button | ||
type="button" | ||
class="flex md:hidden md:group-hover:flex w-5 h-5 items-center justify-center rounded" | ||
title="Delete conversation" | ||
on:click|preventDefault={() => dispatch("deleteConversation", conv.id)} | ||
> | ||
<CarbonTrashCan | ||
class="text-gray-400 hover:text-gray-500 dark:hover:text-gray-300 text-xs" | ||
/> | ||
</button> | ||
</a> | ||
{/each} | ||
</div> | ||
<div class="flex flex-col p-3 gap-2"> | ||
<button | ||
on:click={switchTheme} | ||
type="button" | ||
class="text-left flex items-center first-letter:capitalize truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700" | ||
> | ||
Theme | ||
</button> | ||
<a | ||
href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions" | ||
class="text-left flex items-center first-letter:capitalize truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700" | ||
> | ||
Community feedback | ||
</a> | ||
<a | ||
href={base} | ||
class="truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700" | ||
> | ||
Settings | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function switchTheme() { | ||
const { classList } = document.querySelector("html") as HTMLElement; | ||
if (classList.contains("dark")) { | ||
classList.remove("dark"); | ||
localStorage.theme = "light"; | ||
} else { | ||
classList.add("dark"); | ||
localStorage.theme = "dark"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters