@oxyhq/services
Version:
52 lines (50 loc) • 1.83 kB
JavaScript
;
/**
* Avatar Picker Hook
*
* Extracts avatar selection logic from OxyContext for better modularity.
* Opens the FileManagement bottom sheet in select mode for image files,
* then updates the user's profile avatar.
*/
import { useCallback } from 'react';
import { translate } from '@oxyhq/core';
import { toast } from '../../lib/sonner';
import { updateAvatarVisibility, updateProfileWithAvatar } from "../utils/avatarUtils.js";
export function useAvatarPicker({
oxyServices,
currentLanguage,
activeSessionId,
queryClient,
showBottomSheet
}) {
const openAvatarPicker = useCallback(() => {
showBottomSheet({
screen: 'FileManagement',
props: {
selectMode: true,
multiSelect: false,
disabledMimeTypes: ['video/', 'audio/', 'application/pdf'],
afterSelect: 'none',
onSelect: async file => {
if (!file.contentType.startsWith('image/')) {
toast.error(translate(currentLanguage ?? undefined, 'editProfile.toasts.selectImage') || 'Please select an image file');
return;
}
try {
await updateAvatarVisibility(file.id, oxyServices, 'OxyContext');
await updateProfileWithAvatar({
avatar: file.id
}, oxyServices, activeSessionId, queryClient);
toast.success(translate(currentLanguage ?? undefined, 'editProfile.toasts.avatarUpdated') || 'Avatar updated');
} catch (e) {
toast.error(e.message || translate(currentLanguage ?? undefined, 'editProfile.toasts.updateAvatarFailed') || 'Failed to update avatar');
}
}
}
});
}, [oxyServices, currentLanguage, showBottomSheet, activeSessionId, queryClient]);
return {
openAvatarPicker
};
}
//# sourceMappingURL=useAvatarPicker.js.map