feat: add PostgreSQL support and enhance evaluation loading

- Added `pg` and `@types/pg` dependencies for PostgreSQL integration.
- Updated `useEvaluation` hook to load user evaluations from the API, improving data management.
- Refactored `saveUserEvaluation` and `loadUserEvaluation` functions to interact with the API instead of localStorage.
- Introduced error handling for profile loading and evaluation saving to enhance robustness.
- Added new methods for managing user profiles and evaluations, including `clearUserProfile` and `loadEvaluationForProfile`.
This commit is contained in:
Julien Froidefond
2025-08-21 08:46:52 +02:00
parent 488684fd9b
commit 4e82a6d860
14 changed files with 1467 additions and 125 deletions

View File

@@ -6,6 +6,7 @@ import {
UserEvaluation,
SkillCategory,
} from "./types";
import { apiClient } from "../services/api-client";
export function calculateCategoryScore(
categoryEvaluation: CategoryEvaluation
@@ -44,21 +45,22 @@ export function generateRadarData(
});
}
export function saveUserEvaluation(evaluation: UserEvaluation): void {
export async function saveUserEvaluation(
evaluation: UserEvaluation
): Promise<void> {
try {
localStorage.setItem(
"peakSkills_userEvaluation",
JSON.stringify(evaluation)
);
await apiClient.saveUserEvaluation(evaluation);
} catch (error) {
console.error("Failed to save user evaluation:", error);
throw error;
}
}
export function loadUserEvaluation(): UserEvaluation | null {
export async function loadUserEvaluation(
profile: UserEvaluation["profile"]
): Promise<UserEvaluation | null> {
try {
const saved = localStorage.getItem("peakSkills_userEvaluation");
return saved ? JSON.parse(saved) : null;
return await apiClient.loadUserEvaluation(profile);
} catch (error) {
console.error("Failed to load user evaluation:", error);
return null;