Browse Source

change the X and picture button so that landscape is all functional (if not great-looking)

kb/add-usage-guide
Trent Larson 8 months ago
parent
commit
a230506d96
  1. 4
      project.task.yaml
  2. 48
      src/components/GiftedPhotoDialog.vue

4
project.task.yaml

@ -3,6 +3,7 @@ tasks :
- bug - landscape doesn't show full camera
- but - portrait stretches pic
- add to readme - check version, close tabs & restart phone if necessary
- bug maybe - a new give remembers the previous project
- alert & stop if give amount < 0
- onboarding video
@ -57,7 +58,7 @@ tasks :
- .1 hide project-create button on project page if not registered
- .1 hide offer & give buttons on project list page if not registered
- .1 add cursor-pointer on the icons for giving on the project page, and on the list of projects on the discover page
- .2 record when InfiniteScroll hits the end of the list and don't trigger any more loads
- .2 record when InfiniteScroll hits the end of the list and don't trigger any more loads (feed, project list, give & offer lists)
- bug - turning notifications on from the help screen did not stay, though account screen toggle did stay (From Jason on iPhone.)
- refactor - supply the projectId to the OfferDialog just like we do with the GiftedDialog offerId (in the "open" method, maybe as well as an attribute)
@ -121,6 +122,7 @@ tasks :
- .5 show seed phrase in a QR code for transfer to another device
- .5 on DiscoverView, switch to a filter UI (eg. just from friend
- .5 don't show "Offer" on project screen if they aren't registered
- 01 especially for iOS, check for new version & update, eg. https://stackoverflow.com/questions/52221805/any-way-yet-to-auto-update-or-just-clear-the-cache-on-a-pwa-on-ios
- 24 Move to Vite
- 32 accept images for projects

48
src/components/GiftedPhotoDialog.vue

@ -1,15 +1,13 @@
<template>
<div v-if="visible" class="dialog-overlay">
<!-- Breadcrumb -->
<div class="dialog">
<!-- Back -->
<div class="text-lg text-center font-light relative px-7">
<h1
class="text-lg text-center px-2 py-1 absolute -right-2 -top-1"
<div
class="text-lg text-center px-2 py-1 absolute -right-2 top-6 z-10"
@click="close()"
>
<fa icon="xmark" class="fa-fw"></fa>
</h1>
</div>
</div>
<!-- Heading -->
@ -30,6 +28,7 @@
>
<span>Upload</span>
</button>
<!-- TODO remove, this and console.logs -->
<!--{{ imageHeight }} {{ imageWidth }} {{ imageWarning }}-->
<button
@click="retryImage"
@ -38,20 +37,17 @@
<span>Retry</span>
</button>
</div>
<div
:style="'height: ' + imageHeight + 'px; width: ' + imageWidth + 'px;'"
>
<img :src="URL.createObjectURL(blob)" class="mt-2" />
<div class="flex justify-center">
<img :src="URL.createObjectURL(blob)" class="mt-2 rounded" />
</div>
</div>
<div v-else>
<!--
Camera "resolution" doesn't change how it shows on screen but rather stretches the result, eg the following which just stretches it vertically:
:resolution="{ width: 375, height: 812 }"
It even messes up when trying to match the ratio with imageHeight and imageWidth.
-->
<camera facingMode="environment" autoplay ref="camera">
<div class="absolute top-0 w-full flex justify-center pb-4">
<div class="absolute bottom-0 w-full flex justify-center pb-8">
<button
@click="takeImage"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-2 rounded-full"
@ -113,17 +109,29 @@ export default class GiftedPhotoDialog extends Vue {
open(setImageFn: (arg: string) => void) {
this.visible = true;
const bottomNav = document.querySelector("#QuickNav") as HTMLElement;
if (bottomNav) {
bottomNav.style.display = "none";
}
this.setImage = setImageFn;
}
close() {
this.visible = false;
const bottomNav = document.querySelector("#QuickNav") as HTMLElement;
if (bottomNav) {
bottomNav.style.display = "";
}
this.blob = null;
}
async takeImage(/* payload: MouseEvent */) {
const cameraComponent = this.$refs.camera as InstanceType<typeof Camera>;
console.log("cameraComponent", cameraComponent, cameraComponent.resolution);
console.log(
"cameraComponent on snapshot",
cameraComponent,
cameraComponent.resolution,
);
this.imageHeight = cameraComponent?.resolution?.height;
this.imageWidth = cameraComponent?.resolution?.width;
const initialImageRatio = this.imageWidth / this.imageHeight;
@ -141,12 +149,14 @@ export default class GiftedPhotoDialog extends Vue {
window.innerHeight,
);
if (initialImageRatio > 1 && windowRatio < 1) {
// the image is wider than it is tall, and the window is taller than it is wide
this.imageWarning = "?";
// For some reason, mobile in portrait orientation renders a horizontally-stretched image.
// We're gonna force it opposite.
this.imageHeight = cameraComponent?.resolution?.width;
this.imageWidth = cameraComponent?.resolution?.height;
} else if (initialImageRatio < 1 && windowRatio > 1) {
// the image is taller than it is wide, and the window is wider than it is tall
// Haven't seen this happen, but just in case.
this.imageWarning = "??";
this.imageHeight = cameraComponent?.resolution?.width;
@ -160,9 +170,11 @@ export default class GiftedPhotoDialog extends Vue {
this.imageHeight,
);
if (newImageRatio < windowRatio) {
// the image is a taller ratio than the window, so fit the height first
this.imageHeight = window.innerHeight / 2;
this.imageWidth = this.imageHeight * newImageRatio;
} else {
// the image is a wider ratio than the window, so fit the width first
this.imageWidth = window.innerWidth / 2;
this.imageHeight = this.imageWidth / newImageRatio;
}
@ -211,9 +223,9 @@ export default class GiftedPhotoDialog extends Vue {
}
}
photoSnapped() {
console.log("snap_photo clicked");
const video = document.querySelector("#video");
const canvas = document.querySelector("#canvas");
console.log("snap_photo clicked");
if (
canvas instanceof HTMLCanvasElement &&
video instanceof HTMLVideoElement
@ -221,9 +233,17 @@ export default class GiftedPhotoDialog extends Vue {
canvas
?.getContext("2d")
?.drawImage(video, 0, 0, canvas.width, canvas.height);
const image_data_url = canvas?.toDataURL("image/jpeg");
// ... or set the blob:
// canvas?.toBlob(
// (blob) => {
// this.blob = blob;
// },
// "image/jpeg",
// 1,
// );
// data url of the image
const image_data_url = canvas?.toDataURL("image/jpeg");
console.log(image_data_url);
}
}

Loading…
Cancel
Save