Skip to content

Commit

Permalink
deployed functions, working 3d model
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcatbuzz committed May 19, 2024
1 parent ae666c8 commit a5d6e9a
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 81 deletions.
20 changes: 20 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@
}
]
},
"database": {
"rules": "database.rules.json"
},
"functions": [
{
"source": "functions",
"logLevel": "debug",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"storage": {
"rules": "storage.rules"
}
Expand Down
30 changes: 15 additions & 15 deletions functions/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ module.exports = {
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'google',
'plugin:@typescript-eslint/recommended',
],
parser: "@typescript-eslint/parser",
parser: '@typescript-eslint/parser',
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
'/lib/**/*', // Ignore built files.
],
plugins: [
"@typescript-eslint",
"import",
'@typescript-eslint',
'import',
],
rules: {
"quotes": ["error", "single"],
"import/no-unresolved": 0,
"indent": ["error", 2],
'quotes': ['error', 'single'],
'import/no-unresolved': 0,
'indent': ['error', 2],
},
};
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ require('dotenv').config();
import {initializeApp} from 'firebase-admin/app';
initializeApp();

export {sendContactMessage} from './sendgrid';
export {sendContactMessageV2} from './sendgrid';
export {checkRecaptcha} from './recaptcha';
3 changes: 2 additions & 1 deletion functions/src/recaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const checkRecaptcha = onRequest((req, res) => {
// 'http://localhost:8080'
res.set('Access-Control-Allow-Origin', 'https://anthonybuzzelli.dev');
res.setHeader('Content-Type', 'application/json');
const token = req.query.token;
const token = req.body.token;
// recommended from Claude const token = req.body.token
console.log(token, 'what is here');
try {
const response = await axios.get(`https://recaptcha.google.com/recaptcha/api/siteverify?secret=${SECRET_KEY}&response=${token}`);
Expand Down
2 changes: 1 addition & 1 deletion functions/src/sendgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sgMail = require('@sendgrid/mail');
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY;
sgMail.setApiKey(SENDGRID_API_KEY);

export const sendContactMessage = onValueWritten(
export const sendContactMessageV2 = onValueWritten(
'messages/{pushkey}', async (change) => {
const dataAfterChange = change.data.after.val();
if (change.data.before.val() || !dataAfterChange.subject) {
Expand Down
52 changes: 52 additions & 0 deletions src/app/animations/nav-animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { NavOptions, createAnimation } from '@ionic/core';

interface TransitionOptions extends NavOptions {
progressCallback?: (ani: Animation | undefined) => void;
baseEl: any;
enteringEl: HTMLElement;
// leavingEl: HTMLElement | undefined;
leavingEl: HTMLElement;
}

function getIonPageElement(element: HTMLElement) {
if (element.classList.contains('ion-page')) {
return element;
}

const ionPage = element.querySelector(
':scope > .ion-page, :scope > ion-nav, :scope > ion-tabs'
);
if (ionPage) {
return ionPage;
}

return element;
}

export function pageTransition(_: HTMLElement, opts: TransitionOptions) {
const DURATION = 600;

const rootTransition = createAnimation()
.duration(opts.duration || DURATION)
.easing('cubic-bezier(0.3,0,0.66,1)');

const enteringPage = createAnimation()
.addElement(getIonPageElement(opts.enteringEl))
.beforeRemoveClass('ion-page-invisible');

const leavingPage = createAnimation().addElement(
getIonPageElement(opts.leavingEl)
);

if (opts.direction === 'forward') {
enteringPage.fromTo('transform', 'translateX(100%)', 'translateX(0)');
leavingPage.fromTo('opacity', '1', '0.25');
} else {
leavingPage.fromTo('transform', 'translateX(0)', 'translateX(100%)');
enteringPage.fromTo('opacity', '0.25', '1');
}

rootTransition.addAnimation(enteringPage);
rootTransition.addAnimation(leavingPage);
return rootTransition;
}
15 changes: 3 additions & 12 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@
<ion-menu contentId="main-content" type="overlay">
<ion-content>
<ion-list id="inbox-list">
<ion-list-header>Inbox</ion-list-header>
<ion-note>hi&#64;ionicframework.com</ion-note>

<ion-list-header>Anthony Buzzelli</ion-list-header>
<ion-menu-toggle auto-hide="false" *ngFor="let p of appPages; let i = index">
<ion-item routerDirection="root" [routerLink]="[p.url]" lines="none" detail="false" routerLinkActive="selected">
<ion-icon aria-hidden="true" slot="start" [ios]="p.icon + '-outline'" [md]="p.icon + '-sharp'"></ion-icon>
<ion-label>{{ p.title }}</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>

<ion-list id="labels-list">
<ion-list-header>Labels</ion-list-header>

<ion-item *ngFor="let label of labels" lines="none">
<ion-icon aria-hidden="true" slot="start" ios="bookmark-outline" md="bookmark-sharp"></ion-icon>
<ion-label>{{ label }}</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-menu>

<ion-router-outlet id="main-content"></ion-router-outlet>
<!-- <app-loading *ngIf="loading"></app-loading> -->
</ion-app>
4 changes: 0 additions & 4 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ ion-menu.md ion-list#inbox-list {
ion-menu.md ion-list#inbox-list ion-list-header {
font-size: 22px;
font-weight: 600;

min-height: 20px;
}

ion-menu.md ion-list#labels-list ion-list-header {
font-size: 16px;

margin-bottom: 18px;

color: #757575;

min-height: 26px;
}

Expand Down
30 changes: 17 additions & 13 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { IonApp, IonSplitPane, IonMenu, IonContent, IonList, IonListHeader, IonNote, IonMenuToggle, IonItem, IonIcon, IonLabel, IonRouterOutlet } from '@ionic/angular/standalone';
import { IonApp, IonMenu, IonContent, IonList, IonListHeader, IonNote, IonMenuToggle, IonItem, IonIcon, IonLabel, IonRouterOutlet } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { mailOutline, mailSharp, paperPlaneOutline, paperPlaneSharp, heartOutline, heartSharp, archiveOutline, archiveSharp, trashOutline, trashSharp, warningOutline, warningSharp, bookmarkOutline, bookmarkSharp } from 'ionicons/icons';
import { LoadingComponent } from './loading/loading.component';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
standalone: true,
imports: [RouterLink, RouterLinkActive, CommonModule, IonApp, IonSplitPane, IonMenu, IonContent, IonList, IonListHeader, IonNote, IonMenuToggle, IonItem, IonIcon, IonLabel, IonRouterOutlet],
imports: [RouterLink, RouterLinkActive, CommonModule, IonApp, IonMenu, IonContent, IonList, IonListHeader, IonNote, IonMenuToggle, IonItem, IonIcon, IonLabel, IonRouterOutlet, LoadingComponent],
})
export class AppComponent {
// loading = true;
// private router = inject(Router);
public appPages = [
{title:'Home', url: '/home', icon: 'mail'},
{ title:'Home', url: '/home', icon: 'mail' },
{ title: 'About', url: '/about', icon: 'mail' },
{ title: 'Projects', url: '/projects', icon: 'mail' },
{ title: 'Contact', url: '/contact', icon: 'mail' },

{ title: 'Inbox', url: '/folder/inbox', icon: 'mail' },
{ title: 'Outbox', url: '/folder/outbox', icon: 'paper-plane' },
{ title: 'Favorites', url: '/folder/favorites', icon: 'heart' },
{ title: 'Archived', url: '/folder/archived', icon: 'archive' },
{ title: 'Trash', url: '/folder/trash', icon: 'trash' },
{ title: 'Spam', url: '/folder/spam', icon: 'warning' },
];
public labels = ['Family', 'Friends', 'Notes', 'Work', 'Travel', 'Reminders'];
{ title: 'Contact', url: '/contact', icon: 'mail' }
]

constructor() {
addIcons({ mailOutline, mailSharp, paperPlaneOutline, paperPlaneSharp, heartOutline, heartSharp, archiveOutline, archiveSharp, trashOutline, trashSharp, warningOutline, warningSharp, bookmarkOutline, bookmarkSharp });

// this.router.events.subscribe(event => {
// if (event instanceof NavigationStart) {
// this.loading = true;
// } else if (event instanceof NavigationEnd) {
// this.loading = false;
// }
// })
}
}
95 changes: 66 additions & 29 deletions src/app/contact/contact.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit, inject } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { CommonModule } from '@angular/common';
// import { HttpClient } from '@angular/common/http';
// import { ReCaptchaV3Service } from 'ng-recaptcha';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ReCaptchaV3Service } from 'ng-recaptcha';
import { Router } from '@angular/router';
import { Database, push, ref, set } from '@angular/fire/database';
import { UIService } from '../ui.service';
Expand All @@ -21,9 +21,9 @@ import { FooterComponent } from '../footer/footer.component';
export class ContactComponent implements OnInit {
private db = inject(Database)
private uiService = inject(UIService)
// private http = inject(HttpClient)
private http = inject(HttpClient)
private router = inject(Router)
// private recaptchaService = inject(ReCaptchaV3Service)
private recaptchaService = inject(ReCaptchaV3Service)

constructor() { }

Expand Down Expand Up @@ -58,32 +58,69 @@ export class ContactComponent implements OnInit {
}

onSubmit() {
this.isSubmitted = true
const value = this.contactForm.value;
const name = value.name;
const email = value.email;
const subject = value.subject;
const message = value.message;

// this.isSubmitted = true
// const value = this.contactForm.value;
// const name = value.name;
// const email = value.email;
// const subject = value.subject;
// const message = value.message;
this.recaptchaService.execute('contact')
.subscribe((token) => {
console.log(token, 'token')
this.verifyRecaptcha(token);
})

const formRequest = { name, email, subject, message};
const messagesRef = ref(this.db, '/messages');
const newMessageRef = push(messagesRef);
set(newMessageRef, {...formRequest})
.then(() => {
// console.log(formRequest, 'What is showing here');
this.contactForm.reset();
this.uiService.presentToast('Your message was sent', 4000);
this.router.navigate(['/']);
})
.catch((error) => {
// console.log(error, 'Error in sending message');
this.uiService.presentToast('Error in sending message', 4000);
this.contactForm.reset();
this.isSubmitted = false;
this.router.navigate(['/']);
throw error;
});
// const formRequest = { name, email, subject, message};
// const messagesRef = ref(this.db, '/messages');
// const newMessageRef = push(messagesRef);
// set(newMessageRef, {...formRequest})
// .then(() => {
// // console.log(formRequest, 'What is showing here');
// this.contactForm.reset();
// this.uiService.presentToast('Your message was sent', 4000);
// this.router.navigate(['/']);
// })
// .catch((error) => {
// // console.log(error, 'Error in sending message');
// this.uiService.presentToast('Error in sending message', 4000);
// this.contactForm.reset();
// this.isSubmitted = false;
// this.router.navigate(['/']);
// throw error;
// });
}

verifyRecaptcha(token: string) {
const url = 'https://us-central1-ionicwebpage.cloudfunctions.net/checkRecaptcha';
const headers = new HttpHeaders().set('Content-Type', 'application/json')

this.http.post(url, { token }, { headers }).subscribe((response) => {
console.log(response, 'data')
this.isSubmitted = true
const value = this.contactForm.value;
const name = value.name;
const email = value.email;
const subject = value.subject;
const message = value.message;
const formRequest = { name, email, subject, message };
const messagesRef = ref(this.db, '/messages');
const newMessageRef = push(messagesRef);
set(newMessageRef, { ...formRequest })
.then(() => {
// console.log(formRequest, 'What is showing here');
this.contactForm.reset();
this.uiService.presentToast('Your message was sent', 4000);
this.router.navigate(['/']);
})
.catch((error) => {
// console.log(error, 'Error in sending message');
this.uiService.presentToast('Error in sending message', 4000);
this.contactForm.reset();
this.isSubmitted = false;
this.router.navigate(['/']);
throw error;
});
})
}

}
Loading

0 comments on commit a5d6e9a

Please sign in to comment.