Skip to content

Commit

Permalink
Rome format
Browse files Browse the repository at this point in the history
  • Loading branch information
Adebesin-Cell committed Sep 26, 2023
1 parent bb02b85 commit d39558e
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 231 deletions.
46 changes: 23 additions & 23 deletions src/components/Settings/Elements/AddItemButton.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import * as Dialog from "@radix-ui/react-dialog";
import { useRef, useState } from "react";
import { HiDocumentText, HiFolder } from "react-icons/hi";
import TextareaAutosize from "react-textarea-autosize";
import { Prompt, usePrompts } from "../../../hooks/usePrompts";
import DialogPortal from "../../Layout/DialogPortal";
import { getUUID } from "../../../lib/getUUID";
import * as Dialog from '@radix-ui/react-dialog'
import { useRef, useState } from 'react'
import { HiDocumentText, HiFolder } from 'react-icons/hi'
import TextareaAutosize from 'react-textarea-autosize'
import { Prompt, usePrompts } from '../../../hooks/usePrompts'
import DialogPortal from '../../Layout/DialogPortal'
import { getUUID } from '../../../lib/getUUID'

export const AddItemButton = ({ isCategory }: { isCategory: boolean }) => {
const [open, setOpen] = useState(false);
const [prompts, setPrompts] = usePrompts();
const formRef = useRef<HTMLFormElement>(null);
const [open, setOpen] = useState(false)
const [prompts, setPrompts] = usePrompts()
const formRef = useRef<HTMLFormElement>(null)

const handleAdd = () => {
if (!formRef.current || !formRef.current.reportValidity()) return;
if (!formRef.current || !formRef.current.reportValidity()) return

const formData = new FormData(formRef.current);
const formData = new FormData(formRef.current)

const newName = formData.get("promptName") as string;
const newPrompt = formData.get("prompt") as string;
const newName = formData.get('promptName') as string
const newPrompt = formData.get('prompt') as string

const item = {
id: getUUID(),
name: newName,
prompt: isCategory ? undefined : newPrompt,
children: isCategory ? [] : undefined,
} as Prompt;
} as Prompt

const newPrompts = [...prompts, item];
setPrompts([]);
setPrompts(newPrompts);
const newPrompts = [...prompts, item]
setPrompts([])
setPrompts(newPrompts)

setOpen(false);
};
setOpen(false)
}

return (
<Dialog.Root open={open} onOpenChange={setOpen}>
Expand All @@ -52,7 +52,7 @@ export const AddItemButton = ({ isCategory }: { isCategory: boolean }) => {
)}
</Dialog.Trigger>
<DialogPortal
title={isCategory ? "Add New Category" : "Add New Prompt"}
title={isCategory ? 'Add New Category' : 'Add New Prompt'}
primaryAction={handleAdd}
secondaryAction={() => setOpen(false)}
primaryText="Save"
Expand Down Expand Up @@ -83,5 +83,5 @@ export const AddItemButton = ({ isCategory }: { isCategory: boolean }) => {
</form>
</DialogPortal>
</Dialog.Root>
);
};
)
}
6 changes: 2 additions & 4 deletions src/components/Settings/Elements/HistoryMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const historyMenu = () => {
const historyMenu = () => {}

}

export default historyMenu;
export default historyMenu
22 changes: 11 additions & 11 deletions src/components/Sidebar/chat/ChatHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useChatHistory } from '../../../hooks/useChatHistory';
import * as Select from '@radix-ui/react-select';
import { RiAddLine, RiTimeLine } from 'react-icons/ri';
import { generateReadableRelativeDate } from '../../../utils/generateReadableDate';
import { useChatHistory } from '../../../hooks/useChatHistory'
import * as Select from '@radix-ui/react-select'
import { RiAddLine, RiTimeLine } from 'react-icons/ri'
import { generateReadableRelativeDate } from '../../../utils/generateReadableDate'

const ChatHistory = () => {
const {
history,
setCurrentChatId,
currentChatId,
getChatHistory,
createChatHistory
} = useChatHistory();
createChatHistory,
} = useChatHistory()

const currentChat = getChatHistory(currentChatId);
const currentChat = getChatHistory(currentChatId)

return (
<div>
Expand All @@ -34,7 +34,7 @@ const ChatHistory = () => {
type='button'
className='cdx-flex cdx-items-center cdx-bg-[#3B82F6] cdx-gap-1.5 cdx-px-2.5 cdx-py-1.5 cdx-rounded-sm cdx-font-medium'
onClick={() => {
createChatHistory('New Chat');
createChatHistory('New Chat')
}}
>
<RiAddLine />
Expand Down Expand Up @@ -70,7 +70,7 @@ const ChatHistory = () => {
</Select.Content>
</Select.Root>
</div>
);
};
)
}

export default ChatHistory;
export default ChatHistory
54 changes: 27 additions & 27 deletions src/components/Sidebar/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { useEffect, useState } from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { GiMagicBroom } from 'react-icons/gi';
import { IoSend } from 'react-icons/io5';
import { HiHand } from 'react-icons/hi';
import ChatHistory from './ChatHistory';
import { useEffect, useState } from 'react'
import TextareaAutosize from 'react-textarea-autosize'
import { GiMagicBroom } from 'react-icons/gi'
import { IoSend } from 'react-icons/io5'
import { HiHand } from 'react-icons/hi'
import ChatHistory from './ChatHistory'

interface SidebarInputProps {
loading: boolean;
submitMessage: (prompt: string) => void;
clearMessages: () => void;
chatIsEmpty: boolean;
cancelRequest: () => void;
loading: boolean
submitMessage: (prompt: string) => void
clearMessages: () => void
chatIsEmpty: boolean
cancelRequest: () => void
}

export function SidebarInput({
loading,
submitMessage,
clearMessages,
chatIsEmpty,
cancelRequest
cancelRequest,
}: SidebarInputProps) {
const [text, setText] = useState('');
const [delayedLoading, setDelayedLoading] = useState(false);
const [text, setText] = useState('')
const [delayedLoading, setDelayedLoading] = useState(false)

useEffect(() => {
const handleLoadingTimeout = setTimeout(() => {
setDelayedLoading(loading);
}, 1000);
setDelayedLoading(loading)
}, 1000)
return () => {
clearTimeout(handleLoadingTimeout);
};
}, [loading]);
clearTimeout(handleLoadingTimeout)
}
}, [loading])

const handleSubmit = () => {
submitMessage(text);
setText('');
};
submitMessage(text)
setText('')
}

return (
<div className='cdx-fixed cdx-bottom-0 cdx-left-0 cdx-right-0 cdx-flex cdx-flex-col '>
Expand Down Expand Up @@ -63,13 +63,13 @@ export function SidebarInput({
disabled={loading}
className='cdx-p-3 cdx-w-full cdx-text-sm cdx-resize-none cdx-max-h-96 cdx-pb-0 cdx-bg-transparent !cdx-border-none focus:!cdx-outline-none'
onChange={(e) => {
e.preventDefault();
setText(e.target.value);
e.preventDefault()
setText(e.target.value)
}}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSubmit();
e.preventDefault()
handleSubmit()
}
}}
/>
Expand Down Expand Up @@ -100,5 +100,5 @@ export function SidebarInput({
</div>
</div>
</div>
);
)
}
36 changes: 18 additions & 18 deletions src/components/Sidebar/chat/ChatList.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { ReactMarkdown } from "react-markdown/lib/react-markdown";
import CodeBlock from "./markdown-components/CodeBlock";
import remarkGfm from "remark-gfm";
import { useEffect, useRef } from "react";
import { Table } from "./markdown-components/Table";
import remarkBreaks from "remark-breaks";
import rehypeRaw from "rehype-raw";
import { ChatMessage, ChatRole } from "../../../hooks/useCurrentChat";
import { ReactMarkdown } from 'react-markdown/lib/react-markdown'
import CodeBlock from './markdown-components/CodeBlock'
import remarkGfm from 'remark-gfm'
import { useEffect, useRef } from 'react'
import { Table } from './markdown-components/Table'
import remarkBreaks from 'remark-breaks'
import rehypeRaw from 'rehype-raw'
import { ChatMessage, ChatRole } from '../../../hooks/useCurrentChat'

interface ChatListProps {
messages: ChatMessage[];
messages: ChatMessage[]
}

const ChatList = ({ messages }: ChatListProps) => {
const containerRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (containerRef.current) {
containerRef.current.scrollTop = containerRef.current.scrollHeight;
containerRef.current.scrollTop = containerRef.current.scrollHeight
}
}, [messages]);
}, [messages])

const filteredMsgs = messages.filter((msg) => msg.role !== ChatRole.SYSTEM);
const filteredMsgs = messages.filter((msg) => msg.role !== ChatRole.SYSTEM)

return (
<div
Expand Down Expand Up @@ -48,7 +48,7 @@ const ChatList = ({ messages }: ChatListProps) => {
.filter((msg) => msg.role !== ChatRole.SYSTEM)
.map((msg, i) => (
<div
data-user={msg.role === ChatRole.USER ? "true" : undefined}
data-user={msg.role === ChatRole.USER ? 'true' : undefined}
className="markdown cdx-px-4 cdx-py-2 data-[user]:cdx-border-l-2 cdx-border-blue-400 data-[user]:cdx-bg-black/5 data-[user]:dark:cdx-bg-neutral-900/50 cdx-max-w-[400px]"
key={`${msg.timestamp}-${i}`}
>
Expand All @@ -60,13 +60,13 @@ const ChatList = ({ messages }: ChatListProps) => {
table: Table,
}}
>
{msg.content.replace(/(?<=\n\n)(?![*-])\n/gi, "&nbsp;\n ")}
{msg.content.replace(/(?<=\n\n)(?![*-])\n/gi, '&nbsp;\n ')}
</ReactMarkdown>
</div>
))
)}
</div>
);
};
)
}

export default ChatList;
export default ChatList
44 changes: 22 additions & 22 deletions src/components/Sidebar/chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect } from 'react';
import ChatList from './ChatList';
import { SidebarInput } from './ChatInput';
import { useChatCompletion } from '../../../hooks/useChatCompletion';
import { SYSTEM_PROMPT } from '../../../config/prompts';
import { Settings } from '../../../config/settings';
import { useEffect } from 'react'
import ChatList from './ChatList'
import { SidebarInput } from './ChatInput'
import { useChatCompletion } from '../../../hooks/useChatCompletion'
import { SYSTEM_PROMPT } from '../../../config/prompts'
import { Settings } from '../../../config/settings'

interface ChatProps {
settings: Settings;
chatId: string;
settings: Settings
chatId: string
}

const Chat = ({ settings, chatId }: ChatProps) => {
Expand All @@ -17,25 +17,25 @@ const Chat = ({ settings, chatId }: ChatProps) => {
apiKey: settings.chat.openAIKey!,
mode: settings.chat.mode,
systemPrompt: SYSTEM_PROMPT,
chatId
});
chatId,
})

useEffect(() => {
const handleWindowMessage = (event: MessageEvent) => {
const { action, prompt } = event.data as {
action: string;
prompt: string;
};
action: string
prompt: string
}
if (action === 'generate') {
submitQuery(prompt);
submitQuery(prompt)
}
};
window.addEventListener('message', handleWindowMessage);
}
window.addEventListener('message', handleWindowMessage)

return () => {
window.removeEventListener('message', handleWindowMessage);
};
}, []);
window.removeEventListener('message', handleWindowMessage)
}
}, [])

return (
<>
Expand All @@ -48,7 +48,7 @@ const Chat = ({ settings, chatId }: ChatProps) => {
cancelRequest={cancelRequest}
/>
</>
);
};
)
}

export default Chat;
export default Chat
22 changes: 11 additions & 11 deletions src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Auth from "./auth";
import Chat from "./chat";
import Header from "./layout/header";
import { useSettings } from "../../hooks/useSettings";
import useThemeSync from "../../hooks/useThemeSync";
import { useChatHistory } from "../../hooks/useChatHistory";
import Auth from './auth'
import Chat from './chat'
import Header from './layout/header'
import { useSettings } from '../../hooks/useSettings'
import useThemeSync from '../../hooks/useThemeSync'
import { useChatHistory } from '../../hooks/useChatHistory'

function Sidebar() {
const [settings] = useSettings();
useThemeSync();
const { currentChatId } = useChatHistory();
const [settings] = useSettings()
useThemeSync()
const { currentChatId } = useChatHistory()
return (
<div className="cdx-flex cdx-backdrop-blur-sm cdx-flex-col cdx-min-h-screen cdx-shadow-md cdx-border-l dark:!cdx-text-white dark:cdx-border-neutral-800 cdx-border-neutral-200 cdx-top-0 cdx-right-0 cdx-w-[400px] cdx-h-full dark:cdx-bg-neutral-800/90 cdx-bg-neutral-100/90">
<Header />
Expand All @@ -18,7 +18,7 @@ function Sidebar() {
<Auth />
)}
</div>
);
)
}

export default Sidebar;
export default Sidebar
Loading

0 comments on commit d39558e

Please sign in to comment.