Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vote buttons styling based on vote_status #81

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pykoi/frontend/dist/assets/index-761f2ce2.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pykoi/frontend/dist/assets/index-857a4a8b.css

This file was deleted.

4 changes: 2 additions & 2 deletions pykoi/frontend/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Svelte</title>
<script type="module" crossorigin src="/assets/index-6fbf13ee.js"></script>
<link rel="stylesheet" href="/assets/index-857a4a8b.css">
<script type="module" crossorigin src="/assets/index-6c166968.js"></script>
<link rel="stylesheet" href="/assets/index-761f2ce2.css">
</head>
<body>
<div id="app"></div>
Expand Down
28 changes: 12 additions & 16 deletions pykoi/frontend/src/lib/Chatbots/Chatbot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { select } from "d3-selection";
import { writable } from "svelte/store";
import DownloadModal from "./Components/DownloadModal.svelte";
import Answer from "./Components/Answer.svelte";

let showModal = false;

Expand Down Expand Up @@ -173,22 +174,7 @@
<p>{message.question}</p>
</div>
<div class="answers">
<div class="answer">
<h5 class="bold">Response:</h5>
<p>{message.answer}</p>
{#if feedback}
<div class="feedback-buttons">
<button
on:click={(event) => logVote(event, "up", index)}
class="small-button thumbs-up">👍</button
>
<button
on:click={(event) => logVote(event, "down", index)}
class="small-button thumbs-down">👎</button
>
</div>
{/if}
</div>
<Answer {feedback} {message} {index} title={true}/>
</div>
</div>
</div>
Expand Down Expand Up @@ -450,4 +436,14 @@
background: inherit;
clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}

.vote-selected {
border: "3px solid black";
opacity: 1;
}

.vote-not-selected {
border: "3px solid transparent";
opacity: 0.65;
}
</style>
66 changes: 42 additions & 24 deletions pykoi/frontend/src/lib/Chatbots/Components/Answer.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script>
import { chatLog } from "../../../store.js";
import { select } from "d3-selection";

export let message = {};
export let feedback = false;
export let index = 0;
export let title = false;

async function insertVote(feedbackUpdate) {
const response = await fetch("/chat/rag_table/update", {
Expand All @@ -17,6 +17,7 @@

if (response.ok) {
console.log("response", response);
message.vote_status = feedbackUpdate.vote_status;
} else {
const err = await response.text();
alert(err);
Expand All @@ -30,36 +31,43 @@
id: index + 1, // increment bc sqlite 1-indexed
vote_status: vote,
};

insertVote(feedbackUpdate);

select(event.currentTarget.parentNode)
.selectAll("button")
.style("border", "3px solid transparent")
.style("opacity", 0.65);
select(event.currentTarget)
.style("border", "3px solid var(--black)")
.style("opacity", 1);
}
console.log("Answer", message.vote_status);
</script>

<div>
{message.answer}
<div class="answer">
{#if title}
<h5 class="bold">Response:</h5>
{/if}
<p>{message.answer}</p>
{#if feedback}
<div class="feedback-buttons">
<button
on:click={(event) => logVote(event, "up", index)}
class="small-button thumbs-up"
class:vote-selected={message.vote_status === "up"}
class:vote-not-selected={message.vote_status === "down"}
>👍</button
>
<button
on:click={(event) => logVote(event, "down", index)}
class="small-button thumbs-down"
class:vote-selected={message.vote_status === "down"}
class:vote-not-selected={message.vote_status === "up"}
>👎</button
>
</div>
{/if}
</div>
{#if feedback}
<div class="feedback-buttons">
<button
on:click={(event) => logVote(event, "up", index)}
class="small-button thumbs-up">👍</button
>
<button
on:click={(event) => logVote(event, "down", index)}
class="small-button thumbs-down">👎</button
>
</div>
{/if}

<style>
.answer {
display: inline-block;
text-align: left;
padding: 10px;
border: 1px solid var(--black);
}
.small-button {
margin-left: 10px;
background: none;
Expand Down Expand Up @@ -92,4 +100,14 @@
.thumbs-down::selection {
background: var(--red);
}

.vote-selected {
border: 3px solid black;
opacity: 1;
}

.vote-not-selected {
border: 3px solid transparent;
opacity: 0.65;
}
</style>