Skip to content

Commit

Permalink
Merge pull request #2318 from idomamia/feat/rtl-layout-chat-support
Browse files Browse the repository at this point in the history
Add RTL layout chat support
  • Loading branch information
tjbck committed May 18, 2024
2 parents 0492540 + 27c59d9 commit 9e60d03
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/lib/components/chat/MessageInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@
}}
/>
<form
dir={$settings?.chatDirection}
class=" flex flex-col relative w-full rounded-3xl px-1.5 bg-gray-50 dark:bg-gray-850 dark:text-gray-100"
on:submit|preventDefault={() => {
submitPrompt(prompt, user);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/chat/Messages/CodeBlock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ __builtins__.input = input`);
</script>

{#if code}
<div class="mb-4">
<div class="mb-4" dir="ltr">
<div
class="flex justify-between bg-[#202123] text-white text-xs px-4 pt-1 pb-0.5 rounded-t-lg overflow-x-auto"
>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/chat/Messages/Name.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class=" self-center font-bold mb-0.5 line-clamp-1">
<div class=" self-center font-bold mb-0.5 line-clamp-1 contents">
<slot />
</div>
4 changes: 3 additions & 1 deletion src/lib/components/chat/Messages/ProfileImage.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script lang="ts">
import { settings } from '$lib/stores';
import { WEBUI_BASE_URL } from '$lib/constants';
export let src = '/user.png';
</script>

<div class=" mr-3">
<div class={$settings?.chatDirection === 'LTR' ? "mr-3" : "ml-3"}>
<img
crossorigin="anonymous"
src={src.startsWith(WEBUI_BASE_URL) ||
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/chat/Messages/ResponseMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
<CitationsModal bind:show={showCitationModal} citation={selectedCitation} />

{#key message.id}
<div class=" flex w-full message-{message.id}" id="message-{message.id}">
<div class=" flex w-full message-{message.id}" id="message-{message.id}" dir="{$settings.chatDirection}">
<ProfileImage
src={modelfiles[message.model]?.imageUrl ??
($i18n.language === 'dg-DG' ? `/doge.png` : `${WEBUI_BASE_URL}/static/favicon.png`)}
Expand Down Expand Up @@ -495,7 +495,7 @@
class=" flex justify-start overflow-x-auto buttons text-gray-600 dark:text-gray-500"
>
{#if siblings.length > 1}
<div class="flex self-center">
<div class="flex self-center" dir="ltr">
<button
class="self-center p-1 hover:bg-black/5 dark:hover:bg-white/5 dark:hover:text-white hover:text-black rounded-md transition"
on:click={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/chat/Messages/UserMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
};
</script>

<div class=" flex w-full user-message">
<div class=" flex w-full user-message" dir="{$settings.chatDirection}">
{#if !($settings?.chatBubble ?? true)}
<ProfileImage
src={message.user
Expand Down
25 changes: 25 additions & 0 deletions src/lib/components/chat/Settings/Interface.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
let promptSuggestions = [];
let showUsername = false;
let chatBubble = true;
let chatDirection: 'LTR' | 'RTL' = 'LTR';
const toggleSplitLargeChunks = async () => {
splitLargeChunks = !splitLargeChunks;
Expand Down Expand Up @@ -76,6 +77,11 @@
}
};
const toggleChangeChatDirection = async () => {
chatDirection = chatDirection === 'LTR' ? 'RTL' : 'LTR';
saveSettings({chatDirection});
};
const updateInterfaceHandler = async () => {
if ($user.role === 'admin') {
promptSuggestions = await setDefaultPromptSuggestions(localStorage.token, promptSuggestions);
Expand Down Expand Up @@ -114,6 +120,7 @@
chatBubble = settings.chatBubble ?? true;
fullScreenMode = settings.fullScreenMode ?? false;
splitLargeChunks = settings.splitLargeChunks ?? false;
chatDirection = settings.chatDirection ?? 'LTR';
});
</script>

Expand Down Expand Up @@ -255,6 +262,24 @@
</div>
</div>

<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Chat direction')}</div>

<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={toggleChangeChatDirection}
type="button"
>
{#if chatDirection === 'LTR'}
<span class="ml-2 self-center">{$i18n.t('LTR')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('RTL')}</span>
{/if}
</button>
</div>
</div>

<hr class=" dark:border-gray-700" />

<div>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/i18n/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"Change Password": "",
"Chat": "",
"Chat Bubble UI": "",
"Chat direction": "",
"Chat History": "",
"Chat History is off for this browser.": "",
"Chats": "",
Expand Down Expand Up @@ -246,6 +247,7 @@
"Light": "",
"Listening...": "",
"LLMs can make mistakes. Verify important information.": "",
"LTR": "",
"Made by OpenWebUI Community": "",
"Make sure to enclose them with": "",
"Manage LiteLLM Models": "",
Expand Down Expand Up @@ -361,6 +363,7 @@
"Role": "",
"Rosé Pine": "",
"Rosé Pine Dawn": "",
"RTL": "",
"Save": "",
"Save & Create": "",
"Save & Update": "",
Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Settings = {
notificationEnabled?: boolean;
title?: TitleSettings;
splitLargeDeltas?: boolean;
chatDirection: 'LTR' | 'RTL';

system?: string;
requestFormat?: string;
Expand Down

0 comments on commit 9e60d03

Please sign in to comment.