Skip to content

Commit

Permalink
Hide avatar when message none (#5366)
Browse files Browse the repository at this point in the history
* hide avatar when message none

* add changeset

* frontend test and story

* test fix

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people committed Aug 29, 2023
1 parent b27f758 commit 0cc7e2d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/puny-wombats-tell.md
@@ -0,0 +1,6 @@
---
"@gradio/chatbot": patch
"gradio": patch
---

fix:Hide avatar when message none
3 changes: 2 additions & 1 deletion js/chatbot/Chatbot.stories.svelte
Expand Up @@ -35,7 +35,8 @@
"Can you write a function in Python?",
"```py\ndef test():\n\tprint(x)\n```"
],
["Can you do math?", "$$1+1=2$$"]
["Can you do math?", "$$1+1=2$$"],
["Can you say nothing?", null]
]}
/>
</Template>
Expand Down
17 changes: 17 additions & 0 deletions js/chatbot/Chatbot.test.ts
Expand Up @@ -36,6 +36,23 @@ describe("Chatbot", () => {
assert.exists(user);
});

test("renders none messages", async () => {
const { getAllByTestId } = await render(Chatbot, {
loading_status,
label: "chatbot",
value: [[null, null]],
root: "",
root_url: "",
latex_delimiters: [{ left: "$$", right: "$$", display: true }],
theme_mode: "dark"
});

const user = getAllByTestId("user");
const bot = getAllByTestId("bot");
assert.equal(user[0].innerHTML, "");
assert.equal(bot[0].innerHTML, "");
});

test("renders additional message as they are passed", async () => {
const { component, getAllByTestId } = await render(Chatbot, {
loading_status,
Expand Down
6 changes: 4 additions & 2 deletions js/chatbot/static/ChatBot.svelte
Expand Up @@ -96,7 +96,10 @@
{#if value !== null}
{#each value as message_pair, i}
{#each message_pair as message, j}
<div class="message-row {j == 0 ? 'user-row' : 'bot-row'}">
<div
class="message-row {j == 0 ? 'user-row' : 'bot-row'}"
class:hide={message === null}
>
{#if avatar_images[j] !== null}
<div class="avatar-container">
<img
Expand All @@ -118,7 +121,6 @@
class:latest={i === value.length - 1}
class="message {j == 0 ? 'user' : 'bot'}"
class:message-fit={!bubble_full_width}
class:hide={message === null}
class:selectable
on:click={() => handle_select(i, j, message)}
dir={rtl ? "rtl" : "ltr"}
Expand Down

0 comments on commit 0cc7e2d

Please sign in to comment.