Fixes: 1) Remove deprecated and redundant logic from `useAvatarUpload`; 2) Correct non-functional avatar upload and improve template handling in `settings.vue`; Extra: 1) Cleanup unused imports, comments, and SCSS styles across files; 2) Simplify plugin configuration and migration to consolidated link logic; 3) Update package dependencies with precise resolution in `package-lock.json`.
48 lines
No EOL
1.2 KiB
TypeScript
48 lines
No EOL
1.2 KiB
TypeScript
import type {IAvatarUploadResponse,} from "~/types";
|
|
import {UPLOAD_AVATAR} from "~/graphql/mutations/user";
|
|
import {isGraphQLError} from "~/utils/error";
|
|
import {useNotification} from "~/composables/notification";
|
|
|
|
export function useAvatarUpload() {
|
|
const { t } = useI18n();
|
|
const userStore = useUserStore();
|
|
const { mutate, onDone, loading, error } = useMutation<IAvatarUploadResponse>(UPLOAD_AVATAR);
|
|
|
|
async function uploadAvatar(event: Event) {
|
|
const file = (event.target as HTMLInputElement).files?.[0];
|
|
if (!file) return;
|
|
|
|
await mutate({ file });
|
|
}
|
|
|
|
onDone(({ data }) => {
|
|
const user = data?.uploadAvatar.user;
|
|
if (user) {
|
|
userStore.setUser(user);
|
|
useNotification({
|
|
message: t('popup.success.avatarUpload'),
|
|
type: 'success'
|
|
});
|
|
}
|
|
});
|
|
|
|
watch(error, (err) => {
|
|
if (!err) return;
|
|
console.error('useAvatarUpload error:', err);
|
|
let message = t('popup.errors.defaultError');
|
|
if (isGraphQLError(err)) {
|
|
message = err.graphQLErrors?.[0]?.message || message;
|
|
} else {
|
|
message = err.message;
|
|
}
|
|
useNotification({
|
|
message,
|
|
type: 'error',
|
|
title: t('popup.errors.main')
|
|
});
|
|
});
|
|
|
|
return {
|
|
uploadAvatar
|
|
};
|
|
} |