Upgrade linter and formatter to Ultracite (#1224)

This commit is contained in:
Hayden Bleasel 2025-09-20 12:47:10 -07:00 committed by GitHub
parent b1d254283b
commit 0e320b391d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 6951 additions and 8342 deletions

View file

@ -1,11 +1,12 @@
'use client';
"use client";
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 { 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 {
AlertDialog,
AlertDialogAction,
@ -15,18 +16,17 @@ 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 { ChatItem } from './sidebar-history-item';
import useSWRInfinite from 'swr/infinite';
import { LoaderIcon } from './icons';
} 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";
type GroupedChats = {
today: Chat[];
@ -36,10 +36,10 @@ type GroupedChats = {
older: Chat[];
};
export interface ChatHistory {
chats: Array<Chat>;
export type ChatHistory = {
chats: Chat[];
hasMore: boolean;
}
};
const PAGE_SIZE = 20;
@ -72,23 +72,27 @@ 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}`;
}
@ -119,13 +123,13 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
? paginatedChatHistories.every((page) => page.chats.length === 0)
: false;
const handleDelete = async () => {
const handleDelete = () => {
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) {
@ -136,15 +140,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("/");
}
};
@ -170,14 +174,14 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
<div className="flex flex-col">
{[44, 32, 28, 64, 52].map((item) => (
<div
key={item}
className="flex h-8 items-center gap-2 rounded-md px-2"
key={item}
>
<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
}
/>
@ -209,7 +213,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
{paginatedChatHistories &&
(() => {
const chatsFromHistory = paginatedChatHistories.flatMap(
(paginatedChatHistory) => paginatedChatHistory.chats,
(paginatedChatHistory) => paginatedChatHistory.chats
);
const groupedChats = groupChatsByDate(chatsFromHistory);
@ -223,9 +227,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);
@ -243,9 +247,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);
@ -263,9 +267,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);
@ -283,9 +287,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);
@ -303,9 +307,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);
@ -343,7 +347,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
</SidebarGroupContent>
</SidebarGroup>
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
<AlertDialog onOpenChange={setShowDeleteDialog} open={showDeleteDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>