-
Notifications
You must be signed in to change notification settings - Fork 416
Feature chat (Beta version) #1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d83257
chat in progress...
duckduckhero 2d35289
before integrating apply function
duckduckhero e62c796
commit preparation
duckduckhero 4d5018c
Merge branch 'main' of https://github.com/fastrepl/hyprnote into feat…
duckduckhero 38ac741
ran tests and made it
duckduckhero 0f707ca
snapshot
yujonglee e20b4d1
fixed some stuff with chat branch
duckduckhero cc6acce
Merge branch 'feature-chat' of https://github.com/fastrepl/hyprnote i…
duckduckhero 5ad03cb
changed some stuff
duckduckhero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
apps/desktop/src/components/right-panel/components/chat/markdown-card.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| import { commands as miscCommands } from "@hypr/plugin-misc"; | ||
| import Renderer from "@hypr/tiptap/renderer"; | ||
| import { Button } from "@hypr/ui/components/ui/button"; | ||
| import { CopyIcon, FileTextIcon, PlayIcon } from "lucide-react"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| interface MarkdownCardProps { | ||
| content: string; | ||
| isComplete: boolean; | ||
| sessionTitle?: string; | ||
| onApplyMarkdown?: (markdownContent: string) => void; | ||
| hasEnhancedNote?: boolean; | ||
| } | ||
|
|
||
| export function MarkdownCard( | ||
| { content, isComplete, sessionTitle, onApplyMarkdown, hasEnhancedNote = false }: MarkdownCardProps, | ||
| ) { | ||
| const [htmlContent, setHtmlContent] = useState<string>(""); | ||
| const [isCopied, setIsCopied] = useState(false); | ||
|
|
||
| const handleApplyClick = () => { | ||
| if (onApplyMarkdown) { | ||
| onApplyMarkdown(content); | ||
| } | ||
| }; | ||
|
|
||
| const handleCopyClick = async () => { | ||
| try { | ||
| await navigator.clipboard.writeText(content); | ||
| setIsCopied(true); | ||
| setTimeout(() => setIsCopied(false), 2000); // Reset after 2 seconds | ||
| } catch (error) { | ||
| console.error("Failed to copy to clipboard:", error); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const convertMarkdown = async () => { | ||
| try { | ||
| let html = await miscCommands.opinionatedMdToHtml(content); | ||
|
|
||
| // Clean up spacing | ||
| html = html | ||
| .replace(/<p>\s*<\/p>/g, "") | ||
| .replace(/<p>\u00A0<\/p>/g, "") | ||
| .replace(/<p> <\/p>/g, "") | ||
| .replace(/<p>\s+<\/p>/g, "") | ||
| .replace(/<p> <\/p>/g, "") | ||
| .trim(); | ||
|
|
||
| setHtmlContent(html); | ||
| } catch (error) { | ||
| console.error("Failed to convert markdown:", error); | ||
| setHtmlContent(content); | ||
| } | ||
| }; | ||
|
|
||
| if (content.trim()) { | ||
| convertMarkdown(); | ||
| } | ||
| }, [content]); | ||
|
|
||
| return ( | ||
| <> | ||
| <style> | ||
| {` | ||
| /* Override tiptap spacing for compact cards */ | ||
| .markdown-card-container .tiptap-normal { | ||
| font-size: 0.875rem !important; | ||
| line-height: 2 !important; | ||
| padding: 0 !important; | ||
| /* Enable text selection */ | ||
| user-select: text !important; | ||
| -webkit-user-select: text !important; | ||
| -moz-user-select: text !important; | ||
| -ms-user-select: text !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal * { | ||
| /* Ensure all children are selectable */ | ||
| user-select: text !important; | ||
| -webkit-user-select: text !important; | ||
| -moz-user-select: text !important; | ||
| -ms-user-select: text !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal h1 { | ||
| margin: 8px 0 8px 0 !important; | ||
| font-size: 1rem !important; | ||
| font-weight: 600 !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal h1:first-child { | ||
| margin-top: 0 !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal p { | ||
| margin: 0 0 20px 0 !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal ul { | ||
| margin: 0 0 8px 0 !important; | ||
| padding-left: 1.2rem !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal li { | ||
| margin-bottom: 3px !important; | ||
| } | ||
|
|
||
| /* Make selection highlight visible */ | ||
| .markdown-card-container .tiptap-normal ::selection { | ||
| background-color: #3b82f6 !important; | ||
| color: white !important; | ||
| } | ||
|
|
||
| .markdown-card-container .tiptap-normal ::-moz-selection { | ||
| background-color: #3b82f6 !important; | ||
| color: white !important; | ||
| } | ||
| `} | ||
| </style> | ||
|
|
||
| {/* Flat card with no shadow */} | ||
| <div className="mt-4 mb-4 border border-neutral-200 rounded-lg bg-white overflow-hidden"> | ||
| {/* Grey header section - Made thinner with py-1 */} | ||
| <div className="bg-neutral-50 px-4 py-1 border-b border-neutral-200 flex items-center justify-between"> | ||
| <div className="text-sm text-neutral-600 flex items-center gap-2"> | ||
| <FileTextIcon className="h-4 w-4" /> | ||
| {sessionTitle || "Hyprnote Suggestion"} | ||
| </div> | ||
|
|
||
| {/* Conditional button based on hasEnhancedNote */} | ||
| {hasEnhancedNote | ||
| ? ( | ||
| <Button | ||
| variant="ghost" | ||
| className="hover:bg-neutral-200 h-6 px-2 text-xs text-neutral-600 flex items-center gap-1" | ||
| onClick={handleApplyClick} | ||
| > | ||
| <PlayIcon className="size-3" /> | ||
| Apply | ||
| </Button> | ||
| ) | ||
| : ( | ||
| <Button | ||
| variant="ghost" | ||
| className="hover:bg-neutral-200 h-6 px-2 text-xs text-neutral-600 flex items-center gap-1" | ||
| onClick={handleCopyClick} | ||
| > | ||
| <CopyIcon className="size-3" /> | ||
| {isCopied ? "Copied" : "Copy"} | ||
| </Button> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Content section - Add selectable class */} | ||
| <div className="p-4"> | ||
| <div className="markdown-card-container select-text"> | ||
| <Renderer initialContent={htmlContent} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
apps/desktop/src/components/right-panel/components/chat/message-content.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { MarkdownCard } from "./markdown-card"; | ||
| import { Message } from "./types"; | ||
|
|
||
| interface MessageContentProps { | ||
| message: Message; | ||
| sessionTitle?: string; | ||
| hasEnhancedNote?: boolean; | ||
| onApplyMarkdown?: (markdownContent: string) => void; | ||
| } | ||
|
|
||
| export function MessageContent({ message, sessionTitle, hasEnhancedNote, onApplyMarkdown }: MessageContentProps) { | ||
| // If no parts are parsed, show regular content | ||
| if (!message.parts || message.parts.length === 0) { | ||
| return ( | ||
| <div className="whitespace-pre-wrap text-sm text-neutral-800"> | ||
| {message.content} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="space-y-1"> | ||
| {message.parts.map((part, index) => ( | ||
| <div key={index}> | ||
| {part.type === "text" | ||
| ? ( | ||
| <div className="whitespace-pre-wrap text-sm text-neutral-800"> | ||
| {part.content} | ||
| </div> | ||
| ) | ||
| : ( | ||
| <MarkdownCard | ||
| content={part.content} | ||
| isComplete={part.isComplete || false} | ||
| sessionTitle={sessionTitle} | ||
| hasEnhancedNote={hasEnhancedNote} | ||
| onApplyMarkdown={onApplyMarkdown} | ||
| /> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.