import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog";
import UiCloseOverlay from "WoltLabSuite/Core/Ui/CloseOverlay";
+interface Result {
+ avatar: string;
+}
+
async function editAvatar(button: HTMLElement): Promise<void> {
// If the user is editing their own avatar, the control panel is open and can overlay the dialog.
UiCloseOverlay.execute();
- const { ok } = await dialogFactory().usingFormBuilder().fromEndpoint(button.dataset.editAvatar!);
+ const { ok, result } = await dialogFactory().usingFormBuilder().fromEndpoint<Result>(button.dataset.editAvatar!);
if (ok) {
- // TODO can we simple replace all avatar images?
- window.location.reload();
+ const avatarForm = document.getElementById("avatarForm");
+ if (avatarForm) {
+ // In the ACP, the form should not be reloaded after changing the avatar.
+ avatarForm.querySelector<HTMLImageElement>("img.userAvatarImage")!.src = result.avatar;
+ } else {
+ // TODO can we simple replace all avatar images?
+ window.location.reload();
+ }
}
}
export function setup(): void {
+ wheneverFirstSeen(
+ "#wcf\\\\action\\\\UserAvatarAction_avatarFileIDContainer woltlab-core-file img",
+ (img: HTMLImageElement) => {
+ img.classList.add("userAvatarImage");
+ img.parentElement!.classList.add("userAvatar");
+ },
+ );
+
wheneverFirstSeen("[data-edit-avatar]", (button) => {
button.addEventListener(
"click",
async function editAvatar(button) {
// If the user is editing their own avatar, the control panel is open and can overlay the dialog.
CloseOverlay_1.default.execute();
- const { ok } = await (0, Dialog_1.dialogFactory)().usingFormBuilder().fromEndpoint(button.dataset.editAvatar);
+ const { ok, result } = await (0, Dialog_1.dialogFactory)().usingFormBuilder().fromEndpoint(button.dataset.editAvatar);
if (ok) {
- // TODO can we simple replace all avatar images?
- window.location.reload();
+ const avatarForm = document.getElementById("avatarForm");
+ if (avatarForm) {
+ // In the ACP, the form should not be reloaded after changing the avatar.
+ avatarForm.querySelector("img.userAvatarImage").src = result.avatar;
+ }
+ else {
+ // TODO can we simple replace all avatar images?
+ window.location.reload();
+ }
}
}
function setup() {
+ (0, Selector_1.wheneverFirstSeen)("#wcf\\\\action\\\\UserAvatarAction_avatarFileIDContainer woltlab-core-file img", (img) => {
+ img.classList.add("userAvatarImage");
+ img.parentElement.classList.add("userAvatar");
+ });
(0, Selector_1.wheneverFirstSeen)("[data-edit-avatar]", (button) => {
button.addEventListener("click", (0, PromiseMutex_1.promiseMutex)(() => editAvatar(button)));
});
(new SetAvatar($user->getDecoratedObject()))();
}
+ // Reload the user object to get the updated avatar
+ UserProfileRuntimeCache::getInstance()->removeObject($user->userID);
+ $user = UserProfileRuntimeCache::getInstance()->getObject($user->userID);
+
return new JsonResponse([
- // TODO did we need the avatar url?
- 'result' => [],
+ 'result' => [
+ 'avatar' => $user->getAvatar()->getURL(),
+ ],
]);
} else {
throw new \LogicException('Unreachable');