mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-03 22:32:35 +02:00
Storing fine-tune data
This commit is contained in:
@@ -6,6 +6,7 @@ import { showLoginPopup } from '../../lib/popup';
|
||||
import { UserCoursesList } from './UserCoursesList';
|
||||
import { FineTuneCourse } from './FineTuneCourse';
|
||||
import {
|
||||
clearFineTuneData,
|
||||
getCourseFineTuneData,
|
||||
getLastSessionId,
|
||||
storeFineTuneData,
|
||||
@@ -40,9 +41,9 @@ export function AICourse(props: AICourseProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
// setAbout(fineTuneData.about);
|
||||
// setGoal(fineTuneData.goal);
|
||||
// setCustomInstructions(fineTuneData.customInstructions);
|
||||
setAbout(fineTuneData.about);
|
||||
setGoal(fineTuneData.goal);
|
||||
setCustomInstructions(fineTuneData.customInstructions);
|
||||
}, []);
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
@@ -57,13 +58,15 @@ export function AICourse(props: AICourseProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sessionId = hasFineTuneData
|
||||
? storeFineTuneData({
|
||||
about,
|
||||
goal,
|
||||
customInstructions,
|
||||
})
|
||||
: '';
|
||||
let sessionId = '';
|
||||
if (hasFineTuneData) {
|
||||
clearFineTuneData();
|
||||
sessionId = storeFineTuneData({
|
||||
about,
|
||||
goal,
|
||||
customInstructions,
|
||||
});
|
||||
}
|
||||
|
||||
window.location.href = `/ai-tutor/search?term=${encodeURIComponent(keyword)}&difficulty=${difficulty}&id=${sessionId}`;
|
||||
}
|
||||
|
@@ -64,8 +64,8 @@ type CourseFineTuneData = {
|
||||
export function storeFineTuneData(meta: CourseFineTuneData) {
|
||||
const sessionId = Date.now().toString();
|
||||
|
||||
sessionStorage.setItem(sessionId, JSON.stringify(meta));
|
||||
sessionStorage.setItem('lastSessionId', sessionId);
|
||||
localStorage.setItem(sessionId, JSON.stringify(meta));
|
||||
localStorage.setItem('lastSessionId', sessionId);
|
||||
|
||||
return sessionId;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ export function storeFineTuneData(meta: CourseFineTuneData) {
|
||||
export function getCourseFineTuneData(
|
||||
sessionId: string,
|
||||
): CourseFineTuneData | null {
|
||||
const meta = sessionStorage.getItem(sessionId);
|
||||
const meta = localStorage.getItem(sessionId);
|
||||
if (!meta) {
|
||||
return null;
|
||||
}
|
||||
@@ -82,16 +82,16 @@ export function getCourseFineTuneData(
|
||||
}
|
||||
|
||||
export function getLastSessionId(): string | null {
|
||||
return sessionStorage.getItem('lastSessionId');
|
||||
return localStorage.getItem('lastSessionId');
|
||||
}
|
||||
|
||||
export function clearFineTuneData() {
|
||||
const sessionId = getLastSessionId();
|
||||
if (sessionId) {
|
||||
sessionStorage.removeItem(sessionId);
|
||||
localStorage.removeItem(sessionId);
|
||||
}
|
||||
|
||||
sessionStorage.removeItem('lastSessionId');
|
||||
localStorage.removeItem('lastSessionId');
|
||||
}
|
||||
|
||||
const NEW_LINE = '\n'.charCodeAt(0);
|
||||
|
Reference in New Issue
Block a user