Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2347 - Build Image viewer in the app #2367

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
73ab363
build the skeleton ImageViwerModal.vue / make sure it open/close
SebinSong Sep 18, 2024
96dae8e
add blurry bg / add modal-btn / implement onLoad handler
SebinSong Sep 18, 2024
263ea1d
calculation logic to determine the minimum zoom value
SebinSong Sep 24, 2024
1bc23d0
update the min zoom calc logic again (incomplete)
SebinSong Sep 24, 2024
592836a
fix the initial render logic
SebinSong Sep 25, 2024
8f745aa
add zoom slider UI to the modal
SebinSong Sep 25, 2024
df76550
fix typo in slider component
SebinSong Sep 25, 2024
70a6c32
custom UI/UX for the slider / dynamic zoom update to the image
SebinSong Sep 25, 2024
a05ada7
extract PointerEventsMixin.js and add it to the image viewer
SebinSong Sep 26, 2024
b76c964
allow moving around the image
SebinSong Sep 27, 2024
f6b854f
add some helper comments for auto-translation logic
SebinSong Sep 27, 2024
5c7b1cc
Merge remote-tracking branch 'origin/master' into sebin/task/#2347-cr…
SebinSong Sep 29, 2024
5b2563f
fix the broken blurry-bg and work on Greg's feedback
SebinSong Sep 30, 2024
a7c2daa
make sure ImageViwerModal.vue is triggered by various call-to-actions
SebinSong Sep 30, 2024
52a8457
implement zoom in/out triggered by wheel event
SebinSong Sep 30, 2024
f3dc680
pass image meta-data to ImageViewerModal.vue
SebinSong Sep 30, 2024
0f00b20
image metadata UI on the modal
SebinSong Oct 1, 2024
90a795e
implement zoom/move by touch events
SebinSong Oct 1, 2024
7d36d1d
fix/optimize zoom action by pinch gesture
SebinSong Oct 2, 2024
1f11d14
fix linter err
SebinSong Oct 2, 2024
78c024b
make sure the color looks good in both themes
SebinSong Oct 2, 2024
f325b9e
use css transform() instead of updating width and height
SebinSong Oct 2, 2024
02319b6
fix the slider bug / fix cypress failure
SebinSong Oct 2, 2024
fd692c0
typo in name / fix pinned-msg issue
SebinSong Oct 3, 2024
446e8ac
Fix for Greg CR 1.
SebinSong Oct 7, 2024
3c2e745
pass the zoom action point
SebinSong Oct 8, 2024
d939b62
simplify auto-translation logic for when zoom without center-point
SebinSong Oct 9, 2024
85e4f21
zooming into a certain point
SebinSong Oct 9, 2024
8fc33ab
percent x,y while pointed zoom action should be fixed
SebinSong Oct 10, 2024
c278745
fix the buggy zoom-into-certain-point
SebinSong Oct 11, 2024
dfd891b
fix linter err
SebinSong Oct 11, 2024
48db233
fix all bugs related to 'zoom-into-ceertain-point'
SebinSong Oct 12, 2024
8c8decc
Merge remote-tracking branch 'origin/master' into sebin/task/#2347-cr…
SebinSong Oct 15, 2024
ddb8e4e
uncomment the err handling logic
SebinSong Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module.exports = defineConfig({
projectId: 'q6whky',
experimentalMemoryManagement: true,
// NOTE: When running 'cypress open' on a browser, high memory usage often leads to crashing the browser.
// So setting 'numTestsKeptInMemory' to 0 here. (reference: https://docs.cypress.io/guides/references/configuration#Global)
numTestsKeptInMemory: 0,
// So setting 'numTestsKeptInMemory' to a relatively low number here. (reference: https://docs.cypress.io/guides/references/configuration#Global)
numTestsKeptInMemory: 3,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
Expand Down
1 change: 1 addition & 0 deletions frontend/utils/lazyLoadedView.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ lazyModal('SendThankYouModal', () => import('../views/containers/payments/SendTh
lazyModal('ThankYouNoteModal', () => import('../views/containers/payments/ThankYouNoteModal.vue'))
lazyModal('AvatarEditorModal', () => import('../views/components/avatar-editor/AvatarEditorModal.vue'))
lazyModal('ChatFileAttachmentWarningModal', () => import('../views/containers/chatroom/file-attachment/ChatFileAttachmentWarningModal.vue'))
lazyModal('ImageViewerModal', () => import('../views/containers/chatroom/image-viewer/ImageViwerModal.vue'))
lazyModalFullScreen('GroupCreationModal', () => import('../views/containers/group-settings/GroupCreationModal.vue'))
lazyModalFullScreen('GroupJoinModal', () => import('../views/containers/group-settings/GroupJoinModal.vue'))
lazyModalFullScreen('GroupMembersAllModal', () => import('../views/containers/dashboard/GroupMembersAllModal.vue'))
Expand Down
13 changes: 13 additions & 0 deletions frontend/views/components/SliderContinuous.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ export default ({
const percent = this.getPercent(value)
this.ephemeral.styleVars = `--percent: ${percent}%; --factor: ${this.getFactor(percent)};`
}
},
watch: {
value (newVal) {
if (newVal !== undefined) {
this.updateSlider(newVal)
}
},
min () {
this.updateSlider(this.value)
},
max () {
this.updateSlider(this.value)
}
}
}: Object)
</script>
Expand Down
8 changes: 4 additions & 4 deletions frontend/views/components/avatar-editor/AvatarEditorModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ modal-template(
:zoom='zoom'
:imageUrl='ephemeral.replaceImageUrl'
@pointer-wheel='HandleWheelOnCanvas'
@pinch-in='decrementSlider(3)'
@pinch-out='incrementSlider(3)'
@pinch-in='decrementSlider(4)'
@pinch-out='incrementSlider(4)'
)

.c-slider-container
Expand Down Expand Up @@ -138,8 +138,8 @@ export default ({
this.$refs.slider.updateSlider(this.form.slider)
},
HandleWheelOnCanvas ({ deltaY }) {
if (deltaY < 0) this.incrementSlider(2)
else this.decrementSlider(2)
if (deltaY < 0) this.incrementSlider(3)
else this.decrementSlider(3)
},
loadPhotoChange (fileList) {
if (!fileList.length) return
Expand Down
2 changes: 1 addition & 1 deletion frontend/views/components/avatar-editor/EditorCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { mapGetters } from 'vuex'
import { imageDataURItoBlob } from '@utils/image.js'
import { EDITED_AVATAR_DIAMETER } from './avatar-editor-constants.js'
import pointerEventsMixin from './avatar-editor-pointer-events-setup.js'
import pointerEventsMixin from '@view-utils/pointerEventsMixins.js'

export default {
name: 'AvatarEditorCanvas',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export const ZOOM_SLIDER_MAX = 100
export const IMAGE_SCALE_MIN = 1
export const IMAGE_SCALE_MAX = 5
export const EDITED_AVATAR_DIAMETER = 512
export const PINCH_ZOOM_THRESHOLD = 2.5
2 changes: 2 additions & 0 deletions frontend/views/containers/chatroom/MessageBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
:variant='variant'
:isForDownload='true'
:isMsgSender='isMsgSender'
:ownerID='from'
:created-at='datetime'
:isGroupCreator='isGroupCreator'
@delete-attachment='deleteAttachment'
)
Expand Down
1 change: 1 addition & 0 deletions frontend/views/containers/chatroom/SendArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
chat-attachment-preview(
v-if='ephemeral.attachments.length'
:attachmentList='ephemeral.attachments'
:ownerID='ourIdentityContractId'
@remove='removeAttachment'
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template lang='pug'>
.c-attachment-container(ref='container' :class='{ "is-for-download": isForDownload }')

// Displaying attachments as part of message
template(v-if='isForDownload')
.c-attachment-preview(
v-for='(entry, entryIndex) in attachmentList'
Expand All @@ -20,6 +22,7 @@
v-if='objectURLList[entryIndex]'
:src='objectURLList[entryIndex]'
:alt='entry.name'
@click='openImageViewer(objectURLList[entryIndex], entry)'
)
.loading-box(v-else :style='loadingBoxStyles[entryIndex]')

Expand Down Expand Up @@ -51,11 +54,13 @@
)
i.icon-trash-alt

// Displaying attachments as part of <send-area />
template(v-else)
.c-attachment-preview(
v-for='(entry, entryIndex) in attachmentList'
:key='entryIndex'
:class='"is-" + fileType(entry)'
@click='openImageViewer(entry.url, entry)'
)
img.c-preview-img(
v-if='fileType(entry) === "image" && entry.url'
Expand All @@ -73,7 +78,7 @@
button.c-attachment-remove-btn(
type='button'
:aria-label='L("Remove attachment")'
@click='$emit("remove", entry.url)'
@click.stop='$emit("remove", entry.url)'
)
i.icon-times

Expand All @@ -88,6 +93,7 @@ import Tooltip from '@components/Tooltip.vue'
import { MESSAGE_VARIANTS } from '@model/contracts/shared/constants.js'
import { getFileExtension, getFileType } from '@view-utils/filters.js'
import { Secret } from '~/shared/domains/chelonia/Secret.js'
import { OPEN_MODAL } from '@utils/events.js'

export default {
name: 'ChatAttachmentPreview',
Expand All @@ -107,7 +113,9 @@ export default {
},
isGroupCreator: Boolean,
isForDownload: Boolean,
isMsgSender: Boolean
isMsgSender: Boolean,
ownerID: String,
createdAt: [Date, String]
},
data () {
return {
Expand Down Expand Up @@ -203,6 +211,22 @@ export default {
width: `${widthInPixel}px`,
height: `${heightInPixel}px`
}
},
openImageViewer (objectURL, data) {
if (objectURL) {
sbp(
'okTurtles.events/emit', OPEN_MODAL, 'ImageViewerModal',
null,
{
metaData: {
name: data.name,
ownerID: this.ownerID,
imgUrl: objectURL,
createdAt: this.createdAt || new Date()
}
}
)
}
}
},
watch: {
Expand Down Expand Up @@ -252,7 +276,6 @@ export default {
position: absolute;
right: 0.5rem;
top: 0;
bottom: 0;

.c-attachment-actions {
display: flex;
Expand Down Expand Up @@ -290,7 +313,8 @@ export default {
padding: 0.5rem;

img {
pointer-events: none;
user-select: none;
cursor: pointer;
max-width: 100%;
max-height: 20rem;

Expand Down Expand Up @@ -320,6 +344,7 @@ export default {
&.is-image {
width: 4.5rem;
height: 4.5rem;
cursor: pointer;

.c-preview-img {
pointer-events: none;
Expand Down
Loading