From b436d3b8e93d01c27178a8d70a27ea195c90b85d Mon Sep 17 00:00:00 2001 From: Mike Fitzpatrick Date: Sun, 3 Jun 2018 16:39:51 -0400 Subject: [PATCH] - Hooked up profile submission - Fixed swipe actions (between profiles / detail toggle) --- package.json | 8 ++--- src/pages/grid/grid.ts | 1 + src/pages/profile/profile.html | 12 ++++++-- src/pages/profile/profile.scss | 25 ++++++++++++++++ src/pages/profile/profile.ts | 20 ++++++++----- src/pages/tell/tell.html | 10 +++++-- src/pages/tell/tell.ts | 53 ++++++++++++++++++++++++++++++++-- src/services/profiles.ts | 40 +++++++++++++++++++++---- 8 files changed, 144 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index a6184c9..ecdf1e9 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "urge", - "version": "0.0.1", - "author": "Ionic Framework", - "homepage": "http://ionicframework.com/", + "name": "looking", + "version": "2.0.0", + "author": "Mike Fitzpatrick", + "homepage": "http://fitz.guru/", "private": true, "scripts": { "clean": "ionic-app-scripts clean", diff --git a/src/pages/grid/grid.ts b/src/pages/grid/grid.ts index 029ab53..9aafe01 100644 --- a/src/pages/grid/grid.ts +++ b/src/pages/grid/grid.ts @@ -43,6 +43,7 @@ export class GridPage { profileTapped(event, profile) { this.navCtrl.push(ProfilePage, { profile: profile, + profileService: this.profileService }); } } diff --git a/src/pages/profile/profile.html b/src/pages/profile/profile.html index f8958c6..4f16564 100644 --- a/src/pages/profile/profile.html +++ b/src/pages/profile/profile.html @@ -1,4 +1,4 @@ - + + + + @@ -15,7 +23,7 @@
- + diff --git a/src/pages/profile/profile.scss b/src/pages/profile/profile.scss index 90139e4..26008e3 100644 --- a/src/pages/profile/profile.scss +++ b/src/pages/profile/profile.scss @@ -32,6 +32,31 @@ page-profile { } } + .profile-nav { + color: #ffffff; + display: none; + position: absolute; + top: 50%; + transform: translateY(-50%); + z-index: 100; + + @media screen and (min-width: 769px) { + display: block; + + &.hidden { + display: none; + } + } + + &.profile-next { + right: 0; + } + + &.profile-previous { + left: 0; + } + } + .button-chat { background-color: #050505; border-radius: 50%; diff --git a/src/pages/profile/profile.ts b/src/pages/profile/profile.ts index ee32bf8..2939ded 100644 --- a/src/pages/profile/profile.ts +++ b/src/pages/profile/profile.ts @@ -4,22 +4,24 @@ import { NavController, NavParams } from 'ionic-angular'; import { ChatPage } from '../chat/chat'; import { LightboxPage } from '../lightbox/lightbox'; -import { ProfileService } from '../../services/profiles'; @Component({ selector: 'page-profile', - templateUrl: 'profile.html', - providers: [ ProfileService ] + templateUrl: 'profile.html' }) export class ProfilePage { detailsOpen: boolean = false; profile: any; + profileService: any; + profileType: string = 'all'; tabNavEl: any; - constructor(public navCtrl: NavController, public navParams: NavParams, public profileService: ProfileService, private _sanitizer: DomSanitizer) { + constructor(public navCtrl: NavController, public navParams: NavParams, private _sanitizer: DomSanitizer) { this.profile = navParams.get('profile'); + this.profileType = this.profile.submitted ? 'submitted' : 'verified'; + this.profileService = navParams.get('profileService'); this.tabNavEl = document.querySelector('#tab-nav .tabbar'); } @@ -34,6 +36,8 @@ export class ProfilePage { closeProfileDetails(event) { if (this.detailsOpen) { this.detailsOpen = false; + document.querySelector('.profile-nav.profile-next').classList.remove('hidden'); + document.querySelector('.profile-nav.profile-previous').classList.remove('hidden'); document.querySelector('.profile-toolbar').classList.remove('hidden'); document.getElementById('detail-overlay').classList.remove('open'); } @@ -48,8 +52,7 @@ export class ProfilePage { } nextProfile(event) { - this.profile = this.profileService.getNextProfile(this.profile._id); - this.navCtrl.setRoot(this.navCtrl.getActive().component); + this.profile = this.profileService.getNextProfile(this.profile._id, this.profileType); } openChat(event, profile) { @@ -61,14 +64,15 @@ export class ProfilePage { openProfileDetails(event) { if (!this.detailsOpen) { this.detailsOpen = true; + document.querySelector('.profile-nav.profile-next').classList.add('hidden'); + document.querySelector('.profile-nav.profile-previous').classList.add('hidden'); document.querySelector('.profile-toolbar').classList.add('hidden'); document.getElementById('detail-overlay').classList.add('open'); } } previousProfile(event) { - this.profile = this.profileService.getPreviousProfile(this.profile._id); - this.navCtrl.setRoot(this.navCtrl.getActive().component); + this.profile = this.profileService.getPreviousProfile(this.profile._id, this.profileType); } showLightbox(event, image) { diff --git a/src/pages/tell/tell.html b/src/pages/tell/tell.html index 3ddddc7..2f17341 100644 --- a/src/pages/tell/tell.html +++ b/src/pages/tell/tell.html @@ -15,11 +15,11 @@
-
@@ -27,6 +27,10 @@ Display name + + Email Address + + About you @@ -36,7 +40,7 @@
- +
diff --git a/src/pages/tell/tell.ts b/src/pages/tell/tell.ts index 87af273..37e07da 100644 --- a/src/pages/tell/tell.ts +++ b/src/pages/tell/tell.ts @@ -12,28 +12,75 @@ import { ProfileService } from '../../services/profiles'; export class TellYourStoryPage { tabNavEl: any; + fileInput: any; + fileLabel: any; userSubmissionForm: FormGroup; - constructor(public navCtrl: NavController, private formBuilder: FormBuilder) { + constructor(public navCtrl: NavController, public profileService: ProfileService, private formBuilder: FormBuilder) { this.tabNavEl = document.querySelector('#tab-nav .tabbar'); this.userSubmissionForm = this.formBuilder.group({ name: [''], about: [''], - pic: [''], + email: [''], messages: [''] }); } ionViewWillEnter() { this.tabNavEl.style.display = 'none'; + this.fileInput = document.querySelector('.file-input'); + this.fileLabel = document.querySelector('.file-label'); + + this.fileInput.addEventListener('change', this.handleFileChange.bind(this), false); } close(event) { this.navCtrl.pop(); } - saveUserSubmission() { + handleFileChange(event) { + this.fileLabel.style.backgroundImage = this.fileInput.files[0]; + //this.fileLabel.querySelector('ion-icon').style.display = none; + } + saveUserSubmission(event) { + var fileInput = document.querySelector('.file-input'); + + // Setup submission for insert + var submission = { + profile: { + details: { + name: this.userSubmissionForm.value.name, + email: this.userSubmissionForm.value.email, + about: this.userSubmissionForm.value.about, + location: this.userSubmissionForm.value.location + }, + messages: [ + { + text: "What is your your experience dating in the LGBT community?", + isUser: false, + timestamp: (Date.now() - 900000) + }, + { + text: this.userSubmissionForm.value.messages, + isUser: true, + timestamp: Date.now() + } + ], + submitted: true + }, + image: this.fileInput.files[0], + }; + + submission.profile = JSON.stringify(submission.profile); + + this.profileService.doProfileSubmission(submission, + function (data) { + console.debug('saveUserSubmission Success', data); + }, + function (data, status) { + console.error('saveUserSubmission Error', data, status); + }); } } diff --git a/src/services/profiles.ts b/src/services/profiles.ts index 5b1f2ce..b7c3968 100644 --- a/src/services/profiles.ts +++ b/src/services/profiles.ts @@ -7,6 +7,7 @@ export class ProfileService { endpoint: string = 'https://api.fitz.guru/urnings/profiles'; fallback: string = 'assets/data/profiles.json'; + epSubmission: string = '/submission'; epSubmitted: string = '/submitted'; epVerified: string = '/verified'; idMap: any; @@ -19,8 +20,8 @@ export class ProfileService { } load() { - if (this.profiles) { - return Promise.resolve(this.profiles); + if (this.profiles && this.profiles.all) { + return Promise.resolve(this.profiles.all); } return new Promise(resolve => { @@ -64,7 +65,36 @@ export class ProfileService { error => { this.doGetRequest(this.fallback, resolve, type); } - ) + ); + } + + doProfileSubmission(submission, success = false, failure = false) { + success = success || function (data) { + console.debug('doProfileSubmission Success', data); + }; + + failure = failure || function (data, status) { + console.error('doProfileSubmission Error', data, status); + }; + + var httpOptions = { + headers: { + 'Content-Type': 'multipart/form-data' + } + }; + + var formData = new FormData(); + for (let property in submission) { + formData.append(property, submission[property]); + } + + this.http + .post(this.endpoint + this.epSubmission, formData, httpOptions) + .subscribe(data => { + success(data); + }, error => { + failure(error, false); + }); } getNextProfile(id, type = 'all') { @@ -83,8 +113,8 @@ export class ProfileService { return this.profiles.all; } - getProfileById(id) { - return this.profiles[this.idMap[id]]; + getProfileById(id, type = 'all') { + return this.profiles[type][this.idMap[type][id]]; } getSubmittedProfiles() {