Skip to content

Commit 4b5444d

Browse files
author
Jicheng Lu
committed
add video component
1 parent 01f31af commit 4b5444d

File tree

6 files changed

+112
-20
lines changed

6 files changed

+112
-20
lines changed

package-lock.json

Lines changed: 26 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"svelte-json-tree": "^2.2.0",
6464
"svelte-jsoneditor": "^0.21.1",
6565
"svelte-link": "^1.4.0",
66+
"svelte-player": "^0.0.21",
6667
"svelte-select": "^5.7.0",
6768
"svelte-splitpanes": "^0.8.0",
6869
"svelte-viewport-info": "^1.0.1",

src/lib/helpers/enums.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const richType = {
2424
}
2525
export const RichType = Object.freeze(richType);
2626

27+
const elementType = {
28+
Text: "text",
29+
Video: "video"
30+
};
31+
export const ElementType = Object.freeze(elementType);
32+
2733
const contentLogSource = {
2834
UserInput: "user input",
2935
Prompt: "prompt",

src/lib/scss/custom/pages/_chat.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,44 @@
169169
flex-direction: column;
170170
width: 80%;
171171

172+
.video-group-container {
173+
display: flex;
174+
flex-wrap: wrap;
175+
gap: 5px;
176+
177+
.video-element-card {
178+
border: none;
179+
box-shadow: none;
180+
flex: 1 1 400px;
181+
182+
.card-body {
183+
padding: 0 !important;
184+
}
185+
186+
.video-element-title {
187+
font-size: 1.1em;
188+
font-weight: 700;
189+
padding-left: 5px;
190+
padding-top: 10px;
191+
padding-bottom: 10px;
192+
margin-bottom: 5px;
193+
width: 100%;
194+
overflow: hidden;
195+
white-space: nowrap;
196+
text-overflow: ellipsis;
197+
}
198+
199+
.video-element-player {
200+
aspect-ratio: 16 / 9;
201+
202+
video, iframe {
203+
border-radius: 10px;
204+
height: 100%;
205+
}
206+
}
207+
}
208+
}
209+
172210
.button-group-container {
173211
display: flex;
174212
flex-wrap: wrap;

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@
940940
<button
941941
type="submit"
942942
class="btn btn-primary btn-rounded waves-effect waves-light"
943-
disabled={isSendingMsg || isThinking}
943+
disabled={isSendingMsg || isThinking || lastBotMsg?.rich_content?.editor == EditorType.None}
944944
on:click={startListen}
945945
>
946946
<i class="mdi mdi-{microphoneIcon} md-36" />
@@ -951,7 +951,7 @@
951951
<ChatTextArea
952952
className={'chat-input'}
953953
bind:text={text}
954-
disabled={isSendingMsg || isThinking}
954+
disabled={isSendingMsg || isThinking || lastBotMsg?.rich_content?.editor == EditorType.None}
955955
editor={lastBotMsg?.rich_content?.editor || ''}
956956
onKeyDown={e => onSendMessage(e)}
957957
/>

src/routes/chat/[agentId]/[conversationId]/richContent/rc-plain-options.svelte

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script>
22
import { onMount } from "svelte";
3+
import SveltePlayer from "svelte-player";
4+
import { Card, CardBody } from "@sveltestrap/sveltestrap";
5+
import { ElementType } from "$lib/helpers/enums";
36
47
/** @type {boolean} */
58
export let isMultiSelect = false;
@@ -23,24 +26,29 @@
2326
/** @type {string[]} */
2427
let payloadAnswers = [];
2528
/** @type {any[]} */
26-
let localOptions = [];
29+
let plainOptions = [];
30+
/** @type {any[]} */
31+
let videoOptions = [];
2732
2833
onMount(() => {
2934
reset();
30-
localOptions = collectOptions(options);
35+
collectOptions(options);
3136
});
3237
3338
/** @param {any[]} options */
3439
function collectOptions(options) {
35-
const res = options?.filter(op => !!op.title && !!op.payload)?.map(op => {
40+
const innerOptions = options?.filter(op => !!op.title && !!op.payload) || [];
41+
42+
videoOptions = innerOptions?.filter(op => op.type == ElementType.Video);
43+
plainOptions = innerOptions?.filter(op => op.type != ElementType.Video)?.map(op => {
3644
return {
3745
title: op.title,
3846
payload: op.payload,
47+
is_primary: op.is_primary,
48+
is_secondary: op.is_secondary,
3949
isClicked: false
4050
};
4151
}) || [];
42-
43-
return res;
4452
}
4553
4654
/**
@@ -54,7 +62,7 @@
5462
if (!isMultiSelect) {
5563
innerConfirm(option?.title, option?.payload);
5664
} else {
57-
localOptions = localOptions.map((op, idx) => {
65+
plainOptions = plainOptions.map((op, idx) => {
5866
if (idx === index) {
5967
op.isClicked = !op.isClicked;
6068
if (op.isClicked) {
@@ -91,18 +99,38 @@
9199
}
92100
93101
function reset() {
94-
localOptions = [];
102+
plainOptions = [];
103+
videoOptions = [];
95104
titleAnswers = [];
96105
payloadAnswers = [];
97106
}
98107
99108
</script>
100109
101-
{#if localOptions.length > 0}
110+
{#if videoOptions.length > 0}
111+
<div>
112+
<div class="video-group-container">
113+
{#each videoOptions as video, index}
114+
<Card class="video-element-card">
115+
<CardBody>
116+
<div class="video-element-title">
117+
{video.title}
118+
</div>
119+
<div class="video-element-player">
120+
<SveltePlayer url={video.payload} controls />
121+
</div>
122+
</CardBody>
123+
</Card>
124+
{/each}
125+
</div>
126+
</div>
127+
{/if}
128+
129+
{#if plainOptions.length > 0}
102130
<div class="button-group-container">
103-
{#each localOptions as option, index}
131+
{#each plainOptions as option, index}
104132
<button
105-
class="btn btn-outline-primary btn-rounded btn-sm m-1"
133+
class={`btn btn-rounded btn-sm m-1 ${option.is_secondary ? 'btn-outline-secondary': 'btn-outline-primary'}`}
106134
class:active={!!option.isClicked}
107135
disabled={disableOption}
108136
on:click={(e) => handleClickOption(e, option, index)}
@@ -114,7 +142,7 @@
114142
<button
115143
class="btn btn-outline-success btn-rounded btn-sm m-1"
116144
name="confirm"
117-
disabled={disableOption || localOptions.every(x => !!!x.isClicked)}
145+
disabled={disableOption || plainOptions.every(x => !!!x.isClicked)}
118146
on:click={(e) => handleConfirm(e)}
119147
>
120148
{confirmBtnText || 'Continue'}

0 commit comments

Comments
 (0)