Skip to content

Commit

Permalink
Merge pull request #100 from n4ze3m/next
Browse files Browse the repository at this point in the history
1.0.2 - white screen bug fix
  • Loading branch information
n4ze3m authored Oct 4, 2023
2 parents 76da28b + 2d9a37b commit 6d77878
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app",
"private": true,
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
24 changes: 22 additions & 2 deletions app/ui/src/components/Bot/Playground/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const PlaygroundChat = () => {
const [sourceData, setSourceData] = React.useState<any>(null);
const [openSource, setOpenSource] = React.useState(false);
const [fileType, setFileType] = React.useState<
"pdf" | "mp3" | "mp4" | "other"
"pdf" | "mp3" | "mp4" | "other" | "lang"
>("other");

React.useEffect(() => {
Expand Down Expand Up @@ -59,7 +59,21 @@ export const PlaygroundChat = () => {
} else if (fileExtension === "mp4") {
setFileType("mp4");
} else {
setFileType("other");
const isExist =
COMMON_PROGRAMMING_LANGUAGES_EXTENSIONS[
`${
source?.metadata?.path || source?.metadata?.source
}`
.split(".")
.pop() ||
("" as keyof typeof COMMON_PROGRAMMING_LANGUAGES_EXTENSIONS)
];

if (isExist) {
setFileType("lang");
} else {
setFileType("other");
}
}
setSourceData(source);
setOpenSource(true);
Expand Down Expand Up @@ -107,7 +121,13 @@ export const PlaygroundChat = () => {
</div>
</>
)}

{fileType === "other" && (
<>
<p className="text-gray-500 text-sm">{sourceData?.pageContent}</p>
</>
)}
{fileType === "lang" && (
<>
<SyntaxHighlighter
startingLineNumber={sourceData?.metadata?.loc?.lines?.from}
Expand Down
6 changes: 3 additions & 3 deletions app/widget/src/hooks/useChatId.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState, useEffect } from "react";

import { generateUUID } from "../utils/uuid";
const useChatId = () => {
const [chatId, setChatId] = useState<string>("");

const resetChatId = () => {
const newChatId = crypto.randomUUID();
const newChatId = generateUUID();
localStorage.removeItem("DS_MESSAGE");
localStorage.removeItem("DS_HISTORY");
localStorage.setItem("DS_CHAT_ID", newChatId);
Expand All @@ -17,7 +17,7 @@ const useChatId = () => {
if (storedChatId) {
setChatId(storedChatId);
} else {
const newChatId = crypto.randomUUID();
const newChatId = generateUUID();
localStorage.setItem("DS_CHAT_ID", newChatId);
setChatId(newChatId);
}
Expand Down
21 changes: 21 additions & 0 deletions app/widget/src/utils/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// this is polyfill for crypto.randomUUID
const generateUniqSerial = () => {
return "xxxx-xxxx-xxx-xxxx".replace(/[x]/g, () => {
const r = Math.floor(Math.random() * 16);
return r.toString(16);
});
};

export function generateUUID() {
try {
if (crypto.randomUUID) {
return crypto.randomUUID();
} else {
console.log("crypto.randomUUID not supported");
return generateUniqSerial();
}
} catch (e) {
console.log("crypto.randomUUID not supported");
return generateUniqSerial();
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dialoqbase",
"version": "1.0.1",
"version": "1.0.2",
"description": "Create chatbots with ease",
"scripts": {
"ui:dev": "pnpm run --filter ui dev",
Expand Down

0 comments on commit 6d77878

Please sign in to comment.