Skip to content

Commit

Permalink
fix: load results to cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Diegogtz03 committed Jun 4, 2024
1 parent 90b093d commit 0873b5f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions knowx/src/app/actions/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ export async function getUserIdFunc(
})
}

export async function callLoadResultsCookie(data: string) {
await loadResultsCookie(data)
}

export async function loadResultsCookie(data: string) {
setCookie(COMPARE_DATA_KEY, data)
}
12 changes: 10 additions & 2 deletions knowx/src/app/components/Phase3/P3_CompareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import {
navigateToCompare,
navigateToHistoryCompare,
} from "@/app/actions/redirect"
import { loadResultsCookie } from "@/app/actions/search"

const P3_CompareButton = ({ isHistory = false }: { isHistory?: boolean }) => {
const P3_CompareButton = ({
isHistory = false,
history = "",
}: {
isHistory?: boolean
history?: string
}) => {
return (
<Button
variant="flat"
color="success"
className="mx-auto my-5 w-[200px] rounded-xl p-5"
onClick={() => {
!isHistory ? navigateToCompare() : navigateToHistoryCompare()
!isHistory ? navigateToCompare() : loadResultsCookie(history),
navigateToHistoryCompare()
}}
>
Compare
Expand Down
4 changes: 4 additions & 0 deletions knowx/src/app/helper/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ export function getCompares() {
const compares = cookies().get(COMPARES_KEY)?.value
return compares
}

export function loadResultsCookie(data: string) {
setCookie(COMPARE_DATA_KEY, data)
}
6 changes: 4 additions & 2 deletions knowx/src/app/history/[...historyId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import InfoComponent from "@/app/components/informational/InfoComponent"
import { Results } from "@/app/interfaces/Phase3"
import P3_ResultsTable from "@/app/components/Phase3/P3_ResultsTable"
import P3_CompareButton from "@/app/components/Phase3/P3_CompareButton"
import { loadResultsCookie } from "@/app/actions/search"
import { Chip } from "@nextui-org/react"

export default async function Home({
Expand Down Expand Up @@ -51,7 +50,10 @@ export default async function Home({
{tableResults != undefined ? (
<>
<P3_ResultsTable incoming_results={tableResults} />
<P3_CompareButton isHistory={true} />
<P3_CompareButton
isHistory={true}
history={history.searchResults || ""}
/>
</>
) : (
<Chip color="danger" className="m-5">
Expand Down

0 comments on commit 0873b5f

Please sign in to comment.