Skip to content

Commit 62cb805

Browse files
committed
Add error messages
1 parent 30073ad commit 62cb805

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ai-chat",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"private": true,
55
"type": "module",
66
"scripts": {
@@ -21,6 +21,7 @@
2121
"markdown-it": "^14.1.0",
2222
"openai": "^4.31.0",
2323
"pinia": "^2.1.7",
24+
"uuid": "^9.0.1",
2425
"validator": "^13.11.0",
2526
"vue": "^3.4.21",
2627
"zod": "^3.22.4"
@@ -31,6 +32,7 @@
3132
"@types/highlight.js": "^10.1.0",
3233
"@types/markdown-it": "^13.0.7",
3334
"@types/node": "^20.11.25",
35+
"@types/uuid": "^9.0.8",
3436
"@types/validator": "^13.11.9",
3537
"@vitejs/plugin-vue": "^5.0.4",
3638
"@vue/eslint-config-prettier": "^8.0.0",

src/components/AppAbout.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
2-
import {FwbButton, FwbModal} from 'flowbite-vue';
3-
import {useAppStore} from '@/stores/app.store';
2+
import {FwbButton, FwbModal} from 'flowbite-vue';
3+
import {useAppStore} from '@/stores/app.store';
44
5-
const appStore = useAppStore();
5+
const appStore = useAppStore();
66
</script>
77

88
<template>
@@ -14,7 +14,7 @@ const appStore = useAppStore();
1414
<div class="flex">
1515
<div><img src="/icon-512.png" alt="Logo"/></div>
1616
<div class="ml-5"><pre class="text-xs">
17-
<b>AI Chat 1.2</b>
17+
<b>AI Chat 1.3</b>
1818

1919
Source code, additional information and contact:
2020
<a href="https://github.com/ksdev-pl/ai-chat" class="hover:text-blue-600">https://github.com/ksdev-pl/ai-chat</a>

src/components/AppContents.vue

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import MarkdownIt from 'markdown-it';
99
import hljs from 'highlight.js';
1010
import {useSettingsStore} from '@/stores/settings.store';
11-
import {FwbButton, FwbSpinner} from 'flowbite-vue';
11+
import {FwbAlert, FwbButton, FwbSpinner} from 'flowbite-vue';
12+
import {useAppStore} from '@/stores/app.store';
1213
1314
const input = ref('');
1415
const numOfInputRows = ref(1);
@@ -17,6 +18,7 @@
1718
const userScrolled = ref(false);
1819
const pending = ref(false);
1920
21+
const appStore = useAppStore();
2022
const chatStore = useChatStore();
2123
const settingsStore = useSettingsStore();
2224
@@ -50,13 +52,19 @@
5052
5153
async function onSend() {
5254
pending.value = true;
53-
userScrolled.value = false;
54-
inputTextarea.value?.blur();
55-
await chatStore.addMessage({role: Role.user, content: input.value});
56-
autoScrollDown();
57-
sendRequestForTitle(input.value);
58-
input.value = '';
59-
await sendRequestForResponse();
55+
try {
56+
userScrolled.value = false;
57+
inputTextarea.value?.blur();
58+
await chatStore.addMessage({role: Role.user, content: input.value});
59+
autoScrollDown();
60+
sendRequestForTitle(input.value);
61+
input.value = '';
62+
await sendRequestForResponse();
63+
} catch (e) {
64+
if (e instanceof Error) {
65+
appStore.addError(e.message);
66+
}
67+
}
6068
pending.value = false;
6169
}
6270
@@ -113,6 +121,14 @@
113121

114122
<template>
115123
<div class="flex flex-1 flex-col overflow-auto">
124+
<fwb-alert closable
125+
type="danger"
126+
class="mt-4 ml-4 mr-4"
127+
v-for="error in appStore.errors"
128+
:key="error.id"
129+
@close="appStore.removeError(error.id)">
130+
{{error.message}}
131+
</fwb-alert>
116132
<main class="flex-1 p-4 overflow-auto" ref="scrollingDiv" @scroll="checkIfUserScrolled()">
117133
<template v-if="chatStore.currentChat">
118134
<template v-for="(message, index) in chatStore.currentChat.messages" :key="index">

src/stores/app.store.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {defineStore} from 'pinia';
22
import {ref} from 'vue';
3+
import {v4 as uuidv4} from 'uuid';
34

45
export const useAppStore = defineStore('app', () => {
56
const isSidebarVisible = ref(true);
67
const isAboutVisible = ref(false);
8+
const errors = ref<{id: string, message: string}[]>([]);
79

810
function toggleSidebar() {
911
isSidebarVisible.value = !isSidebarVisible.value;
@@ -17,11 +19,22 @@ export const useAppStore = defineStore('app', () => {
1719
isAboutVisible.value = false;
1820
}
1921

22+
function addError(error: string) {
23+
errors.value.push({id: uuidv4(), message: error});
24+
}
25+
26+
function removeError(id: string) {
27+
errors.value = errors.value.filter(error => error.id !== id);
28+
}
29+
2030
return {
2131
isSidebarVisible,
2232
isAboutVisible,
33+
errors,
2334
toggleSidebar,
2435
showAbout,
25-
hideAbout
36+
hideAbout,
37+
addError,
38+
removeError
2639
};
2740
});

0 commit comments

Comments
 (0)