reloading user profile on update

This commit is contained in:
Zamitto
2024-06-18 13:50:31 -03:00
parent 9c37711bbf
commit eea19d43c2
6 changed files with 78 additions and 21 deletions

View File

@@ -3,8 +3,12 @@ import { HydraApi } from "@main/services/hydra-api";
import axios from "axios";
import fs from "node:fs";
import mime from "mime";
import { UserProfile } from "@types";
const patchUserProfile = (displayName: string, profileImageUrl?: string) => {
const patchUserProfile = async (
displayName: string,
profileImageUrl?: string
) => {
if (profileImageUrl) {
return HydraApi.patch("/profile", {
displayName,
@@ -21,10 +25,9 @@ const updateProfile = async (
_event: Electron.IpcMainInvokeEvent,
displayName: string,
newProfileImagePath: string | null
): Promise<any> => {
): Promise<UserProfile | null> => {
if (!newProfileImagePath) {
patchUserProfile(displayName);
return;
return (await patchUserProfile(displayName)).data;
}
const stats = fs.statSync(newProfileImagePath);
@@ -51,8 +54,7 @@ const updateProfile = async (
return undefined;
});
console.log(profileImageUrl);
patchUserProfile(displayName, profileImageUrl);
return (await patchUserProfile(displayName, profileImageUrl)).data;
};
registerEvent("updateProfile", updateProfile);