add page to take a picture and upload to an image server

This commit is contained in:
2024-02-23 19:02:10 -07:00
parent c239db6a4f
commit c696de33f3
7 changed files with 118 additions and 3 deletions

View File

@@ -36,8 +36,16 @@
<fa icon="chevron-right" />
</div>
</div>
<div class="mt-2 text-right">
<span v-if="showGivenToUser" class="mr-16">
<div class="mt-2 flex justify-between">
<span>
<router-link
:to="{ name: 'gifted-photo' }"
class="bg-blue-500 text-white px-1.5 py-1 rounded-md"
>
<fa icon="camera" class="fa-fw" />
</router-link>
</span>
<span v-if="showGivenToUser">
<input type="checkbox" class="mr-2" v-model="givenToUser" />
<label class="text-sm">Given to you</label>
</span>

View File

@@ -18,6 +18,7 @@ import {
faBitcoinSign,
faBurst,
faCalendar,
faCamera,
faChevronLeft,
faChevronRight,
faCircle,
@@ -76,6 +77,7 @@ library.add(
faBitcoinSign,
faBurst,
faCalendar,
faCamera,
faChevronLeft,
faChevronRight,
faCircle,
@@ -127,9 +129,11 @@ library.add(
);
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import Camera from "simple-vue-camera";
createApp(App)
.component("fa", FontAwesomeIcon)
.component("camera", Camera)
.use(createPinia())
.use(VueAxios, axios)
.use(router)

View File

@@ -84,6 +84,12 @@ const routes: Array<RouteRecordRaw> = [
component: () =>
import(/* webpackChunkName: "discover" */ "../views/DiscoverView.vue"),
},
{
path: "/gifted-photo",
name: "gifted-photo",
component: () =>
import(/* webpackChunkName: "gifted-photo" */ "../views/GiftedPhoto.vue"),
},
{
path: "/help",
name: "help",

89
src/views/GiftedPhoto.vue Normal file
View File

@@ -0,0 +1,89 @@
<template>
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb -->
<div class="mb-8">
<!-- Back -->
<div class="text-lg text-center font-light relative px-7">
<h1
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
@click="$router.back()"
>
<fa icon="chevron-left" class="fa-fw"></fa>
</h1>
</div>
<!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4">
Photo
</h1>
</div>
<div v-if="localImageUrl">
Dude, you got an image! Dude, you got an image!
</div>
<div v-else>
<camera
:resolution="{ width: 375, height: 812 }"
facingMode="user"
autoplay
ref="camera"
>
<button @click="storeImage">I'm on top of the video</button>
</camera>
</div>
</section>
</template>
<script lang="ts">
import axios from "axios";
import Camera from "simple-vue-camera";
import { Component, Vue } from "vue-facing-decorator";
interface Notification {
group: string;
type: string;
title: string;
text: string;
}
@Component({ components: { Camera } })
export default class GiftedPhoto extends Vue {
$notify!: (notification: Notification, timeout?: number) => void;
localImageUrl: string | null = null;
async storeImage(/* payload: MouseEvent */) {
const cameraComponent = this.$refs.camera as InstanceType<typeof Camera>;
const blob = await cameraComponent?.snapshot();
if (!blob) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: "There was an error taking the picture. Please try again.",
},
-1,
);
return;
}
//this.localImageUrl = URL.createObjectURL(blob);
console.log("Got an image:", blob?.size);
const formData = new FormData();
formData.append("image", blob, "snapshot.jpg");
try {
const response = await axios.post(
"http://localhost:3000/image",
formData,
);
console.log("Upload successful", response.data);
} catch (error) {
console.error("Error uploading the image", error);
}
}
}
</script>