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,11 @@
|
|||
"use client";
|
||||
'use client';
|
||||
|
||||
import { isToday, isYesterday, subMonths, subWeeks } from "date-fns";
|
||||
import { motion } from "framer-motion";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import type { User } from "next-auth";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import useSWRInfinite from "swr/infinite";
|
||||
import { isToday, isYesterday, subMonths, subWeeks } from 'date-fns';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import type { User } from 'next-auth';
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { motion } from 'framer-motion';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
|
|
@ -16,17 +15,18 @@ import {
|
|||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import {
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarMenu,
|
||||
useSidebar,
|
||||
} from "@/components/ui/sidebar";
|
||||
import type { Chat } from "@/lib/db/schema";
|
||||
import { fetcher } from "@/lib/utils";
|
||||
import { LoaderIcon } from "./icons";
|
||||
import { ChatItem } from "./sidebar-history-item";
|
||||
} from '@/components/ui/sidebar';
|
||||
import type { Chat } from '@/lib/db/schema';
|
||||
import { fetcher } from '@/lib/utils';
|
||||
import { ChatItem } from './sidebar-history-item';
|
||||
import useSWRInfinite from 'swr/infinite';
|
||||
import { LoaderIcon } from './icons';
|
||||
|
||||
type GroupedChats = {
|
||||
today: Chat[];
|
||||
|
|
@ -36,10 +36,10 @@ type GroupedChats = {
|
|||
older: Chat[];
|
||||
};
|
||||
|
||||
export type ChatHistory = {
|
||||
chats: Chat[];
|
||||
export interface ChatHistory {
|
||||
chats: Array<Chat>;
|
||||
hasMore: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
|
|
@ -72,27 +72,23 @@ const groupChatsByDate = (chats: Chat[]): GroupedChats => {
|
|||
lastWeek: [],
|
||||
lastMonth: [],
|
||||
older: [],
|
||||
} as GroupedChats
|
||||
} as GroupedChats,
|
||||
);
|
||||
};
|
||||
|
||||
export function getChatHistoryPaginationKey(
|
||||
pageIndex: number,
|
||||
previousPageData: ChatHistory
|
||||
previousPageData: ChatHistory,
|
||||
) {
|
||||
if (previousPageData && previousPageData.hasMore === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pageIndex === 0) {
|
||||
return `/api/history?limit=${PAGE_SIZE}`;
|
||||
}
|
||||
if (pageIndex === 0) return `/api/history?limit=${PAGE_SIZE}`;
|
||||
|
||||
const firstChatFromPage = previousPageData.chats.at(-1);
|
||||
|
||||
if (!firstChatFromPage) {
|
||||
return null;
|
||||
}
|
||||
if (!firstChatFromPage) return null;
|
||||
|
||||
return `/api/history?ending_before=${firstChatFromPage.id}&limit=${PAGE_SIZE}`;
|
||||
}
|
||||
|
|
@ -123,13 +119,13 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
? paginatedChatHistories.every((page) => page.chats.length === 0)
|
||||
: false;
|
||||
|
||||
const handleDelete = () => {
|
||||
const handleDelete = async () => {
|
||||
const deletePromise = fetch(`/api/chat?id=${deleteId}`, {
|
||||
method: "DELETE",
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
toast.promise(deletePromise, {
|
||||
loading: "Deleting chat...",
|
||||
loading: 'Deleting chat...',
|
||||
success: () => {
|
||||
mutate((chatHistories) => {
|
||||
if (chatHistories) {
|
||||
|
|
@ -140,15 +136,15 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
}
|
||||
});
|
||||
|
||||
return "Chat deleted successfully";
|
||||
return 'Chat deleted successfully';
|
||||
},
|
||||
error: "Failed to delete chat",
|
||||
error: 'Failed to delete chat',
|
||||
});
|
||||
|
||||
setShowDeleteDialog(false);
|
||||
|
||||
if (deleteId === id) {
|
||||
router.push("/");
|
||||
router.push('/');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -174,14 +170,14 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
<div className="flex flex-col">
|
||||
{[44, 32, 28, 64, 52].map((item) => (
|
||||
<div
|
||||
className="flex h-8 items-center gap-2 rounded-md px-2"
|
||||
key={item}
|
||||
className="flex h-8 items-center gap-2 rounded-md px-2"
|
||||
>
|
||||
<div
|
||||
className="h-4 max-w-(--skeleton-width) flex-1 rounded-md bg-sidebar-accent-foreground/10"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": `${item}%`,
|
||||
'--skeleton-width': `${item}%`,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
|
|
@ -213,7 +209,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
{paginatedChatHistories &&
|
||||
(() => {
|
||||
const chatsFromHistory = paginatedChatHistories.flatMap(
|
||||
(paginatedChatHistory) => paginatedChatHistory.chats
|
||||
(paginatedChatHistory) => paginatedChatHistory.chats,
|
||||
);
|
||||
|
||||
const groupedChats = groupChatsByDate(chatsFromHistory);
|
||||
|
|
@ -227,9 +223,9 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
</div>
|
||||
{groupedChats.today.map((chat) => (
|
||||
<ChatItem
|
||||
key={chat.id}
|
||||
chat={chat}
|
||||
isActive={chat.id === id}
|
||||
key={chat.id}
|
||||
onDelete={(chatId) => {
|
||||
setDeleteId(chatId);
|
||||
setShowDeleteDialog(true);
|
||||
|
|
@ -247,9 +243,9 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
</div>
|
||||
{groupedChats.yesterday.map((chat) => (
|
||||
<ChatItem
|
||||
key={chat.id}
|
||||
chat={chat}
|
||||
isActive={chat.id === id}
|
||||
key={chat.id}
|
||||
onDelete={(chatId) => {
|
||||
setDeleteId(chatId);
|
||||
setShowDeleteDialog(true);
|
||||
|
|
@ -267,9 +263,9 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
</div>
|
||||
{groupedChats.lastWeek.map((chat) => (
|
||||
<ChatItem
|
||||
key={chat.id}
|
||||
chat={chat}
|
||||
isActive={chat.id === id}
|
||||
key={chat.id}
|
||||
onDelete={(chatId) => {
|
||||
setDeleteId(chatId);
|
||||
setShowDeleteDialog(true);
|
||||
|
|
@ -287,9 +283,9 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
</div>
|
||||
{groupedChats.lastMonth.map((chat) => (
|
||||
<ChatItem
|
||||
key={chat.id}
|
||||
chat={chat}
|
||||
isActive={chat.id === id}
|
||||
key={chat.id}
|
||||
onDelete={(chatId) => {
|
||||
setDeleteId(chatId);
|
||||
setShowDeleteDialog(true);
|
||||
|
|
@ -307,9 +303,9 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
</div>
|
||||
{groupedChats.older.map((chat) => (
|
||||
<ChatItem
|
||||
key={chat.id}
|
||||
chat={chat}
|
||||
isActive={chat.id === id}
|
||||
key={chat.id}
|
||||
onDelete={(chatId) => {
|
||||
setDeleteId(chatId);
|
||||
setShowDeleteDialog(true);
|
||||
|
|
@ -347,7 +343,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
|
|||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
|
||||
<AlertDialog onOpenChange={setShowDeleteDialog} open={showDeleteDialog}>
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue