-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(history): use localstorage for query local result
- Loading branch information
Showing
6 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use client"; | ||
import { historyQueryKey } from "@/app/utils/local-storage"; | ||
import { LocalHistory } from "@/app/interfaces/history"; | ||
import { Answer } from "@/app/components/answer"; | ||
import { Sources } from "@/app/components/sources"; | ||
import { Relates } from "@/app/components/relates"; | ||
import { Title } from "@/app/components/title"; | ||
import { Fragment } from "react"; | ||
|
||
export const HistoryResult = () => { | ||
const history = window.localStorage.getItem(historyQueryKey); | ||
if (!history) return null; | ||
let historyRecord: LocalHistory[]; | ||
try { | ||
historyRecord = JSON.parse(history); | ||
} catch { | ||
historyRecord = []; | ||
} | ||
return historyRecord.map( | ||
({ query, rid, sources, markdown, relates, timestamp }) => { | ||
return ( | ||
<Fragment key={`${rid}-${timestamp}`}> | ||
<div className={"mt-6 border-t pt-4"}> | ||
<Title query={query} /> | ||
</div> | ||
<div className="flex flex-col gap-8"> | ||
<Answer markdown={markdown} sources={sources}></Answer> | ||
<Sources sources={sources}></Sources> | ||
<Relates relates={relates}></Relates> | ||
</div> | ||
</Fragment> | ||
); | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Relate } from "@/app/interfaces/relate"; | ||
import { Source } from "@/app/interfaces/source"; | ||
|
||
export interface LocalHistory { | ||
markdown: string; | ||
relates: Relate[]; | ||
sources: Source[]; | ||
rid: string; | ||
query: string; | ||
timestamp: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const historyQueryKey = "lepton_previous_query"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters