Skip to content

Commit

Permalink
fix loading issues and parsing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Diegogtz03 committed Jun 14, 2024
1 parent ca02b39 commit 8d23172
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 70 deletions.
53 changes: 47 additions & 6 deletions knowx/src/actions/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,17 @@ export async function categorySearchFunction(query: string) {
export async function getFullSearch() {
const MAX_TRYS = 5
let trys = 0
let data: Results[] = []
let data: Results = {
results: [
{
Name: "",
Description: "",
Categories: [],
},
],
categories: [],
}
let validJSON: boolean = false

const session = await getServerSession()
const userId = await getUserId({ newEmail: session?.user?.email || "" })
Expand Down Expand Up @@ -224,7 +234,7 @@ export async function getFullSearch() {
u.append("topic", currentQuery)
}

while (trys < MAX_TRYS && data.length === 0) {
while (trys < MAX_TRYS && data.categories.length === 0 && !validJSON) {
const res = await fetch(`${process.env.API_ROOT_ROUTE}/search`, {
method: "POST",
body: u,
Expand All @@ -236,19 +246,50 @@ export async function getFullSearch() {
if (matched) {
try {
data = JSON.parse(matched[0])

const categoriesFound = data.categories

if (!categoriesFound.includes("Description")) {
categoriesFound.concat(["Description"])
}

validJSON = true

data!.results[0].Categories.forEach((category) => {
if (!categoriesFound.includes(category.Name)) {
validJSON = false
data = {
results: [
{
Name: "",
Description: "",
Categories: [],
},
],
categories: [],
}
}
})
} catch (e) {
data = []
data = {
results: [
{
Name: "",
Description: "",
Categories: [],
},
],
categories: [],
}
}
} else {
data = []
}

trys++
}

setCookie(COMPARE_DATA_KEY, JSON.stringify(data))

logSearchResults({
await logSearchResults({
userId: userId,
searchId: parseInt(getCookie(CURRENT_SEARCH_ID_KEY) || ""),
searchResults: JSON.stringify(data),
Expand Down
98 changes: 49 additions & 49 deletions knowx/src/app/history/[...historyId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,64 +38,64 @@ export default async function Home({
}

return (
<main className="bg-backgroundLight dark:bg-backgroundDark">
<Header
isDashboard={false}
userMenuShowBoth={true}
title="Search History"
>
<Suspense fallback={<Loading />}>
<Suspense fallback={<Loading />}>
<main className="bg-backgroundLight dark:bg-backgroundDark">
<Header
isDashboard={false}
userMenuShowBoth={true}
title="Search History"
>
<div className="flex flex-col items-center">
<HistoryOverview history={history} />

{tableResults != undefined ? (
<div className="mb-9 flex flex-col items-center">
<P3_ResultsTable incoming_results={tableResults} />
<P3_CompareButton
isHistory={true}
history={history.searchResults || ""}
/>
</div>
) : (
<Chip color="danger" className="m-5">
Error loading results
</Chip>
)}
<HistoryOverview history={history}>
{tableResults != undefined ? (
<div className="z-10 mb-9 flex flex-col items-center">
<P3_ResultsTable incoming_results={tableResults} />
<P3_CompareButton
isHistory={true}
history={history.searchResults || ""}
/>
</div>
) : (
<Chip color="danger" className="m-5">
Error loading results
</Chip>
)}
</HistoryOverview>
</div>
</Suspense>
</Header>
</Header>

<InfoComponent title="History" icon={2}>
<>
<p>The results above show the detailed history of your search.</p>
<InfoComponent title="History" icon={2}>
<>
<p>The results above show the detailed history of your search.</p>

<br />
<br />

<p>
These include the information generated by our system and the ones
selected by you for this specific search.
</p>
<p>
These include the information generated by our system and the ones
selected by you for this specific search.
</p>

<br />
<br />

<p>
The{" "}
<Chip variant="dot" color="secondary">
purple
</Chip>{" "}
chips represent those categories created by you.
</p>
<p>
The{" "}
<Chip variant="dot" color="secondary">
purple
</Chip>{" "}
chips represent those categories created by you.
</p>

<br />
<br />

<p>
Use the action buttons to provide feedback on the generated topics
or delete the search from your history.
</p>
<p>
Use the action buttons to provide feedback on the generated topics
or delete the search from your history.
</p>

<br />
</>
</InfoComponent>
</main>
<br />
</>
</InfoComponent>
</main>
</Suspense>
)
}
12 changes: 6 additions & 6 deletions knowx/src/app/history/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export default async function Home() {

return (
<main className="bg-backgroundLight dark:bg-backgroundDark">
<Header isDashboard={false} title="Search History">
<div className="flex w-2/3">
<Suspense fallback={<Loading />}>
<Suspense fallback={<Loading />}>
<Header isDashboard={false} title="Search History">
<div className="flex w-2/3">
<SearchHistoryList history={history || []} />
</Suspense>
</div>
</Header>
</div>
</Header>
</Suspense>
<InfoComponent title="History" icon={2}>
<>
<p>
Expand Down
6 changes: 5 additions & 1 deletion knowx/src/components/History/HistoryOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ const transformToArray = (data: string) => {

export default function HistoryOverview({
history,
children,
}: {
history: FullHistoryType
children?: React.ReactNode
}) {
const [searchHistory, setSearchHistory] = useState<FullHistoryType>(history)

Expand Down Expand Up @@ -84,7 +86,7 @@ export default function HistoryOverview({
</Chip>
)}

<ButtonGroup className="absolute bottom-0 mb-5 dark:dark">
<ButtonGroup className="absolute bottom-0 left-5 mb-5 dark:dark">
<Button
isIconOnly
color="default"
Expand Down Expand Up @@ -278,6 +280,8 @@ export default function HistoryOverview({
)}
</Card>
</div>

{children}
</div>
)
}
2 changes: 1 addition & 1 deletion knowx/src/components/History/SearchHistoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function SearchHistoryList({
sortDescriptor={historyList.sortDescriptor}
onSortChange={historyList.sort}
selectionMode="single"
className="h-auto w-full min-w-full table-auto overflow-hidden rounded-lg dark:dark"
className="h-auto max-h-[70vh] w-full min-w-full table-auto overflow-hidden rounded-lg dark:dark"
aria-label="search history table"
onRowAction={(key: Key) => openItem(Number(key))}
>
Expand Down
12 changes: 6 additions & 6 deletions knowx/src/components/LoadingScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// import Header from "./Header"
import Header from "./Header"
import { Spinner } from "@nextui-org/react"

export default function LoadingScreen() {
return (
<main className="bg-backgroundLight dark:bg-backgroundDark">
{/* <Header isDashboard={false} userMenuShowBoth={true}> */}
<div className="flex w-2/3 justify-center">
<Spinner size="lg" label="Loading..." color="secondary" />
</div>
{/* </Header> */}
<Header isDashboard={false} userMenuShowBoth={true}>
<div className="flex w-2/3 justify-center">
<Spinner size="lg" label="Loading..." color="secondary" />
</div>
</Header>
</main>
)
}
2 changes: 1 addition & 1 deletion knowx/src/components/Phase3/P3_ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const P3_ResultsTable = ({
<Table
color={"primary"}
selectionMode="multiple"
className="dark:pretty-scrollbar 2x:min-w-[90vw] h-full w-[90vw] min-w-[60vw] max-w-[50vw] table-auto overflow-auto rounded-lg dark:dark"
className="dark:pretty-scrollbar 2x:min-w-[90vw] h-full w-[90vw] min-w-[60vw] max-w-[80vw] table-auto overflow-auto rounded-lg dark:dark"
aria-label="search history table"
onSelectionChange={(keys) => {
setCurrentRows(keys as Set<string>)
Expand Down

0 comments on commit 8d23172

Please sign in to comment.