Skip to content

Commit

Permalink
Feat: right side quick filters will be applied based on the main filters
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmullapudi committed Nov 25, 2024
1 parent d85316a commit bc720ec
Show file tree
Hide file tree
Showing 47 changed files with 709 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class ConversationHistoryService {
const projects: Project[] = [];

// Get previous conversation history message and response
let previousHistory = null;
let previousHistory: ConversationHistory[] = null;
if (conversationHistory.conversationId) {
const previousMessages = await this.prisma.conversationHistory.findMany({
where: {
Expand All @@ -109,14 +109,9 @@ export class ConversationHistoryService {
orderBy: {
createdAt: 'desc',
},
take: 1,
take: 2,
});

if (previousMessages.length > 0) {
previousHistory = {
conversation: previousMessages[0],
};
}
previousHistory = previousMessages;
}

return {
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/modules/conversation/conversation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ export class ConversationService {
data: {
workspaceId,
userId,
title: conversationData.message.substring(0, 100),
ConversationHistory: {
create: {
userId,
...conversationData,
},
},
},
include: {
ConversationHistory: true,
},
});
}

Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/common/layouts/content-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const ContentBox = observer(
return (
<main
className={cn(
'p-3 pt-0 pl-0 flex flex-col h-[calc(100vh_-_48px)]',
'p-3 pt-0 pl-0 h-[calc(100vh_-_48px)]',
applicationStore.sidebarCollapsed && 'pl-3',
className,
)}
>
<div className="bg-background-2 h-full rounded-lg overflow-hidden shadow flex flex-col">
<div className="bg-background-2 h-full rounded-lg overflow-hidden shadow">
{children}
</div>
</main>
Expand Down
4 changes: 4 additions & 0 deletions apps/webapp/src/common/user-avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export function UserAvatar({
showFull = false,
className,
}: UserAvatarProps) {
if (!user) {
return null;
}

return (
<Tooltip>
<TooltipTrigger asChild>
Expand Down
16 changes: 12 additions & 4 deletions apps/webapp/src/hooks/conversations/use-conversation-history.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { sort } from 'fast-sort';
import React from 'react';

import type { ConversationHistoryType } from 'common/types';

import { useContextStore } from 'store/global-context-provider';

export const useConversationHistory = (conversationId: string) => {
const { conversationHistoryStore } = useContextStore();

return React.useMemo(() => {
return conversationHistoryStore.getConversationHistoryForConversation(
conversationId,
);
const conversationHistory =
conversationHistoryStore.getConversationHistoryForConversation(
conversationId,
);
return sort(conversationHistory).asc(
(co: ConversationHistoryType) => new Date(co.createdAt),
) as ConversationHistoryType[];

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [conversationId]);
}, [conversationId, conversationHistoryStore.conversationHistory.length]);
};
32 changes: 0 additions & 32 deletions apps/webapp/src/modules/ai/ai-conversation.tsx

This file was deleted.

Empty file.
51 changes: 14 additions & 37 deletions apps/webapp/src/modules/ai/ai.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { UserTypeEnum } from '@tegonhq/types';
import { Button } from '@tegonhq/ui/components/button';
import { Textarea } from '@tegonhq/ui/components/textarea';
import { AddLine, SendLine } from '@tegonhq/ui/icons';
import { AddLine } from '@tegonhq/ui/icons';
import { AI as AII } from '@tegonhq/ui/icons';
import { HistoryIcon } from 'lucide-react';
import { observer } from 'mobx-react-lite';
import { useState } from 'react';

import { useCreateConversationMutation } from 'services/conversations';
import { useContextStore } from 'store/global-context-provider';

import { AIConversation } from './ai-conversation';
import { Conversation } from './conversation';
import { AIHistoryDropdown } from './history-dropdown';

export const AI = observer(() => {
const { mutate: createConversation } = useCreateConversationMutation({});
const [text, setText] = useState('');
const { commonStore } = useContextStore();

return (
<div className="flex flex-col h-full">
Expand All @@ -24,40 +20,21 @@ export const AI = observer(() => {
</div>

<div className="flex gap-1 items-center">
<Button variant="ghost">
<Button
variant="ghost"
onClick={() => {
commonStore.update({ currentConversationId: undefined });
}}
>
<AddLine size={16} />
</Button>

<Button variant="ghost">
<HistoryIcon size={16} />
</Button>
<AIHistoryDropdown />
</div>
</div>
<div className="grow">
<AIConversation />
</div>

<div className="p-3 px-5 relative">
<Textarea
className="bg-transparent border border-border max-h-[500px]"
rows={4}
autoFocus
onChange={(e) => setText(e.currentTarget.value)}
placeholder="Ask AI anything..."
/>
<Button
variant="ghost"
className="transition-all duration-500 ease-in-out my-2 absolute bottom-2 right-6"
type="submit"
onClick={() => {
createConversation({
message: text,
userType: UserTypeEnum.User,
});
}}
>
<SendLine size={20} />
</Button>
<div className="grow overflow-hidden">
<Conversation />
</div>
</div>
);
Expand Down
61 changes: 61 additions & 0 deletions apps/webapp/src/modules/ai/conversation-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { UserTypeEnum } from '@tegonhq/types';
import { defaultExtensions } from '@tegonhq/ui/components/ui/editor/editor-extensions';
import { AI } from '@tegonhq/ui/icons';
import { Editor } from '@tiptap/core';
import { observer } from 'mobx-react-lite';
import React, { useEffect, useRef } from 'react';

import type { ConversationHistoryType } from 'common/types';
import { UserAvatar } from 'common/user-avatar';

import { useUserData } from 'hooks/users';

interface AIConversationItemProps {
conversationHistory: ConversationHistoryType;
}

export const ConversationItem = observer(
({ conversationHistory }: AIConversationItemProps) => {
const { user } = useUserData(conversationHistory.userId);
const id = `a${conversationHistory.id.replace(/-/g, '')}`;
const editorRef = useRef<Editor | null>(null);

useEffect(() => {
const element = document.getElementById(id);
let editor: Editor;

if (element) {
editor = new Editor({
element,
extensions: defaultExtensions,
editable: false,
});
editorRef.current = editor;

editor.commands.setContent(conversationHistory.message, false, {
preserveWhitespace: true,
});
}
// Clean up on unmount
return () => {
editor && editor.destroy();
};
}, [id, conversationHistory.message]);

const getIcon = () => {
if (conversationHistory.userType === UserTypeEnum.User) {
return <UserAvatar user={user} />;
}

return <AI size={16} />;
};

return (
<div className="flex px-3 gap-2 border-b border-border py-4">
<div className="shrink-0">{getIcon()}</div>

<div id={id}></div>
</div>
);
},
);
36 changes: 36 additions & 0 deletions apps/webapp/src/modules/ai/conversation-textarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Button } from '@tegonhq/ui/components/ui/button';
import { Textarea } from '@tegonhq/ui/components/ui/textarea';
import { SendLine } from '@tegonhq/ui/icons';
import { useState } from 'react';

interface ConversationTextareaProps {
onSend: (value: string) => void;
}

export function ConversationTextarea({ onSend }: ConversationTextareaProps) {
const [text, setText] = useState('');

return (
<div className="p-3 px-5 relative">
<Textarea
className="bg-transparent border border-border max-h-[500px]"
rows={1}
value={text}
autoFocus
onChange={(e) => setText(e.currentTarget.value)}
placeholder="Ask AI anything..."
/>
<Button
variant="ghost"
className="transition-all duration-500 ease-in-out my-2 absolute bottom-2 right-6"
type="submit"
onClick={() => {
onSend(text);
setText('');
}}
>
<SendLine size={20} />
</Button>
</div>
);
}
Loading

0 comments on commit bc720ec

Please sign in to comment.