From 58af4d888e60c4d23dca4319bed8b7d22e8b2b74 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 14 Sep 2019 22:26:29 -0700 Subject: [PATCH] feat: clicking avatar opens media modal (#1485) fixes #1464 --- .../profile/AccountProfileHeader.html | 55 ++++++++++++++++++- src/routes/_utils/getImageNativeDimensions.js | 11 ++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/routes/_utils/getImageNativeDimensions.js diff --git a/src/routes/_components/profile/AccountProfileHeader.html b/src/routes/_components/profile/AccountProfileHeader.html index fdebf62e..89a171e6 100644 --- a/src/routes/_components/profile/AccountProfileHeader.html +++ b/src/routes/_components/profile/AccountProfileHeader.html @@ -1,6 +1,10 @@

Name and following

- +
store, @@ -118,6 +140,37 @@ bot: ({ account }) => !!account.bot, label: ({ bot }) => bot ? 'bot' : '' }, + methods: { + async onAvatarClick () { + const { account } = this.get() + const { avatar, avatar_static: avatarStatic, display_name: displayName, username } = account + const [showMediaDialog, nativeDimensions] = await Promise.all([ + importShowMediaDialog(), + getImageNativeDimensions(avatarStatic) + ]) + // pretend this is a media attachment so it will work in the media dialog + const { width, height } = nativeDimensions + const mediaAttachments = [ + { + description: `Avatar for ${displayName || username}`, + type: 'image', + preview_url: avatarStatic, + url: avatar, + meta: { + original: { + width, + height + }, + small: { + width: 100, + height: 100 + } + } + } + ] + showMediaDialog(mediaAttachments, /* index */ 0) + } + }, components: { Avatar, ExternalLink, diff --git a/src/routes/_utils/getImageNativeDimensions.js b/src/routes/_utils/getImageNativeDimensions.js new file mode 100644 index 00000000..c5defa63 --- /dev/null +++ b/src/routes/_utils/getImageNativeDimensions.js @@ -0,0 +1,11 @@ +import { decodeImage } from './decodeImage' + +export async function getImageNativeDimensions (url) { + const img = document.createElement('img') + img.src = url + await decodeImage(img) + return { + width: img.naturalWidth, + height: img.naturalHeight + } +}