feat: add multiple skills addition and optimize evaluation handling
- Introduced `addMultipleSkillsToEvaluation` function in `EvaluationClientWrapper` for batch skill addition. - Updated `SkillEvaluation` and `SkillSelector` components to utilize the new multiple skills addition feature. - Implemented optimistic UI updates for skill level, mentor status, and learning status changes, enhancing user experience. - Refactored evaluation state management to improve performance and maintainability. - Added error handling and rollback mechanisms for better reliability during API interactions.
This commit is contained in:
@@ -296,14 +296,21 @@ export function useEvaluation() {
|
||||
const addSkillToEvaluation = async (category: string, skillId: string) => {
|
||||
if (!userEvaluation) return;
|
||||
|
||||
// Sauvegarder l'état actuel pour le rollback
|
||||
const previousEvaluation = userEvaluation;
|
||||
|
||||
try {
|
||||
// Optimistic UI update - mettre à jour immédiatement l'interface
|
||||
const updatedEvaluations = userEvaluation.evaluations.map((catEval) => {
|
||||
if (catEval.category === category) {
|
||||
if (!catEval.selectedSkillIds.includes(skillId)) {
|
||||
return {
|
||||
...catEval,
|
||||
selectedSkillIds: [...catEval.selectedSkillIds, skillId],
|
||||
skills: [...catEval.skills, { skillId, level: null }],
|
||||
skills: [
|
||||
...catEval.skills,
|
||||
{ skillId, level: null, canMentor: false, wantsToLearn: false },
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -317,6 +324,8 @@ export function useEvaluation() {
|
||||
};
|
||||
|
||||
setUserEvaluation(newEvaluation);
|
||||
|
||||
// Appel API en arrière-plan
|
||||
await apiClient.addSkillToEvaluation(
|
||||
userEvaluation.profile,
|
||||
category,
|
||||
@@ -324,6 +333,9 @@ export function useEvaluation() {
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Failed to add skill to evaluation:", error);
|
||||
// Rollback optimiste en cas d'erreur
|
||||
setUserEvaluation(previousEvaluation);
|
||||
// Optionnel: afficher une notification d'erreur à l'utilisateur
|
||||
}
|
||||
};
|
||||
|
||||
@@ -333,7 +345,11 @@ export function useEvaluation() {
|
||||
) => {
|
||||
if (!userEvaluation) return;
|
||||
|
||||
// Sauvegarder l'état actuel pour le rollback
|
||||
const previousEvaluation = userEvaluation;
|
||||
|
||||
try {
|
||||
// Optimistic UI update - mettre à jour immédiatement l'interface
|
||||
const updatedEvaluations = userEvaluation.evaluations.map((catEval) => {
|
||||
if (catEval.category === category) {
|
||||
return {
|
||||
@@ -354,6 +370,8 @@ export function useEvaluation() {
|
||||
};
|
||||
|
||||
setUserEvaluation(newEvaluation);
|
||||
|
||||
// Appel API en arrière-plan
|
||||
await apiClient.removeSkillFromEvaluation(
|
||||
userEvaluation.profile,
|
||||
category,
|
||||
@@ -361,6 +379,9 @@ export function useEvaluation() {
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Failed to remove skill from evaluation:", error);
|
||||
// Rollback optimiste en cas d'erreur
|
||||
setUserEvaluation(previousEvaluation);
|
||||
// Optionnel: afficher une notification d'erreur à l'utilisateur
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user