Skip to content

Commit

Permalink
fixed the theme and added clerk auth
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmy committed Dec 19, 2023
1 parent 8606fcc commit 3f494df
Show file tree
Hide file tree
Showing 12 changed files with 862 additions and 204 deletions.
568 changes: 565 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
},
"dependencies": {
"@auth0/nextjs-auth0": "^3.5.0",
"@clerk/nextjs": "^4.28.1",
"@clerk/themes": "^1.7.9",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.19",
Expand All @@ -27,6 +29,7 @@
"dayjs": "^1.11.10",
"eslint": "8.44.0",
"eslint-config-next": "13.4.9",
"lucide-react": "^0.298.0",
"md5": "^2.3.0",
"next": "13.4.9",
"node-html-markdown": "^1.3.0",
Expand Down
9 changes: 4 additions & 5 deletions src/app/components/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { FormEvent, ChangeEvent } from "react";
import Messages from "./Messages";
import { useChat } from "ai/react";
import { useEffect } from "react";
import "src/app/globals.css";
import Accordion from "@mui/material/Accordion";
import AccordionDetails from "@mui/material/AccordionDetails";
import AccordionSummary from "@mui/material/AccordionSummary";
Expand Down Expand Up @@ -96,7 +95,7 @@ const Chat: React.FC<Chat> = ({
</Accordion>
</div>
</div>
<div className="border-slate-400 bg-slate-800 overflow-y-auto">
<div className="border-slate-400 bg-[#18181A] overflow-auto">
<Messages messages={messages} />
</div>

Expand All @@ -108,12 +107,12 @@ const Chat: React.FC<Chat> = ({
>
<div className="flex-row space-x-2">
<textarea
className="resize-none overflow-auto max-h-24 border rounded w-full py-2 px-3 text-gray-200 leading-tight pl-3 bg-black border-gray-700 duration-200 h-24"
className="resize-none overflow-auto max-h-24 border rounded w-full py-2 pl-3 pr-20 text-gray-200 leading-tight bg-black border-gray-700 duration-200 h-24"
value={input}
onChange={handleInputChange}
/>
></textarea>

<span className="absolute inset-y-0 right-3 flex items-center pr-3 pointer-events-none text-gray-400">
<span className="absolute inset-y-0 right-5 flex items-center pr-3 pointer-events-none text-gray-400">
<div className="h-3 w-3"></div>
</span>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputLabel from "@mui/material/InputLabel";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import Box from "@mui/material/Box";
import { UserButton } from "@clerk/nextjs";
import { createTheme } from "@mui/material/styles";
import { ThemeProvider } from "@mui/material/styles";

Expand Down Expand Up @@ -109,9 +109,9 @@ export default function Header({
</FormControl>
</ThemeProvider>

<Button variant="outlined" color="primary">
<a href="/api/auth/logout">Logout</a>
</Button>
<div className="ml-3">
<UserButton afterSignOutUrl="/" />
</div>
</div>
</header>
);
Expand Down
189 changes: 189 additions & 0 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
"use client";

import React, { useEffect, useRef, useState, FormEvent } from "react";
import Header from "@/components/Header";
import Chat from "@/components/Chat";
import { useChat } from "ai/react";
import InstructionModal from "@/components/InstructionModal";
import { AiFillGithub, AiOutlineInfoCircle } from "react-icons/ai";
import Search from "@/components/Search";
import dayjs from "dayjs";
import { url } from "inspector";
import { Button } from "@mui/material";

interface search_result {
raw_case_num: string;
case_title: string;
case_date: string;
case_court: string;
case_neutral_cit: string;
case_action_no: string;
url: string;
}

const Page: React.FC = () => {
const [isModalOpen, setModalOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
const [selectedMinDate, setSelectedMinDate] = useState(dayjs("1991-07-11"));
const [selectedMaxDate, setSelectedMaxDate] = useState(dayjs());
const [cofa, setCofa] = useState<string[]>([]);
const [coa, setCoa] = useState<string[]>([]);
const [coficivil, setcoficivil] = useState<string[]>([]);
const [coficriminal, setCoficriminal] = useState<string[]>([]);
const [cofiprobate, setCofiprobate] = useState<string[]>([]);
const [ct, setCt] = useState<string[]>([]);
const [dc, setDc] = useState<string[]>([]);
const [fc, setFc] = useState<string[]>([]);
const [lt, setLt] = useState<string[]>([]);
const [others, setOthers] = useState<string[]>([]);
const [sortOption, setSortOption] = useState("Relevance");
const [filteredResults, setFilteredResults] = useState<search_result[]>([]);
const [resultsShown, setResultsShown] = useState<number>(3);

const performSearch = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault(); // Prevent the default form submission behavior
const filters = [
...cofa,
...coa,
...coficivil,
...coficriminal,
...cofiprobate,
...ct,
...dc,
...fc,
...lt,
...others,
];
console.log(
"Search performed with query:",
searchQuery,
selectedMinDate.format("MM/DD/YYYY"),
selectedMaxDate.format("MM/DD/YYYY"),
filters,
sortOption
);
searchApi(searchQuery, filters);
};

async function searchApi(searchQuery: string, filters: string[]) {
try {
const response = await fetch("/api/search", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ searchQuery, filters }),
});

if (!response.ok) {
throw new Error(`Error: ${response.status}`);
}

const data = await response.json();

const deduplicatedResults = data.deduplicatedResults;
console.log("API results:", deduplicatedResults);

const filteredResults = deduplicatedResults.filter(
(result: search_result) => {
const caseDate = dayjs(result.case_date);
return (
(caseDate.isSame(selectedMinDate) ||
caseDate.isAfter(selectedMinDate)) &&
(caseDate.isSame(selectedMaxDate) ||
caseDate.isBefore(selectedMaxDate))
);
}
);
console.log("Length of API data: ", deduplicatedResults.length);
console.log("Filtered results: ", filteredResults);

if (sortOption === "Recency") {
filteredResults.sort((a: search_result, b: search_result) => {
// Convert case_date strings to Day.js objects for comparison
const dateA = dayjs(a.case_date);
const dateB = dayjs(b.case_date);

// Sort in descending order
return dateB.diff(dateA);
});
}
console.log("sory by ", filteredResults);

setFilteredResults(filteredResults);
} catch (error) {
console.error(
"Error during API call:",
error instanceof Error ? error.message : "An unknown error occurred"
);
throw error;
}
}

console.log("Here is the filteredResults: ", filteredResults);

return (
<div className="flex flex-col justify-between h-screen bg-black mx-auto max-w-full">
<Header
filteredResults={filteredResults}
resultsShown={resultsShown}
setResultsShown={setResultsShown}
/>
<div className="flex w-full flex-grow overflow-hidden relative">
<div className="w-1/4 min-w-[20%] p-2 border-r border-slate-400">
<Search
searchQuery={searchQuery}
setSearchQuery={setSearchQuery}
selectedMinDate={selectedMinDate}
setSelectedMinDate={setSelectedMinDate}
selectedMaxDate={selectedMaxDate}
setSelectedMaxDate={setSelectedMaxDate}
cofa={cofa}
setCofa={setCofa}
coa={coa}
setCoa={setCoa}
coficivil={coficivil}
setcoficivil={setcoficivil}
coficriminal={coficriminal}
setCoficriminal={setCoficriminal}
cofiprobate={cofiprobate}
setCofiprobate={setCofiprobate}
ct={ct}
setCt={setCt}
dc={dc}
setDc={setDc}
fc={fc}
setFc={setFc}
lt={lt}
setLt={setLt}
others={others}
setOthers={setOthers}
sortOption={sortOption}
setSortOption={setSortOption}
performSearch={performSearch}
/>
</div>
<div className="flex flex-row overflow-x-auto">
{filteredResults.slice(0, resultsShown).map((result, index) => (
<div
key={`${index}-${result.raw_case_num}`}
className="w-2/5 border border-slate-400 min-w-[33%]"
>
<Chat
raw_case_num={result.raw_case_num}
query={searchQuery}
case_date={dayjs(result.case_date).format("DD MMM, YYYY")}
case_action_no={result.case_action_no}
case_neutral_cit={result.case_neutral_cit}
url={result.url}
case_title={result.case_title}
/>
</div>
))}
</div>
</div>
</div>
);
};

export default Page;
16 changes: 8 additions & 8 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ body {
/* styles/globals.css */
/* Style the scrollbar track (the part the scrollbar sits in) */
::-webkit-scrollbar {
width: 12px; /* width of the entire scrollbar */
width: 10px; /* width of the entire scrollbar */
}

/* Style the scrollbar handle */
::-webkit-scrollbar-thumb {
background-color: #000000; /* color of the scrollbar itself */
background-color: #ffffff; /* color of the scrollbar itself */
border-radius: 20px; /* roundness of the scrollbar */
/* creates padding around the scrollbar */
border: 3px solid #9CA3AF;
/* border: 0px solid #9CA3AF; */
}

/* Handle scrollbar hover, active, and idle states */
::-webkit-scrollbar-thumb:hover {
background-color: #000000;
border: 3px solid #6B7280;
background-color: #ffffff;
/* border: 0px solid #6B7280; */
}

::-webkit-scrollbar-thumb:active {
background-color: #000000;
border: 3px solid #9CA3AF;
background-color: #ffffff;
/* border: 0px solid #9CA3AF; */
}

::-webkit-scrollbar-thumb:window-inactive {
background-color: #ffffff;
border: 0px solid #9CA3AF;
/* border: 0px solid #9CA3AF; */
}
11 changes: 8 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ClerkProvider } from "@clerk/nextjs";
import { dark } from "@clerk/themes";

export const metadata = {
title: "FastLegal",
description: "Supercharge your legal research",
Expand All @@ -11,8 +14,10 @@ export default function RootLayout({
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
<ClerkProvider appearance={dark}>
<html lang="en">
<body>{children}</body>
</html>
</ClerkProvider>
);
}
Loading

0 comments on commit 3f494df

Please sign in to comment.