Skip to content

Instantly share code, notes, and snippets.

@ryanhugh
Created August 25, 2019 21:53
Show Gist options
  • Save ryanhugh/d2f33b87f8891fb8f29b8d16433e2498 to your computer and use it in GitHub Desktop.
Save ryanhugh/d2f33b87f8891fb8f29b8d16433e2498 to your computer and use it in GitHub Desktop.
Spread diff, unused and never merged into master
From c9d9bfc2eda631e30dfe940a0d33766bef595f6a Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Mon, 21 May 2018 15:11:18 +0900
Subject: [PATCH 01/12] start
---
backend/scrapers/employees/matchEmployees.js | 2 +-
backend/server.js | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/backend/scrapers/employees/matchEmployees.js b/backend/scrapers/employees/matchEmployees.js
index c7ab006d..8a8f2689 100644
--- a/backend/scrapers/employees/matchEmployees.js
+++ b/backend/scrapers/employees/matchEmployees.js
@@ -328,7 +328,7 @@ class CombineCCISandEmployees {
}
if (output[attrName] && output[attrName] !== profile[attrName]) {
- macros.log('Overriding ', output[attrName], '\twith', profile[attrName]);
+ macros.log('Overriding ', output[attrName], '\twith', profile[attrName], '(Name: ', person.firstName, person.lastName, ')');
}
diff --git a/backend/server.js b/backend/server.js
index bf1bb430..5b042f59 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -511,6 +511,8 @@ async function onSendToMessengerButtonClick(sender, userPageId, b64ref) {
facebookMessengerId: sender,
facebookPageId: userPageId,
loginKeys: [userObject.loginKey],
+ referrals: 0,
+ points: 0,
};
macros.log('Adding ', newUser, 'to the db');
From 1603ddf7099e0f24060823062914e7994f491498 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Thu, 24 May 2018 22:03:53 +0800
Subject: [PATCH 02/12] worked on spread some
---
backend/server.js | 5 +
backend/updater.js | 2 +-
frontend/components/Home.js | 2 +
frontend/components/ReferModal.js | 150 ++++++++++++++++++++++++++
frontend/components/authentication.js | 19 +++-
5 files changed, 173 insertions(+), 5 deletions(-)
create mode 100644 frontend/components/ReferModal.js
diff --git a/backend/server.js b/backend/server.js
index 5b042f59..2c7d3e05 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -511,7 +511,12 @@ async function onSendToMessengerButtonClick(sender, userPageId, b64ref) {
facebookMessengerId: sender,
facebookPageId: userPageId,
loginKeys: [userObject.loginKey],
+
+ // How many people they have referred. This only goes up and is never decremented.
referrals: 0,
+
+ // This is the user's score. This goes up by 3 for every referral and down by 1 for every notification they are sent.
+ // Each 1 pt advantage means 30 min advantage.
points: 0,
};
diff --git a/backend/updater.js b/backend/updater.js
index da984294..47a55a3e 100644
--- a/backend/updater.js
+++ b/backend/updater.js
@@ -304,7 +304,7 @@ class Updater {
// This should never run.
// The user should not be able to sign up for a section that didn't exist when they were signing up.
if (!oldSection) {
- macros.error('Section was added?', hash, newSection);
+ macros.warn('Section was added?', hash, newSection, sectionHashToUsers, classHashToUsers);
continue;
}
diff --git a/frontend/components/Home.js b/frontend/components/Home.js
index 74449c2d..d26bddfb 100644
--- a/frontend/components/Home.js
+++ b/frontend/components/Home.js
@@ -15,6 +15,7 @@ import aoun from './aouuuuuuuuun.png';
import SplashPage from './SplashPage/SplashPage';
import search from './search';
import FeedbackModal from './FeedbackModal';
+import ReferModal from './ReferModal';
import macros from './macros';
import ResultsLoader from './ResultsLoader';
import logo from './logo.svg';
@@ -602,6 +603,7 @@ class Home extends React.Component {
</div>
<FeedbackModal closeForm={ this.closeForm } feedbackModalOpen={ this.state.feedbackModalOpen } />
+ <ReferModal />
<ReactTooltip effect='solid' className='listIconTooltip' />
</div>
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
new file mode 100644
index 00000000..0ae30aec
--- /dev/null
+++ b/frontend/components/ReferModal.js
@@ -0,0 +1,150 @@
+/*
+ * This file is part of Search NEU and licensed under AGPL3.
+ * See the license file in the root folder for details.
+ */
+
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Button, Icon, Modal, Header, TextArea, Input, Form, Message } from 'semantic-ui-react';
+import { Transition } from 'react-transition-group';
+
+import authentication from './authentication';
+import macros from './macros';
+import request from './request';
+
+// This modal pops up after someone signs up for notifications
+// It provides the user with some information that they can use to refer other people to the site (eg. a url, share on FB, etc)
+
+class ReferModal extends React.Component {
+ // The bool of whether this modal is open is kept in here.
+
+ constructor(props) {
+ super(props);
+
+ this.state = {
+
+ // The value of hte message box.
+ isOpen: '',
+ };
+
+ // this.onTextAreaChange = this.onTextAreaChange.bind(this);
+ // this.onContactChange = this.onContactChange.bind(this);
+ // this.hideMessage = this.hideMessage.bind(this);
+ // this.onSubmit = this.onSubmit.bind(this);
+
+ this.initialize();
+ }
+
+ async initialize() {
+
+ debugger
+
+ let facebookApi = await authentication.getFacebookApi();
+
+ facebookApi.Event.subscribe('send_to_messenger', (e) => {
+ if (e.event === 'opt_in') {
+ macros.log("Opening referral modal.")
+ this.setState({
+ isOpen: true
+ })
+ }
+ });
+ }
+
+ async onSubmit() {
+
+ const response = await request.post({
+ url: '/submitFeedback',
+ body: {
+ message: this.state.messageValue,
+ contact: this.state.contactValue,
+ },
+ });
+
+ if (response.error) {
+ macros.error('Unable to submit feedback', response.error, this.state.messageValue, this.state.contactValue);
+ }
+
+ this.setState({
+ messageVisible: true,
+ messageValue: '',
+ contactValue: '',
+ });
+
+ // Hide the message after 2 seconds
+ setTimeout(() => {
+ this.setState({
+ messageVisible: false,
+ });
+ }, 2000);
+
+ this.props.closeForm();
+ }
+
+ onTextAreaChange(event) {
+ this.setState({
+ messageValue: event.target.value,
+ });
+ }
+
+ onContactChange(event) {
+ this.setState({
+ contactValue: event.target.value,
+ });
+ }
+
+ hideMessage() {
+ this.setState({
+ messageVisible: false,
+ });
+ }
+
+ render() {
+ const transitionStyles = {
+ entering: { opacity: 0 },
+ entered: { opacity: 1 },
+ exited: { display: 'none', opacity: 0 },
+ };
+
+ return (
+ <div className='feedback-container'>
+ <Transition in={ this.state.messageVisible } timeout={ 500 }>
+ {(state) => {
+ return (
+ <Message
+ success
+ className='alertMessage'
+ header='Your submission was successful.'
+ style={{ ...transitionStyles[state] }}
+ onDismiss={ this.hideMessage }
+ />
+ );
+ }}
+ </Transition>
+ <Modal open={ this.props.feedbackModalOpen } onClose={ this.props.closeForm } size='small' className='feedback-modal-container'>
+ <Header icon='mail' content='Search NEU Feedback' />
+ <Modal.Content className='formModalContent'>
+ <Form>
+ <div className='feedbackParagraph'>Find a bug in Search NEU? Find a query that dosen&apos;t come up with the results you were looking for? Have an idea for an improvement or just want to say hi? Drop a line below! Feel free to write whatever you want to and someone on the team will read it.</div>
+ <TextArea name='response' form='feedbackForm' className='feedbackTextbox' onChange={ this.onTextAreaChange } />
+ <p>By default this form is anonymous. Leave your name and/or email if you want us to be able to contact you.</p>
+ <Input name='contact' form='feedbackForm' className='formModalInput' onChange={ this.onContactChange } />
+ </Form>
+ </Modal.Content>
+ <Modal.Actions>
+ <Button basic color='red' onClick={ this.props.closeForm }>
+ <Icon name='remove' />
+ Cancel
+ </Button>
+ <Button type='submit' color='green' form='feedbackForm' onClick={ this.onSubmit }>
+ <Icon name='checkmark' />
+ Submit
+ </Button>
+ </Modal.Actions>
+ </Modal>
+ </div>
+ );
+ }
+}
+
+export default ReferModal;
diff --git a/frontend/components/authentication.js b/frontend/components/authentication.js
index 9fe7067d..7c9e8b53 100644
--- a/frontend/components/authentication.js
+++ b/frontend/components/authentication.js
@@ -8,10 +8,6 @@ import randomstring from 'randomstring';
import request from './request';
import macros from './macros';
-// TODO: add check to see if the user is logged in or not:
-// https://developers.facebook.com/docs/reference/javascript
-// https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus
-
// Eventually, this can be used to get the current user data from the server.
class Authentication {
@@ -29,6 +25,13 @@ class Authentication {
this.successfullyRendered = false;
this.onSendToMessengerClick = this.onSendToMessengerClick.bind(this);
+
+
+ this.facebookApiPromiseResolver = null;
+
+ this.facebookApiPromise = new Promise((resolve) => {
+ this.facebookApiPromiseResolver = null;
+ })
this.downloadUserData();
}
@@ -39,6 +42,12 @@ class Authentication {
downloadUserData() {
}
+
+ // This returns the window.FB after it has finished loading.
+ // If you use window.FB directly, there is a chance that it dosen't exist yet and the code may crash.
+ async getFacebookAPI() {
+ return this.facebookApiPromise;
+ }
initFB() {
@@ -51,6 +60,8 @@ class Authentication {
window.FB.Event.subscribe('send_to_messenger', this.onSendToMessengerClick);
+
+ this.facebookApiPromiseResolver(window.FB);
}
getLoginKey() {
From 97d37c3bad18fce12faae9707b2eef62dc6c8001 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Sun, 27 May 2018 22:45:11 +0800
Subject: [PATCH 03/12] .
---
frontend/components/ReferModal.js | 4 +---
frontend/components/authentication.js | 1 -
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 0ae30aec..ef5a9333 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -37,9 +37,7 @@ class ReferModal extends React.Component {
async initialize() {
- debugger
-
- let facebookApi = await authentication.getFacebookApi();
+ let facebookApi = await authentication.getFacebookAPI();
facebookApi.Event.subscribe('send_to_messenger', (e) => {
if (e.event === 'opt_in') {
diff --git a/frontend/components/authentication.js b/frontend/components/authentication.js
index 7c9e8b53..17934bc7 100644
--- a/frontend/components/authentication.js
+++ b/frontend/components/authentication.js
@@ -58,7 +58,6 @@ class Authentication {
version : 'v2.11',
});
-
window.FB.Event.subscribe('send_to_messenger', this.onSendToMessengerClick);
this.facebookApiPromiseResolver(window.FB);
From c879f30013e96733136eae4afa218d139cee7d77 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Sun, 27 May 2018 23:32:03 +0800
Subject: [PATCH 04/12] .
---
frontend/components/FeedbackModal.js | 2 +-
frontend/components/ReferModal.js | 23 +++++++----------------
frontend/components/authentication.js | 2 +-
3 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/frontend/components/FeedbackModal.js b/frontend/components/FeedbackModal.js
index 14f244df..b441a292 100644
--- a/frontend/components/FeedbackModal.js
+++ b/frontend/components/FeedbackModal.js
@@ -26,7 +26,7 @@ class FeedbackModal extends React.Component {
this.state = {
- // The value of hte message box.
+ // The value of the message box.
messageValue: '',
// The value of the contact box.
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index ef5a9333..19517042 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -23,8 +23,8 @@ class ReferModal extends React.Component {
this.state = {
- // The value of hte message box.
- isOpen: '',
+ // The value of the message box.
+ isOpen: false,
};
// this.onTextAreaChange = this.onTextAreaChange.bind(this);
@@ -34,6 +34,10 @@ class ReferModal extends React.Component {
this.initialize();
}
+
+ componentDidMount() {
+ macros.log("componentDidMount rfere modal")
+ }
async initialize() {
@@ -106,20 +110,7 @@ class ReferModal extends React.Component {
return (
<div className='feedback-container'>
- <Transition in={ this.state.messageVisible } timeout={ 500 }>
- {(state) => {
- return (
- <Message
- success
- className='alertMessage'
- header='Your submission was successful.'
- style={{ ...transitionStyles[state] }}
- onDismiss={ this.hideMessage }
- />
- );
- }}
- </Transition>
- <Modal open={ this.props.feedbackModalOpen } onClose={ this.props.closeForm } size='small' className='feedback-modal-container'>
+ <Modal open={ this.isOpen } onClose={ this.props.closeForm } size='small' className='feedback-modal-container'>
<Header icon='mail' content='Search NEU Feedback' />
<Modal.Content className='formModalContent'>
<Form>
diff --git a/frontend/components/authentication.js b/frontend/components/authentication.js
index 17934bc7..5e6df964 100644
--- a/frontend/components/authentication.js
+++ b/frontend/components/authentication.js
@@ -30,7 +30,7 @@ class Authentication {
this.facebookApiPromiseResolver = null;
this.facebookApiPromise = new Promise((resolve) => {
- this.facebookApiPromiseResolver = null;
+ this.facebookApiPromiseResolver = resolve;
})
this.downloadUserData();
From 8d1f5798b9fbcecf68e68064877337fe8eeb744e Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Mon, 28 May 2018 11:37:49 +0800
Subject: [PATCH 05/12] form now pops up and goes away when you click the
button
---
frontend/components/ReferModal.js | 63 +++++++------------------------
1 file changed, 13 insertions(+), 50 deletions(-)
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 19517042..735e497d 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -32,11 +32,16 @@ class ReferModal extends React.Component {
// this.hideMessage = this.hideMessage.bind(this);
// this.onSubmit = this.onSubmit.bind(this);
+ this.closeForm = this.closeForm.bind(this);
+
this.initialize();
}
componentDidMount() {
macros.log("componentDidMount rfere modal")
+ this.setState({
+ isOpen: false
+ })
}
async initialize() {
@@ -53,52 +58,10 @@ class ReferModal extends React.Component {
});
}
- async onSubmit() {
-
- const response = await request.post({
- url: '/submitFeedback',
- body: {
- message: this.state.messageValue,
- contact: this.state.contactValue,
- },
- });
-
- if (response.error) {
- macros.error('Unable to submit feedback', response.error, this.state.messageValue, this.state.contactValue);
- }
-
+ closeForm() {
this.setState({
- messageVisible: true,
- messageValue: '',
- contactValue: '',
- });
-
- // Hide the message after 2 seconds
- setTimeout(() => {
- this.setState({
- messageVisible: false,
- });
- }, 2000);
-
- this.props.closeForm();
- }
-
- onTextAreaChange(event) {
- this.setState({
- messageValue: event.target.value,
- });
- }
-
- onContactChange(event) {
- this.setState({
- contactValue: event.target.value,
- });
- }
-
- hideMessage() {
- this.setState({
- messageVisible: false,
- });
+ isOpen: false
+ })
}
render() {
@@ -110,22 +73,22 @@ class ReferModal extends React.Component {
return (
<div className='feedback-container'>
- <Modal open={ this.isOpen } onClose={ this.props.closeForm } size='small' className='feedback-modal-container'>
- <Header icon='mail' content='Search NEU Feedback' />
+ <Modal open={ this.state.isOpen } onClose={ this.closeForm } size='small' className='feedback-modal-container'>
+ <Header icon='mail' content='Refer your friends for priority notifications!' />
<Modal.Content className='formModalContent'>
<Form>
- <div className='feedbackParagraph'>Find a bug in Search NEU? Find a query that dosen&apos;t come up with the results you were looking for? Have an idea for an improvement or just want to say hi? Drop a line below! Feel free to write whatever you want to and someone on the team will read it.</div>
+ <div className='feedbackParagraph'>Share Search NEU with your friends and we'll make sure to send you the first notification when a seat opens up!</div>
<TextArea name='response' form='feedbackForm' className='feedbackTextbox' onChange={ this.onTextAreaChange } />
<p>By default this form is anonymous. Leave your name and/or email if you want us to be able to contact you.</p>
<Input name='contact' form='feedbackForm' className='formModalInput' onChange={ this.onContactChange } />
</Form>
</Modal.Content>
<Modal.Actions>
- <Button basic color='red' onClick={ this.props.closeForm }>
+ <Button basic color='red' onClick={ this.closeForm }>
<Icon name='remove' />
Cancel
</Button>
- <Button type='submit' color='green' form='feedbackForm' onClick={ this.onSubmit }>
+ <Button type='submit' color='green' form='feedbackForm' onClick={ this.closeForm }>
<Icon name='checkmark' />
Submit
</Button>
From 6e98e2eec8792283eed3b3c4d5460a43b623bdf4 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Mon, 28 May 2018 19:25:50 +0800
Subject: [PATCH 06/12] .
---
frontend/components/ReferModal.js | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 735e497d..9ad79211 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -77,8 +77,24 @@ class ReferModal extends React.Component {
<Header icon='mail' content='Refer your friends for priority notifications!' />
<Modal.Content className='formModalContent'>
<Form>
- <div className='feedbackParagraph'>Share Search NEU with your friends and we'll make sure to send you the first notification when a seat opens up!</div>
- <TextArea name='response' form='feedbackForm' className='feedbackTextbox' onChange={ this.onTextAreaChange } />
+ <div className='feedbackParagraph'>Refer a friend to Search NEU for priority notifications!</div>
+ Send on messenger, url share, facebook, other (twitter, email, etc)
+
+ url: https://searchneu.com/referred_from/idhere
+
+ this works pretty well when the user is on mobile and has messenger installed
+ <a href="fb-messenger://share/?link=https%3A%2F%searchneu.com%referred_from%2F" + id here + "&app_id=1979224428978082">Send In Messenger</a>
+
+ this works pretty well when people are on web
+ https://developers.facebook.com/docs/sharing/reference/send-dialog
+
+
+ email link
+ you should be able to prefill body and subject here
+
+
+
+
<p>By default this form is anonymous. Leave your name and/or email if you want us to be able to contact you.</p>
<Input name='contact' form='feedbackForm' className='formModalInput' onChange={ this.onContactChange } />
</Form>
From 9fdcc46ba3aedfb85f87cf6156702eddb16dde05 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Mon, 28 May 2018 20:41:04 +0800
Subject: [PATCH 07/12] .
---
frontend/components/ReferModal.js | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 9ad79211..4620e7cb 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -73,31 +73,31 @@ class ReferModal extends React.Component {
return (
<div className='feedback-container'>
- <Modal open={ this.state.isOpen } onClose={ this.closeForm } size='small' className='feedback-modal-container'>
+ <Modal open={ this.state.isOpen || true } onClose={ this.closeForm } size='small' className='feedback-modal-container'>
<Header icon='mail' content='Refer your friends for priority notifications!' />
<Modal.Content className='formModalContent'>
- <Form>
<div className='feedbackParagraph'>Refer a friend to Search NEU for priority notifications!</div>
Send on messenger, url share, facebook, other (twitter, email, etc)
url: https://searchneu.com/referred_from/idhere
this works pretty well when the user is on mobile and has messenger installed
- <a href="fb-messenger://share/?link=https%3A%2F%searchneu.com%referred_from%2F" + id here + "&app_id=1979224428978082">Send In Messenger</a>
+ <a target='_blank'
+ rel='noopener noreferrer'
+ href={"fb-messenger://share/?link=https%3A%2F%searchneu.com%referred_from%2F" + 'idhere' + "&app_id=1979224428978082"}>Send In Messenger</a>
this works pretty well when people are on web
+
+ <a target='_blank'
+ rel='noopener noreferrer'
+ href="mailto:?subject=Search NEU&body=Hey,%0D%0A Not sure if you've heard of it, but if you haven't check out %3Ca%20href%3D%22https%3A%2F%2Fsearchneu.com%22%3ESearch%20NEU%3C%2Fa%3E - it's a great site for class information at NEU. https://searchneu.com">Send via email</a>
https://developers.facebook.com/docs/sharing/reference/send-dialog
+ // insert the user's name at the bottom of this email.
+
email link
you should be able to prefill body and subject here
-
-
-
-
- <p>By default this form is anonymous. Leave your name and/or email if you want us to be able to contact you.</p>
- <Input name='contact' form='feedbackForm' className='formModalInput' onChange={ this.onContactChange } />
- </Form>
</Modal.Content>
<Modal.Actions>
<Button basic color='red' onClick={ this.closeForm }>
From 37154a7dcc948d4117156cee3119ab0029a8a332 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Tue, 29 May 2018 22:41:10 +0800
Subject: [PATCH 08/12] .
---
frontend/components/ReferModal.js | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 4620e7cb..f48934ad 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -64,6 +64,11 @@ class ReferModal extends React.Component {
})
}
+ // Android
+ onAndroidShareClick() {
+
+ }
+
render() {
const transitionStyles = {
entering: { opacity: 0 },
@@ -79,6 +84,15 @@ class ReferModal extends React.Component {
<div className='feedbackParagraph'>Refer a friend to Search NEU for priority notifications!</div>
Send on messenger, url share, facebook, other (twitter, email, etc)
+
+ on mobile the order should be;
+ - facebook messenger
+ - instagram direct
+ - sms (if there is room + it looks good)
+ - copy the url
+ - other (on android this can bring up the share dialog, on ios.... maybe add a bunch of more links tothe bottom?)
+
+
url: https://searchneu.com/referred_from/idhere
this works pretty well when the user is on mobile and has messenger installed
@@ -90,9 +104,14 @@ class ReferModal extends React.Component {
<a target='_blank'
rel='noopener noreferrer'
- href="mailto:?subject=Search NEU&body=Hey,%0D%0A Not sure if you've heard of it, but if you haven't check out %3Ca%20href%3D%22https%3A%2F%2Fsearchneu.com%22%3ESearch%20NEU%3C%2Fa%3E - it's a great site for class information at NEU. https://searchneu.com">Send via email</a>
+ href="mailto:?subject=Search NEU&body=Hey,%0D%0A%0D%0ANot sure if you've heard of it, but if you haven't check out %3Ca%20href%3D%22https%3A%2F%2Fsearchneu.com%22%3ESearch%20NEU%3C%2Fa%3E - it's a great site for class information at NEU. https://searchneu.com">Send via email</a>
https://developers.facebook.com/docs/sharing/reference/send-dialog
+ // for sharing on android mobile
+
+ https://developers.google.com/web/updates/2016/09/navigator-share
+
+
// insert the user's name at the bottom of this email.
From 7599954adb087a6d44e5b685c211eee78e27322b Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Mon, 4 Jun 2018 02:24:38 -0400
Subject: [PATCH 09/12] .
---
frontend/components/ReferModal.js | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index f48934ad..d8ffb7e3 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -69,6 +69,13 @@ class ReferModal extends React.Component {
}
+
+ // If navigator.share, return one button that just calls navigator.share.
+ // else, return a couple buttons - one for fb, fbmessenger,, email, link
+ getShareElements() {
+
+ }
+
render() {
const transitionStyles = {
entering: { opacity: 0 },
@@ -85,6 +92,9 @@ class ReferModal extends React.Component {
Send on messenger, url share, facebook, other (twitter, email, etc)
+ // clipboard https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
+
+
on mobile the order should be;
- facebook messenger
- instagram direct
From 07ae3348be9b2b4e5154b9dea247a77c41793735 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Thu, 7 Jun 2018 13:26:27 -0400
Subject: [PATCH 10/12] some more work
---
frontend/components/ReferModal.js | 17 +++++++++++++++++
frontend/components/share.svg | 6 ++++++
2 files changed, 23 insertions(+)
create mode 100644 frontend/components/share.svg
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index d8ffb7e3..63fa8e1a 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -11,6 +11,7 @@ import { Transition } from 'react-transition-group';
import authentication from './authentication';
import macros from './macros';
import request from './request';
+import share from './share.svg';
// This modal pops up after someone signs up for notifications
// It provides the user with some information that they can use to refer other people to the site (eg. a url, share on FB, etc)
@@ -33,6 +34,7 @@ class ReferModal extends React.Component {
// this.onSubmit = this.onSubmit.bind(this);
this.closeForm = this.closeForm.bind(this);
+ this.onAndroidShareClick = this.onAndroidShareClick.bind(this);
this.initialize();
}
@@ -83,12 +85,27 @@ class ReferModal extends React.Component {
exited: { display: 'none', opacity: 0 },
};
+ let element = null;
+
+ // Return the share thing
+ if (!window.navigator.share) {
+ element = <Button basic onClick={this.onAndroidShareClick}><img src={share}/>Share!</Button>
+ }
+
return (
<div className='feedback-container'>
<Modal open={ this.state.isOpen || true } onClose={ this.closeForm } size='small' className='feedback-modal-container'>
<Header icon='mail' content='Refer your friends for priority notifications!' />
<Modal.Content className='formModalContent'>
<div className='feedbackParagraph'>Refer a friend to Search NEU for priority notifications!</div>
+
+
+ <br/>
+ <br/>
+ {element}
+ <br/>
+ <br/>
+
Send on messenger, url share, facebook, other (twitter, email, etc)
diff --git a/frontend/components/share.svg b/frontend/components/share.svg
new file mode 100644
index 00000000..1a4ed149
--- /dev/null
+++ b/frontend/components/share.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 26 26" version="1.1" width="50px" height="50px">
+<g id="surface1">
+<path style=" " d="M 21 0 C 18.238281 0 16 2.238281 16 5 C 16 5.085938 16.027344 5.164063 16.03125 5.25 L 8.1875 9.1875 C 7.320313 8.457031 6.222656 8 5 8 C 2.238281 8 0 10.238281 0 13 C 0 15.761719 2.238281 18 5 18 C 6.222656 18 7.320313 17.542969 8.1875 16.8125 L 16.03125 20.75 C 16.027344 20.835938 16 20.914063 16 21 C 16 23.761719 18.238281 26 21 26 C 23.761719 26 26 23.761719 26 21 C 26 18.238281 23.761719 16 21 16 C 19.777344 16 18.679688 16.457031 17.8125 17.1875 L 9.96875 13.25 C 9.972656 13.164063 10 13.085938 10 13 C 10 12.914063 9.972656 12.835938 9.96875 12.75 L 17.8125 8.8125 C 18.679688 9.542969 19.777344 10 21 10 C 23.761719 10 26 7.761719 26 5 C 26 2.238281 23.761719 0 21 0 Z "/>
+</g>
+</svg>
From 1f84f4a5c5827c51c5a71e8b4191f7645cf61bac Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Thu, 7 Jun 2018 16:59:44 -0400
Subject: [PATCH 11/12] android mobile done.
---
frontend/components/ReferModal.js | 55 +++++++++++++++++++++++--------
frontend/css/_ReferModal.scss | 53 +++++++++++++++++++++++++++++
frontend/css/base.scss | 29 ++++++++--------
package.json | 2 +-
yarn.lock | 2 +-
5 files changed, 111 insertions(+), 30 deletions(-)
create mode 100644 frontend/css/_ReferModal.scss
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 63fa8e1a..36004c0c 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -42,7 +42,7 @@ class ReferModal extends React.Component {
componentDidMount() {
macros.log("componentDidMount rfere modal")
this.setState({
- isOpen: false
+ isOpen: true
})
}
@@ -68,6 +68,13 @@ class ReferModal extends React.Component {
// Android
onAndroidShareClick() {
+ // alert('hi')
+ window.navigator.share({
+ title: 'hi there',
+ text: 'Hello World',
+
+ url: 'https://google.com'
+ })
}
@@ -88,24 +95,48 @@ class ReferModal extends React.Component {
let element = null;
// Return the share thing
- if (!window.navigator.share) {
- element = <Button basic onClick={this.onAndroidShareClick}><img src={share}/>Share!</Button>
+ if (window.navigator.share || 1) {
+ element = <Button size='big' basic className="android-share-button" onClick={this.onAndroidShareClick}>
+ <img src={share} className="share-img"/>
+ {/*<Icon disabled name='share alternate' />*/}
+ <span className="text">Share!</span>
+ </Button>
+
+
+ // {/*<Button basic onClick={this.onAndroidShareClick}><img src={share}/>Share!</Button>*/}
}
return (
- <div className='feedback-container'>
- <Modal open={ this.state.isOpen || true } onClose={ this.closeForm } size='small' className='feedback-modal-container'>
+ <div className='referModal-container'>
+ <Modal open={ this.state.isOpen } onClose={ this.closeForm } size='small' className='refer-modal-container'>
<Header icon='mail' content='Refer your friends for priority notifications!' />
<Modal.Content className='formModalContent'>
- <div className='feedbackParagraph'>Refer a friend to Search NEU for priority notifications!</div>
+ <div className='feedbackParagraph'>Share Search NEU with your friends and get priority notifications!</div>
- <br/>
<br/>
{element}
<br/>
+
+
+ <div className="copy-text">
+ <span>Or copy your share link:&nbsp;&nbsp;</span>
+ <Button basic><Icon disabled name='copy'/>copy</Button>
+ </div>
<br/>
+ {/*When a popular class fills up, many students subscribe for notifications for the same */}
+
+ When a popular class fills up, many students usually subscribe for notifications on the same class. Share Search NEU with your friends to get notified first! We'll send you the notification 1 hour earlier for every friend you refer to the site.
+
+
+ {/*Sometimes, many students are subscribed to the same class. */}
+{/*
+ For every friend you refer, we'll send the no
+
+ Some languge down here that explains what is going on omg how awesme is this feature.*/}
+
+{/*
Send on messenger, url share, facebook, other (twitter, email, etc)
@@ -143,16 +174,12 @@ class ReferModal extends React.Component {
email link
- you should be able to prefill body and subject here
+ you should be able to prefill body and subject here*/}
</Modal.Content>
<Modal.Actions>
- <Button basic color='red' onClick={ this.closeForm }>
- <Icon name='remove' />
- Cancel
- </Button>
- <Button type='submit' color='green' form='feedbackForm' onClick={ this.closeForm }>
+ <Button basic onClick={ this.closeForm }>
<Icon name='checkmark' />
- Submit
+ Done
</Button>
</Modal.Actions>
</Modal>
diff --git a/frontend/css/_ReferModal.scss b/frontend/css/_ReferModal.scss
new file mode 100644
index 00000000..13d6755a
--- /dev/null
+++ b/frontend/css/_ReferModal.scss
@@ -0,0 +1,53 @@
+/*
+ * This file is part of Search NEU and licensed under AGPL3.
+ * See the license file in the root folder for details.
+ */
+
+.refer-modal-container {
+
+
+ // This css fixes the position of the feedback modal. It broke when we updated the version of a package.
+ // It might be fixed (and make this code obsolete) in a future package.
+ top: 50%;
+ position: fixed;
+ left: 50%;
+ transform: translate(-50%, 0px);
+
+
+
+ .share-img {
+ height: 23px;
+ color: #bbb;
+ -webkit-text-stroke: #bbb;
+ opacity: .4;
+ padding-right: 10px;
+ padding-top: 0px;
+ margin-left: -5px;
+ }
+
+ .android-share-button{
+ display: block;
+ margin: 0 auto;
+ }
+
+
+ .copy-text {
+ text-align: center;
+ display: block;
+ margin: 0 auto;
+ }
+
+ .copy-button {
+
+ }
+
+
+ .text {
+ display: inline-block;
+ /* padding-bottom: 5px; */
+ vertical-align: top;
+ }
+
+}
+
+
diff --git a/frontend/css/base.scss b/frontend/css/base.scss
index 4edd016e..6bc73264 100644
--- a/frontend/css/base.scss
+++ b/frontend/css/base.scss
@@ -6,22 +6,23 @@
* that imports all partials.
*/
- @import 'variables';
+@import 'variables';
- @import 'panels/BaseClassPanel';
- @import 'panels/DesktopClassPanel';
- @import 'panels/DesktopSectionPanel';
- @import 'panels/EmployeePanel';
- @import 'panels/MobileClassPanel';
- @import 'panels/MobileSectionPanel';
- @import 'panels/SplashPage';
- @import 'panels/WeekdayBoxes';
- @import 'FeedbackModal';
- @import 'SignUpForNotifications';
- @import 'ResultsLoader';
- @import 'Home';
+@import 'panels/BaseClassPanel';
+@import 'panels/DesktopClassPanel';
+@import 'panels/DesktopSectionPanel';
+@import 'panels/EmployeePanel';
+@import 'panels/MobileClassPanel';
+@import 'panels/MobileSectionPanel';
+@import 'panels/SplashPage';
+@import 'panels/WeekdayBoxes';
+@import 'FeedbackModal';
+@import 'ReferModal';
+@import 'SignUpForNotifications';
+@import 'ResultsLoader';
+@import 'Home';
- html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote, pre, form, fieldset, table, th, td {
+html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote, pre, form, fieldset, table, th, td {
margin: 0;
padding: 0;
}
diff --git a/package.json b/package.json
index a2feaa72..3aecced5 100644
--- a/package.json
+++ b/package.json
@@ -123,7 +123,7 @@
"eslint-plugin-react": "^7.0.1",
"extract-text-webpack-plugin": "^3.0.2",
"ignore-styles": "^5.0.1",
- "node-sass": "^4.7.2",
+ "node-sass": "^4.9.0",
"sass-loader": "^7.0.1",
"style-loader": "^0.21.0"
},
diff --git a/yarn.lock b/yarn.lock
index ccc8227f..d6b193a2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6740,7 +6740,7 @@ node-pre-gyp@^0.10.0:
semver "^5.3.0"
tar "^4"
-node-sass@^4.7.2:
+node-sass@^4.9.0:
version "4.9.0"
resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.9.0.tgz#d1b8aa855d98ed684d6848db929a20771cc2ae52"
dependencies:
From 2894a5898e70dbe812fd87ca4f88ee9849c2cbd9 Mon Sep 17 00:00:00 2001
From: Ryan Hughes <[email protected]>
Date: Thu, 7 Jun 2018 17:33:53 -0400
Subject: [PATCH 12/12] ..
---
backend/server.js | 29 +++++++++++++
frontend/components/ReferModal.js | 13 ++----
frontend/components/authentication.js | 62 +++++++++++++++++++++++++--
3 files changed, 90 insertions(+), 14 deletions(-)
diff --git a/backend/server.js b/backend/server.js
index 2c7d3e05..0ec1dc1b 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -589,6 +589,35 @@ app.post('/webhook/', wrap(async (req, res) => {
let rateLimit = {};
let lastHour = 0;
+app.post('/getUser', wrap(async (req, res) => {
+ // Don't cache this endpoint.
+ res.setHeader('Cache-Control', 'no-cache, no-store');
+
+ if (!req.body.loginKey && !req.body.facebookMessengerId) {
+ macros.log('need loginKey or facebookMessengerId');
+ res.send(JSON.stringify({
+ error: 'need loginKey or facebookMessengerId.',
+ }));
+ return;
+ }
+
+ let facebookMessengerId = req.body.facebookMessengerId;
+
+ if (facebookMessengerId && (facebookMessengerId.length !== 16 || !/^\d+$/.test(facebookMessengerId))) {
+ macros.log('invalid facebookMessengerId');
+ res.send(JSON.stringify({
+ error: 'invalid 2.',
+ }));
+ return;
+ }
+
+
+
+
+
+
+}))
+
app.post('/submitFeedback', wrap(async (req, res) => {
// Don't cache this endpoint.
res.setHeader('Cache-Control', 'no-cache, no-store');
diff --git a/frontend/components/ReferModal.js b/frontend/components/ReferModal.js
index 36004c0c..ee374fa0 100644
--- a/frontend/components/ReferModal.js
+++ b/frontend/components/ReferModal.js
@@ -28,11 +28,6 @@ class ReferModal extends React.Component {
isOpen: false,
};
- // this.onTextAreaChange = this.onTextAreaChange.bind(this);
- // this.onContactChange = this.onContactChange.bind(this);
- // this.hideMessage = this.hideMessage.bind(this);
- // this.onSubmit = this.onSubmit.bind(this);
-
this.closeForm = this.closeForm.bind(this);
this.onAndroidShareClick = this.onAndroidShareClick.bind(this);
@@ -68,12 +63,10 @@ class ReferModal extends React.Component {
// Android
onAndroidShareClick() {
- // alert('hi')
window.navigator.share({
- title: 'hi there',
- text: 'Hello World',
-
- url: 'https://google.com'
+ title: 'Yo dude, check out Search NEU',
+ text: 'its lit yo',
+ url: 'https://searchneu.com/referred_from/'
})
}
diff --git a/frontend/components/authentication.js b/frontend/components/authentication.js
index 5e6df964..be34ae99 100644
--- a/frontend/components/authentication.js
+++ b/frontend/components/authentication.js
@@ -33,14 +33,50 @@ class Authentication {
this.facebookApiPromiseResolver = resolve;
})
- this.downloadUserData();
+ // this.downloadUserData();
+ this.getIsLoggedIn();
}
// Downloads the user data from the server.
// Send the loginKey and the facebookMessengerId (if we have it).
// Save the facebookMessengerId when the server responds (the server can respond to this request a lot faster when given the facebookMessengerId).
- downloadUserData() {
+ async downloadUserData() {
+
+ let user = await request.post({
+ url:'/getUser',
+ body: {
+ loginKey: this.getLoginKey(),
+ }
+ })
+
+
+ if (!user) {
+ macros.error("No user with this login key existed?")
+ return;
+ }
+
+
+ return user;
+
+
+ }
+
+ async getUserFacebookMessengerId() {
+
+ if (window.localStorage.facebookMessengerId) {
+ return window.localStorage.facebookMessengerId;
+ }
+
+ let user = await this.downloadUserData();
+
+ if (!user) {
+ return null;
+ }
+
+ window.localStorage.facebookMessengerId = user.facebookMessengerId;
+
+ return user.facebookMessengerId;
}
// This returns the window.FB after it has finished loading.
@@ -85,14 +121,32 @@ class Authentication {
return true;
}
- return new Promise((resolve) => {
- window.FB.getLoginStatus((response) => {
+ return new Promise(async (resolve) => {
+
+ let FB = await this.getFacebookAPI();
+
+ FB.getLoginStatus((response) => {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
+
+
+ let loginId = response.authResponse.userID;
+
+ // User logged out of Facebook and then logged into Facebook a different account which caused the userID to change.
+ // Clear out the local loginKey because that loginKey references the old account.
+ // If this is not done, any actions that use the loginKey to pull user data will pull from the old account instead of the one they are currently logged into.
+ if (window.localStorage.facebookLoginId && loginId !== window.localStorage.facebookLoginId) {
+ window.localStorage.clear();
+ macros.warn("Deleted an old login key and cleared localStorage because the user switched Facebook accounts.");
+ }
+
+ window.localStorage.facebookLoginId = loginId;
+
+
resolve(true);
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment