mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +01:00
✨ feat: Enhance favorites management with validation, update data structure, and improve UI interactions
This commit is contained in:
parent
bfeae91a96
commit
960e2ee527
10 changed files with 117 additions and 31 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import type { Favorite } from '~/store/favorites';
|
||||
import store from '~/store';
|
||||
import { useGetFavoritesQuery, useUpdateFavoritesMutation } from '~/data-provider';
|
||||
|
||||
|
|
@ -11,13 +12,15 @@ export default function useFavorites() {
|
|||
useEffect(() => {
|
||||
if (getFavoritesQuery.data) {
|
||||
if (Array.isArray(getFavoritesQuery.data)) {
|
||||
const mapped = getFavoritesQuery.data.map((f: any) => {
|
||||
if (f.agentId || (f.model && f.endpoint)) return f;
|
||||
if (f.type === 'agent' && f.id) return { agentId: f.id };
|
||||
// Drop label and map legacy model format
|
||||
if (f.type === 'model') return { model: f.model, endpoint: f.endpoint };
|
||||
return f;
|
||||
});
|
||||
const mapped = getFavoritesQuery.data.map(
|
||||
(f: Favorite & { type?: string; id?: string }) => {
|
||||
if (f.agentId || (f.model && f.endpoint)) return f;
|
||||
if (f.type === 'agent' && f.id) return { agentId: f.id };
|
||||
// Drop label and map legacy model format
|
||||
if (f.type === 'model') return { model: f.model, endpoint: f.endpoint };
|
||||
return f;
|
||||
},
|
||||
);
|
||||
setFavorites(mapped);
|
||||
} else {
|
||||
// Handle legacy format or invalid data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue