Skip to content

Commit

Permalink
prompt-improvised
Browse files Browse the repository at this point in the history
  • Loading branch information
ARYPROGRAMMER committed Oct 26, 2024
1 parent feee1d5 commit 4993ce5
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $~$
<details>
<summary>Screenshots</summary>

![Video](https://drive.google.com/file/d/19Je0J6Eh9QprQcmyzdBEpkH9ufwnkmc4/view?usp=sharing)
![image](screenshots/img2.png)
![image](screenshots/img3.png)

Expand Down
5 changes: 2 additions & 3 deletions app/api/analyzer/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export async function POST(req: NextRequest) {

// Generate the analysis
const result = await generateObject({
model,
schema: DocAnalyzerSchema,
model: model,
schema: DocAnalyzerSchema.strict(),
prompt,
});

Expand All @@ -45,7 +45,6 @@ export async function POST(req: NextRequest) {
review: result.object.review,
starred: false
};

return NextResponse.json(docPlan);
} catch (error) {
console.error("Error analyzing document:", error);
Expand Down
106 changes: 96 additions & 10 deletions components/add-doc-list.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import { useStudyPlans } from "@/lib/hooks/doc-analyzer-plans";
import StudyPlanCard from "./doc-analyzed";
import AddStudyPlan from "./add-doc-analyze";
import { DocPlan } from "@/lib/doc-analyzer.types";
import type { DocPlan } from "@/lib/doc-analyzer.types";
import StudyPlanCard from "./doc-analyzed"; // Adjusted the path to match the commented-out import
import AddStudyPlan from "./add-doc-analyze"; // Adjusted the path to match the commented-out import
import Link from "next/link";
import { GitHubLogoIcon } from "@radix-ui/react-icons";
import { ModeToggle } from "@/components/theme/theme-toggle";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Separator } from "@/components/ui/separator";
import { Button } from "@/components/ui/button";
import { useToast } from "@/components/ui/use-toast";
import {
Card,
CardContent,
Expand All @@ -23,7 +25,10 @@ import {
} from "@/components/ui/tooltip";
import { Badge } from "@/components/ui/badge";

export default function StudyPlansList() {
interface StudyPlansListProps {}

const StudyPlansList: React.FC<StudyPlansListProps> = () => {
const { toast } = useToast();
const {
filteredStudyPlans: studyPlans,
generateStudyPlan,
Expand All @@ -33,10 +38,79 @@ export default function StudyPlansList() {
setShowStarredOnly,
} = useStudyPlans();

const handleGenerateStudyPlan = async (content: string) => {
try {
toast({
title: "Analyzing document...",
description: "Please wait while we process your document.",
duration: 3000,
});

await generateStudyPlan(content);

toast({
title: "Success!",
description: "Document has been analyzed successfully.",
variant: "default",
duration: 3000,
});
} catch (error) {
console.error("Error generating study plan:", error);
toast({
title: "Error",
description: "Failed to analyze document. Please try again.",
variant: "destructive",
duration: 5000,
});
}
};

const handleDeletePlan = (id: string) => {
try {
deleteStudyPlan(id);
toast({
title: "Document deleted",
description: "The document has been removed successfully.",
duration: 3000,
});
} catch (error) {
toast({
title: "Error",
description: "Failed to delete document. Please try again.",
variant: "destructive",
duration: 5000,
});
}
};

const handleToggleStar = (id: string) => {
try {
toggleStar(id);
const plan = studyPlans.find(p => p.id.toString() === id);
const isStarred = !plan?.starred;

toast({
title: isStarred ? "Document starred" : "Document unstarred",
description: isStarred
? "Document has been added to your starred list."
: "Document has been removed from your starred list.",
duration: 2000,
});
} catch (error) {
toast({
title: "Error",
description: "Failed to update document star status.",
variant: "destructive",
duration: 5000,
});
}
};

return (
<TooltipProvider>
<ScrollArea className="h-screen">
<div className="container mx-auto p-6">
{/* Header Card */}
<Card className="mb-6">
<CardHeader className="space-y-1">
<div className="flex items-center justify-between">
Expand All @@ -52,6 +126,8 @@ export default function StudyPlansList() {
<Link
href="https://github.com/ARYPROGRAMMER/Legal-Document-Reviewer"
className="hover:opacity-80 transition-opacity"
target="_blank"
rel="noopener noreferrer"
>
<Button variant="outline" size="icon">
<GitHubLogoIcon className="w-5 h-5" />
Expand All @@ -66,6 +142,7 @@ export default function StudyPlansList() {
</CardHeader>
</Card>

{/* Controls Section */}
<div className="flex items-center justify-between mb-6">
<div className="flex items-center gap-4">
<h2 className="text-2xl font-semibold">Legal Document Reviewer</h2>
Expand All @@ -78,7 +155,13 @@ export default function StudyPlansList() {
<TooltipTrigger asChild>
<Button
variant={showStarredOnly ? "secondary" : "outline"}
onClick={() => setShowStarredOnly(!showStarredOnly)}
onClick={() => {
setShowStarredOnly(!showStarredOnly);
toast({
title: showStarredOnly ? "Showing all documents" : "Showing starred documents",
duration: 2000,
});
}}
>
{showStarredOnly ? "Showing Starred" : "Show Starred"}
</Button>
Expand All @@ -87,20 +170,21 @@ export default function StudyPlansList() {
{showStarredOnly ? "Show all documents" : "Show only starred documents"}
</TooltipContent>
</Tooltip>
<AddStudyPlan onAdd={generateStudyPlan} />
<AddStudyPlan onAdd={handleGenerateStudyPlan} />
</div>
</div>

<Separator className="mb-6" />

{/* Content Section */}
{studyPlans.length > 0 ? (
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{studyPlans.map((plan: DocPlan) => (
<StudyPlanCard
key={plan.id}
plan={plan}
toggleStar={toggleStar}
deletePlan={deleteStudyPlan}
toggleStar={() => handleToggleStar(plan.id.toString())}
deletePlan={() => handleDeletePlan(plan.id.toString())}
/>
))}
</div>
Expand All @@ -120,7 +204,7 @@ export default function StudyPlansList() {
Show All Documents
</Button>
) : (
<AddStudyPlan onAdd={generateStudyPlan} />
<AddStudyPlan onAdd={handleGenerateStudyPlan} />
)}
</CardContent>
</Card>
Expand All @@ -129,4 +213,6 @@ export default function StudyPlansList() {
</ScrollArea>
</TooltipProvider>
);
}
};

export default StudyPlansList;
129 changes: 129 additions & 0 deletions components/ui/toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"use client"

import * as React from "react"
import { Cross2Icon } from "@radix-ui/react-icons"
import * as ToastPrimitives from "@radix-ui/react-toast"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const ToastProvider = ToastPrimitives.Provider

const ToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Viewport
ref={ref}
className={cn(
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
className
)}
{...props}
/>
))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName

const toastVariants = cva(
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
{
variants: {
variant: {
default: "border bg-background text-foreground",
destructive:
"destructive group border-destructive bg-destructive text-destructive-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)

const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => {
return (
<ToastPrimitives.Root
ref={ref}
className={cn(toastVariants({ variant }), className)}
{...props}
/>
)
})
Toast.displayName = ToastPrimitives.Root.displayName

const ToastAction = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Action>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Action
ref={ref}
className={cn(
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
className
)}
{...props}
/>
))
ToastAction.displayName = ToastPrimitives.Action.displayName

const ToastClose = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Close>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Close
ref={ref}
className={cn(
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
className
)}
toast-close=""
{...props}
>
<Cross2Icon className="h-4 w-4" />
</ToastPrimitives.Close>
))
ToastClose.displayName = ToastPrimitives.Close.displayName

const ToastTitle = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Title>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Title
ref={ref}
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
{...props}
/>
))
ToastTitle.displayName = ToastPrimitives.Title.displayName

const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Description
ref={ref}
className={cn("text-sm opacity-90", className)}
{...props}
/>
))
ToastDescription.displayName = ToastPrimitives.Description.displayName

type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>

type ToastActionElement = React.ReactElement<typeof ToastAction>

export {
type ToastProps,
type ToastActionElement,
ToastProvider,
ToastViewport,
Toast,
ToastTitle,
ToastDescription,
ToastClose,
ToastAction,
}
35 changes: 35 additions & 0 deletions components/ui/toaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use client"

import {
Toast,
ToastClose,
ToastDescription,
ToastProvider,
ToastTitle,
ToastViewport,
} from "@/components/ui/toast"
import { useToast } from "@/components/ui/use-toast"

export function Toaster() {
const { toasts } = useToast()

return (
<ToastProvider>
{toasts.map(function ({ id, title, description, action, ...props }) {
return (
<Toast key={id} {...props}>
<div className="grid gap-1">
{title && <ToastTitle>{title}</ToastTitle>}
{description && (
<ToastDescription>{description}</ToastDescription>
)}
</div>
{action}
<ToastClose />
</Toast>
)
})}
<ToastViewport />
</ToastProvider>
)
}
Loading

0 comments on commit 4993ce5

Please sign in to comment.