-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ComposerAttachment UI * rename ComposerAttachment type to ThreadComposerAttachment
- Loading branch information
Showing
13 changed files
with
121 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { | ||
ComposerAttachment, | ||
ThreadComposerAttachment, | ||
MessageAttachment, | ||
} from "../../context/stores/Attachment"; | ||
|
||
export type AttachmentAdapter = { | ||
accept: string; | ||
add(state: { file: File }): Promise<ComposerAttachment>; | ||
remove(attachment: ComposerAttachment): Promise<void>; | ||
send(attachment: ComposerAttachment): Promise<MessageAttachment>; | ||
add(state: { file: File }): Promise<ThreadComposerAttachment>; | ||
remove(attachment: ThreadComposerAttachment): Promise<void>; | ||
send(attachment: ThreadComposerAttachment): Promise<MessageAttachment>; | ||
}; |
This file contains 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 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 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 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 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 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,77 @@ | ||
"use client"; | ||
|
||
import { forwardRef, type FC } from "react"; | ||
|
||
import { CircleXIcon } from "lucide-react"; | ||
import { withDefaults } from "./utils/withDefaults"; | ||
import { useThreadConfig } from "./thread-config"; | ||
import { | ||
TooltipIconButton, | ||
TooltipIconButtonProps, | ||
} from "./base/tooltip-icon-button"; | ||
import { useThreadContext } from "../context/react/ThreadContext"; | ||
import { useAttachmentContext } from "../context/react/AttachmentContext"; | ||
|
||
const ComposerAttachmentRoot = withDefaults("div", { | ||
className: "aui-composer-attachment-root", | ||
}); | ||
|
||
ComposerAttachmentRoot.displayName = "ComposerAttachmentRoot"; | ||
|
||
const ComposerAttachment: FC = () => { | ||
const { useAttachment } = useAttachmentContext({ type: "composer" }); | ||
const attachment = useAttachment((a) => a.attachment); | ||
|
||
return ( | ||
<ComposerAttachmentRoot> | ||
.{attachment.name.split(".").pop()} | ||
<ComposerAttachmentRemove /> | ||
</ComposerAttachmentRoot> | ||
); | ||
}; | ||
|
||
ComposerAttachment.displayName = "ComposerAttachment"; | ||
|
||
const ComposerAttachmentRemove = forwardRef< | ||
HTMLButtonElement, | ||
Partial<TooltipIconButtonProps> | ||
>((props, ref) => { | ||
const { | ||
strings: { | ||
composer: { removeAttachment: { tooltip = "Remove file" } = {} } = {}, | ||
} = {}, | ||
} = useThreadConfig(); | ||
|
||
const { useComposer } = useThreadContext(); | ||
const { useAttachment } = useAttachmentContext(); | ||
const handleRemoveAttachment = () => { | ||
useComposer | ||
.getState() | ||
.removeAttachment(useAttachment.getState().attachment.id); | ||
}; | ||
|
||
return ( | ||
<TooltipIconButton | ||
tooltip={tooltip} | ||
className="aui-composer-attachment-remove" | ||
side="top" | ||
{...props} | ||
onClick={handleRemoveAttachment} | ||
ref={ref} | ||
> | ||
{props.children ?? <CircleXIcon />} | ||
</TooltipIconButton> | ||
); | ||
}); | ||
|
||
ComposerAttachmentRemove.displayName = "ComposerAttachmentRemove"; | ||
|
||
const exports = { | ||
Root: ComposerAttachmentRoot, | ||
Remove: ComposerAttachmentRemove, | ||
}; | ||
|
||
export default Object.assign( | ||
ComposerAttachment, | ||
exports, | ||
) as typeof ComposerAttachment & typeof exports; |
Oops, something went wrong.