forked from trent_larson/crowd-funder-for-time-pwa
add file-chooser to the profile image selection
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
backgroundColor: '#f8f8f8',
|
||||
margin: 'auto',
|
||||
}"
|
||||
:img="URL.createObjectURL(blob)"
|
||||
:img="createBlobURL(blob)"
|
||||
:options="{
|
||||
viewMode: 1,
|
||||
dragMode: 'crop',
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
<div v-else>
|
||||
<div class="flex justify-center">
|
||||
<img :src="URL.createObjectURL(blob)" class="mt-2 rounded" />
|
||||
<img :src="createBlobURL(blob)" class="mt-2 rounded" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="absolute bottom-[1rem] left-[1rem] px-2 py-1">
|
||||
@@ -60,7 +60,10 @@
|
||||
<span>Upload</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="absolute bottom-[1rem] right-[1rem] px-2 py-1">
|
||||
<div
|
||||
v-if="showRetry"
|
||||
class="absolute bottom-[1rem] right-[1rem] px-2 py-1"
|
||||
>
|
||||
<button
|
||||
@click="retryImage"
|
||||
class="bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white py-1 px-2 rounded-md"
|
||||
@@ -127,17 +130,19 @@ import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
|
||||
import { accessToken } from "@/libs/crypto";
|
||||
|
||||
@Component({ components: { Camera, VuePictureCropper } })
|
||||
export default class GiftedPhotoDialog extends Vue {
|
||||
export default class PhotoDialog extends Vue {
|
||||
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
||||
|
||||
activeDeviceNumber = 0;
|
||||
activeDid = "";
|
||||
blob: Blob | null = null;
|
||||
blob?: Blob;
|
||||
claimType = "GiveAction";
|
||||
crop = false;
|
||||
fileName?: string;
|
||||
mirror = false;
|
||||
numDevices = 0;
|
||||
setImage: (arg: string) => void = () => {};
|
||||
setImageCallback: (arg: string) => void = () => {};
|
||||
showRetry = true;
|
||||
uploading = false;
|
||||
visible = false;
|
||||
|
||||
@@ -163,7 +168,13 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
open(setImageFn: (arg: string) => void, crop?: boolean, claimType?: string) {
|
||||
open(
|
||||
setImageFn: (arg: string) => void,
|
||||
crop?: boolean,
|
||||
claimType?: string,
|
||||
blob?: Blob, // for image upload, just to use the cropping function
|
||||
inputFileName?: string,
|
||||
) {
|
||||
this.visible = true;
|
||||
this.crop = !!crop;
|
||||
this.claimType = claimType || "GiveAction";
|
||||
@@ -171,7 +182,16 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
if (bottomNav) {
|
||||
bottomNav.style.display = "none";
|
||||
}
|
||||
this.setImage = setImageFn;
|
||||
this.setImageCallback = setImageFn;
|
||||
if (blob) {
|
||||
this.blob = blob;
|
||||
this.fileName = inputFileName;
|
||||
this.showRetry = false;
|
||||
} else {
|
||||
this.blob = undefined;
|
||||
this.fileName = undefined;
|
||||
this.showRetry = true;
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
@@ -180,7 +200,7 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
if (bottomNav) {
|
||||
bottomNav.style.display = "";
|
||||
}
|
||||
this.blob = null;
|
||||
this.blob = undefined;
|
||||
}
|
||||
|
||||
async cameraStarted() {
|
||||
@@ -236,10 +256,13 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
|
||||
// The resolution is only necessary because of that mobile portrait-orientation case.
|
||||
// The mobile emulation in a browser shows something stretched vertically, but real devices work fine.
|
||||
this.blob = await cameraComponent?.snapshot({
|
||||
height: imageHeight,
|
||||
width: imageWidth,
|
||||
}); // png is default; if that changes, change extension in formData.append
|
||||
this.blob =
|
||||
(await cameraComponent?.snapshot({
|
||||
height: imageHeight,
|
||||
width: imageWidth,
|
||||
})) || undefined;
|
||||
// png is default
|
||||
this.fileName = "snapshot.png";
|
||||
if (!this.blob) {
|
||||
this.$notify(
|
||||
{
|
||||
@@ -254,8 +277,13 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
private createBlobURL(blob: Blob): string {
|
||||
console.log("blob", blob);
|
||||
return URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
async retryImage() {
|
||||
this.blob = null;
|
||||
this.blob = undefined;
|
||||
}
|
||||
|
||||
/****
|
||||
@@ -307,7 +335,7 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
this.uploading = true;
|
||||
|
||||
if (this.crop) {
|
||||
this.blob = await cropper?.getBlob();
|
||||
this.blob = (await cropper?.getBlob()) || undefined;
|
||||
}
|
||||
|
||||
const identifier = await getIdentity(this.activeDid);
|
||||
@@ -330,7 +358,7 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
this.uploading = false;
|
||||
return;
|
||||
}
|
||||
formData.append("image", this.blob, "snapshot.png");
|
||||
formData.append("image", this.blob, this.fileName || "snapshot.png");
|
||||
formData.append("claimType", this.claimType);
|
||||
try {
|
||||
const response = await axios.post(
|
||||
@@ -341,8 +369,8 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
this.uploading = false;
|
||||
|
||||
this.visible = false;
|
||||
this.blob = null;
|
||||
this.setImage(response.data.url as string);
|
||||
this.blob = undefined;
|
||||
this.setImageCallback(response.data.url as string);
|
||||
} catch (error) {
|
||||
console.error("Error uploading the image", error);
|
||||
this.$notify(
|
||||
@@ -355,7 +383,7 @@ export default class GiftedPhotoDialog extends Vue {
|
||||
5000,
|
||||
);
|
||||
this.uploading = false;
|
||||
this.blob = null;
|
||||
this.blob = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user