mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +01:00
feat: clean up comments and improve code readability in favorites and agent components; bump @librechat/data-schemas to 0.0.24
This commit is contained in:
parent
4e4a132660
commit
bfeae91a96
9 changed files with 55 additions and 52 deletions
|
|
@ -37,10 +37,8 @@ const getFavoritesController = async (req, res) => {
|
||||||
|
|
||||||
let favorites = user.favorites || [];
|
let favorites = user.favorites || [];
|
||||||
|
|
||||||
// Ensure favorites is an array (migration/dev fix)
|
|
||||||
if (!Array.isArray(favorites)) {
|
if (!Array.isArray(favorites)) {
|
||||||
favorites = [];
|
favorites = [];
|
||||||
// Optionally update the DB to fix it permanently
|
|
||||||
await User.findByIdAndUpdate(userId, { $set: { favorites: [] } });
|
await User.findByIdAndUpdate(userId, { $set: { favorites: [] } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ const AgentCard: React.FC<AgentCardProps> = ({ agent, onClick, className = '' })
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Owner info - moved to bottom right */}
|
{/* Owner info */}
|
||||||
{(() => {
|
{(() => {
|
||||||
const displayName = getContactDisplayName(agent);
|
const displayName = getContactDisplayName(agent);
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
|
|
|
||||||
|
|
@ -141,24 +141,24 @@ const AgentDetail: React.FC<AgentDetailProps> = ({ agent, isOpen, onClose }) =>
|
||||||
return (
|
return (
|
||||||
<OGDialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
<OGDialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||||
<OGDialogContent ref={dialogRef} className="max-h-[90vh] w-11/12 max-w-lg overflow-y-auto">
|
<OGDialogContent ref={dialogRef} className="max-h-[90vh] w-11/12 max-w-lg overflow-y-auto">
|
||||||
{/* Agent avatar - top center */}
|
{/* Agent avatar */}
|
||||||
<div className="mt-6 flex justify-center">{renderAgentAvatar(agent, { size: 'xl' })}</div>
|
<div className="mt-6 flex justify-center">{renderAgentAvatar(agent, { size: 'xl' })}</div>
|
||||||
|
|
||||||
{/* Agent name - center aligned below image */}
|
{/* Agent name */}
|
||||||
<div className="mt-3 text-center">
|
<div className="mt-3 text-center">
|
||||||
<h2 className="text-2xl font-bold text-text-primary">
|
<h2 className="text-2xl font-bold text-text-primary">
|
||||||
{agent?.name || localize('com_agents_loading')}
|
{agent?.name || localize('com_agents_loading')}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Contact info - center aligned below name */}
|
{/* Contact info */}
|
||||||
{agent?.support_contact && formatContact() && (
|
{agent?.support_contact && formatContact() && (
|
||||||
<div className="mt-1 text-center text-sm text-text-secondary">
|
<div className="mt-1 text-center text-sm text-text-secondary">
|
||||||
{localize('com_agents_contact')}: {formatContact()}
|
{localize('com_agents_contact')}: {formatContact()}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Agent description - below contact */}
|
{/* Agent description */}
|
||||||
<div className="mt-4 whitespace-pre-wrap px-6 text-center text-base text-text-primary">
|
<div className="mt-4 whitespace-pre-wrap px-6 text-center text-base text-text-primary">
|
||||||
{agent?.description}
|
{agent?.description}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ function ModelSelectorContent() {
|
||||||
searchValue,
|
searchValue,
|
||||||
searchResults,
|
searchResults,
|
||||||
selectedValues,
|
selectedValues,
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
setSearchValue,
|
setSearchValue,
|
||||||
setSelectedValues,
|
setSelectedValues,
|
||||||
|
|
|
||||||
|
|
@ -23,41 +23,43 @@ const DraggableFavoriteItem = ({
|
||||||
children,
|
children,
|
||||||
}: DraggableFavoriteItemProps) => {
|
}: DraggableFavoriteItemProps) => {
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const [{ handlerId }, drop] = useDrop({
|
const [{ handlerId }, drop] = useDrop<{ index: number; id: string }, unknown, { handlerId: any }>(
|
||||||
accept: 'favorite-item',
|
{
|
||||||
collect(monitor) {
|
accept: 'favorite-item',
|
||||||
return {
|
collect(monitor) {
|
||||||
handlerId: monitor.getHandlerId(),
|
return {
|
||||||
};
|
handlerId: monitor.getHandlerId(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
hover(item, monitor) {
|
||||||
|
if (!ref.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dragIndex = item.index;
|
||||||
|
const hoverIndex = index;
|
||||||
|
|
||||||
|
if (dragIndex === hoverIndex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hoverBoundingRect = ref.current?.getBoundingClientRect();
|
||||||
|
const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
|
||||||
|
const clientOffset = monitor.getClientOffset();
|
||||||
|
const hoverClientY = (clientOffset as any).y - hoverBoundingRect.top;
|
||||||
|
|
||||||
|
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
moveItem(dragIndex, hoverIndex);
|
||||||
|
item.index = hoverIndex;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
hover(item: { index: number; id: string }, monitor) {
|
);
|
||||||
if (!ref.current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const dragIndex = item.index;
|
|
||||||
const hoverIndex = index;
|
|
||||||
|
|
||||||
if (dragIndex === hoverIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hoverBoundingRect = ref.current?.getBoundingClientRect();
|
|
||||||
const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
|
|
||||||
const clientOffset = monitor.getClientOffset();
|
|
||||||
const hoverClientY = (clientOffset as any).y - hoverBoundingRect.top;
|
|
||||||
|
|
||||||
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
moveItem(dragIndex, hoverIndex);
|
|
||||||
item.index = hoverIndex;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [{ isDragging }, drag] = useDrag({
|
const [{ isDragging }, drag] = useDrag({
|
||||||
type: 'favorite-item',
|
type: 'favorite-item',
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,23 @@ import { dataService } from 'librechat-data-provider';
|
||||||
import type { FavoritesState } from '~/store/favorites';
|
import type { FavoritesState } from '~/store/favorites';
|
||||||
|
|
||||||
export const useGetFavoritesQuery = (config?: any) => {
|
export const useGetFavoritesQuery = (config?: any) => {
|
||||||
return useQuery<FavoritesState>(['favorites'], () => dataService.getFavorites() as Promise<FavoritesState>, {
|
return useQuery<FavoritesState>(
|
||||||
refetchOnWindowFocus: false,
|
['favorites'],
|
||||||
refetchOnReconnect: false,
|
() => dataService.getFavorites() as Promise<FavoritesState>,
|
||||||
refetchOnMount: false,
|
{
|
||||||
...config,
|
refetchOnWindowFocus: false,
|
||||||
});
|
refetchOnReconnect: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
...config,
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useUpdateFavoritesMutation = () => {
|
export const useUpdateFavoritesMutation = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
(favorites: FavoritesState) => dataService.updateFavorites(favorites) as Promise<FavoritesState>,
|
(favorites: FavoritesState) =>
|
||||||
|
dataService.updateFavorites(favorites) as Promise<FavoritesState>,
|
||||||
{
|
{
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
queryClient.setQueryData(['favorites'], data);
|
queryClient.setQueryData(['favorites'], data);
|
||||||
|
|
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -47913,7 +47913,7 @@
|
||||||
},
|
},
|
||||||
"packages/data-schemas": {
|
"packages/data-schemas": {
|
||||||
"name": "@librechat/data-schemas",
|
"name": "@librechat/data-schemas",
|
||||||
"version": "0.0.30",
|
"version": "0.0.31",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-alias": "^5.1.0",
|
"@rollup/plugin-alias": "^5.1.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@librechat/data-schemas",
|
"name": "@librechat/data-schemas",
|
||||||
"version": "0.0.30",
|
"version": "0.0.31",
|
||||||
"description": "Mongoose schemas and models for LibreChat",
|
"description": "Mongoose schemas and models for LibreChat",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ export interface IUser extends Document {
|
||||||
models: Array<{
|
models: Array<{
|
||||||
model: string;
|
model: string;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
label?: string;
|
|
||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue