Revert "Upgrade linter and formatter to Ultracite" (#1226)
This commit is contained in:
parent
0e320b391d
commit
1aff7d9868
177 changed files with 8334 additions and 6943 deletions
|
|
@ -1,12 +1,14 @@
|
|||
import equal from "fast-deep-equal";
|
||||
import { memo } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { useCopyToClipboard } from "usehooks-ts";
|
||||
import type { Vote } from "@/lib/db/schema";
|
||||
import type { ChatMessage } from "@/lib/types";
|
||||
import { Action, Actions } from "./elements/actions";
|
||||
import { CopyIcon, PencilEditIcon, ThumbDownIcon, ThumbUpIcon } from "./icons";
|
||||
import { useSWRConfig } from 'swr';
|
||||
import { useCopyToClipboard } from 'usehooks-ts';
|
||||
|
||||
import type { Vote } from '@/lib/db/schema';
|
||||
|
||||
import { CopyIcon, ThumbDownIcon, ThumbUpIcon, PencilEditIcon } from './icons';
|
||||
import { Actions, Action } from './elements/actions';
|
||||
import { memo } from 'react';
|
||||
import equal from 'fast-deep-equal';
|
||||
import { toast } from 'sonner';
|
||||
import type { ChatMessage } from '@/lib/types';
|
||||
|
||||
export function PureMessageActions({
|
||||
chatId,
|
||||
|
|
@ -19,19 +21,17 @@ export function PureMessageActions({
|
|||
message: ChatMessage;
|
||||
vote: Vote | undefined;
|
||||
isLoading: boolean;
|
||||
setMode?: (mode: "view" | "edit") => void;
|
||||
setMode?: (mode: 'view' | 'edit') => void;
|
||||
}) {
|
||||
const { mutate } = useSWRConfig();
|
||||
const [_, copyToClipboard] = useCopyToClipboard();
|
||||
|
||||
if (isLoading) {
|
||||
return null;
|
||||
}
|
||||
if (isLoading) return null;
|
||||
|
||||
const textFromParts = message.parts
|
||||
?.filter((part) => part.type === "text")
|
||||
?.filter((part) => part.type === 'text')
|
||||
.map((part) => part.text)
|
||||
.join("\n")
|
||||
.join('\n')
|
||||
.trim();
|
||||
|
||||
const handleCopy = async () => {
|
||||
|
|
@ -41,24 +41,24 @@ export function PureMessageActions({
|
|||
}
|
||||
|
||||
await copyToClipboard(textFromParts);
|
||||
toast.success("Copied to clipboard!");
|
||||
toast.success('Copied to clipboard!');
|
||||
};
|
||||
|
||||
// User messages get edit (on hover) and copy actions
|
||||
if (message.role === "user") {
|
||||
if (message.role === 'user') {
|
||||
return (
|
||||
<Actions className="-mr-0.5 justify-end">
|
||||
<div className="relative">
|
||||
{setMode && (
|
||||
<Action
|
||||
className="-left-10 absolute top-0 opacity-0 transition-opacity group-hover/message:opacity-100"
|
||||
onClick={() => setMode("edit")}
|
||||
tooltip="Edit"
|
||||
onClick={() => setMode('edit')}
|
||||
className="-left-10 absolute top-0 opacity-0 transition-opacity group-hover/message:opacity-100"
|
||||
>
|
||||
<PencilEditIcon />
|
||||
</Action>
|
||||
)}
|
||||
<Action onClick={handleCopy} tooltip="Copy">
|
||||
<Action tooltip="Copy" onClick={handleCopy}>
|
||||
<CopyIcon />
|
||||
</Action>
|
||||
</div>
|
||||
|
|
@ -68,35 +68,34 @@ export function PureMessageActions({
|
|||
|
||||
return (
|
||||
<Actions className="-ml-0.5">
|
||||
<Action onClick={handleCopy} tooltip="Copy">
|
||||
<Action tooltip="Copy" onClick={handleCopy}>
|
||||
<CopyIcon />
|
||||
</Action>
|
||||
|
||||
<Action
|
||||
tooltip="Upvote Response"
|
||||
data-testid="message-upvote"
|
||||
disabled={vote?.isUpvoted}
|
||||
onClick={() => {
|
||||
const upvote = fetch("/api/vote", {
|
||||
method: "PATCH",
|
||||
onClick={async () => {
|
||||
const upvote = fetch('/api/vote', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({
|
||||
chatId,
|
||||
messageId: message.id,
|
||||
type: "up",
|
||||
type: 'up',
|
||||
}),
|
||||
});
|
||||
|
||||
toast.promise(upvote, {
|
||||
loading: "Upvoting Response...",
|
||||
loading: 'Upvoting Response...',
|
||||
success: () => {
|
||||
mutate<Vote[]>(
|
||||
mutate<Array<Vote>>(
|
||||
`/api/vote?chatId=${chatId}`,
|
||||
(currentVotes) => {
|
||||
if (!currentVotes) {
|
||||
return [];
|
||||
}
|
||||
if (!currentVotes) return [];
|
||||
|
||||
const votesWithoutCurrent = currentVotes.filter(
|
||||
(currentVote) => currentVote.messageId !== message.id
|
||||
(vote) => vote.messageId !== message.id,
|
||||
);
|
||||
|
||||
return [
|
||||
|
|
@ -108,44 +107,42 @@ export function PureMessageActions({
|
|||
},
|
||||
];
|
||||
},
|
||||
{ revalidate: false }
|
||||
{ revalidate: false },
|
||||
);
|
||||
|
||||
return "Upvoted Response!";
|
||||
return 'Upvoted Response!';
|
||||
},
|
||||
error: "Failed to upvote response.",
|
||||
error: 'Failed to upvote response.',
|
||||
});
|
||||
}}
|
||||
tooltip="Upvote Response"
|
||||
>
|
||||
<ThumbUpIcon />
|
||||
</Action>
|
||||
|
||||
<Action
|
||||
tooltip="Downvote Response"
|
||||
data-testid="message-downvote"
|
||||
disabled={vote && !vote.isUpvoted}
|
||||
onClick={() => {
|
||||
const downvote = fetch("/api/vote", {
|
||||
method: "PATCH",
|
||||
onClick={async () => {
|
||||
const downvote = fetch('/api/vote', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({
|
||||
chatId,
|
||||
messageId: message.id,
|
||||
type: "down",
|
||||
type: 'down',
|
||||
}),
|
||||
});
|
||||
|
||||
toast.promise(downvote, {
|
||||
loading: "Downvoting Response...",
|
||||
loading: 'Downvoting Response...',
|
||||
success: () => {
|
||||
mutate<Vote[]>(
|
||||
mutate<Array<Vote>>(
|
||||
`/api/vote?chatId=${chatId}`,
|
||||
(currentVotes) => {
|
||||
if (!currentVotes) {
|
||||
return [];
|
||||
}
|
||||
if (!currentVotes) return [];
|
||||
|
||||
const votesWithoutCurrent = currentVotes.filter(
|
||||
(currentVote) => currentVote.messageId !== message.id
|
||||
(vote) => vote.messageId !== message.id,
|
||||
);
|
||||
|
||||
return [
|
||||
|
|
@ -157,15 +154,14 @@ export function PureMessageActions({
|
|||
},
|
||||
];
|
||||
},
|
||||
{ revalidate: false }
|
||||
{ revalidate: false },
|
||||
);
|
||||
|
||||
return "Downvoted Response!";
|
||||
return 'Downvoted Response!';
|
||||
},
|
||||
error: "Failed to downvote response.",
|
||||
error: 'Failed to downvote response.',
|
||||
});
|
||||
}}
|
||||
tooltip="Downvote Response"
|
||||
>
|
||||
<ThumbDownIcon />
|
||||
</Action>
|
||||
|
|
@ -176,13 +172,9 @@ export function PureMessageActions({
|
|||
export const MessageActions = memo(
|
||||
PureMessageActions,
|
||||
(prevProps, nextProps) => {
|
||||
if (!equal(prevProps.vote, nextProps.vote)) {
|
||||
return false;
|
||||
}
|
||||
if (prevProps.isLoading !== nextProps.isLoading) {
|
||||
return false;
|
||||
}
|
||||
if (!equal(prevProps.vote, nextProps.vote)) return false;
|
||||
if (prevProps.isLoading !== nextProps.isLoading) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue