Skip to content
This repository was archived by the owner on Jul 15, 2018. It is now read-only.

Commit 6eb771d

Browse files
author
Paul Xu
authored
Merge pull request #33 from jdunk/add-unmatch-button
Adds an "Unmatch" button (and fixes many eslint errors)
2 parents 9c76f5b + 57f7034 commit 6eb771d

File tree

9 files changed

+130
-38
lines changed

9 files changed

+130
-38
lines changed

app/components/Button/styles.css

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
color: white;
55
font-size: 10px;
66
margin:5px;
7-
}
7+
}
88

99
.locationToggle {
1010
composes: button;
@@ -32,6 +32,7 @@
3232

3333
.buttonMatch {
3434
composes: button;
35+
cursor: pointer;
3536
height: 50px;
3637
width: 50px;
3738
font-weight: 600;
@@ -60,7 +61,6 @@
6061
border-color: #5cc3e8;
6162
}
6263

63-
6464
.superlike:hover{
6565
color: white;
6666
background-color: #5cc3e8;
@@ -79,7 +79,8 @@
7979
transition: 0.25s;
8080
}
8181

82-
.fetchMatches {
82+
.fetchMatches, .unmatch {
83+
cursor: pointer;
8384
font-size: 12px;
8485
max-height: 30px;
8586
padding: 5px 15px;
@@ -97,7 +98,7 @@
9798
color: #e95f5c;
9899
}
99100

100-
.fetchMatches:hover {
101+
.fetchMatches:hover, .unmatch:hover {
101102
background-color: transparent;
102103
color: #e95f5c;
103104
transition: 0.25s;
@@ -109,8 +110,6 @@
109110
transition: 0.25s;
110111
}
111112

112-
113-
114113
.accountSettings {
115114
flex: 1;
116115
background: white;

app/components/DetailView/index.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import Icon from 'components/Icon';
99
import Text from 'components/Text';
1010
import Button from 'components/Button';
1111

12-
const buttonMapping = [
13-
'pass', 'superlike', 'like',
14-
];
15-
1612
class DetailView extends React.Component {
1713
componentWillReceiveProps(nextProps) {
1814
if (nextProps.imageData.length === 0) {
@@ -41,15 +37,6 @@ class DetailView extends React.Component {
4137
}
4238
}
4339

44-
45-
renderButtons({ _id, content_hash, name }, onClickButton) {
46-
return (
47-
<div className={styles.detailViewContainerButtons}>
48-
{buttonMapping.map((each) => <Button key={each} type={each} details={{ name }} onClick={onClickButton} id={_id} hash={content_hash}></Button>)}
49-
</div>
50-
);
51-
}
52-
5340
render() {
5441
const age = getAge(this.props.data.birth_date);
5542
const jobs = this.props.data.jobs && this.props.data.jobs[0];
@@ -85,6 +72,7 @@ class DetailView extends React.Component {
8572
<Text type="school">{schools && schools.name}</Text>
8673
<Text type="jobs">{(jobs && jobs.title) && jobs.title.name}{(jobs && jobs.title) && jobs.company ? ' at ' : null}{jobs && jobs.company && <a href={jobs.company.id} target="_blank">{jobs.company.name}</a>}</Text>
8774
<Text type="bio">{this.props.data.bio}</Text>
75+
{this.props.unmatch ? <Button type="unmatch" onClick={() => this.props.unmatch(this.props.matchId)}>Unmatch</Button> : null}
8876

8977
{this.props.data.common_connections && this.props.data.common_connections.length > 0 ?
9078
<div>
@@ -136,7 +124,8 @@ DetailView.propTypes = {
136124
isFetching: PropTypes.bool,
137125
isPotentialLike: PropTypes.bool,
138126
recommendationView: PropTypes.bool,
127+
unmatch: PropTypes.func,
128+
matchId: PropTypes.string,
139129
};
140130

141-
142131
export default DetailView;

app/containers/Messages/actions.js

+25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
SEND_MESSAGE,
1010
SEND_MESSAGE_SUCCESS,
1111
SEND_MESSAGE_ERROR,
12+
UNMATCH,
13+
UNMATCH_SUCCESS,
14+
UNMATCH_ERROR,
1215
ALL_DATA_FETCHED,
1316
UPDATE_POINTER,
1417
FETCH_MATCHES_DATA,
@@ -107,6 +110,28 @@ export function sendMessageError(error) {
107110
};
108111
}
109112

113+
export function unmatch(id) {
114+
return {
115+
type: UNMATCH,
116+
payload: {
117+
id,
118+
},
119+
};
120+
}
121+
122+
export function unmatchSuccess() {
123+
return {
124+
type: UNMATCH_SUCCESS,
125+
};
126+
}
127+
128+
export function unmatchError(error) {
129+
return {
130+
type: UNMATCH_ERROR,
131+
payload: error,
132+
};
133+
}
134+
110135
export function updatePointer() {
111136
return {
112137
type: UPDATE_POINTER,

app/containers/Messages/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export const SELECT_PERSON = 'SELECT_PERSON';
88
export const SEND_MESSAGE = 'SEND_MESSAGE';
99
export const SEND_MESSAGE_SUCCESS = 'SEND_MESSAGE_SUCCESS';
1010
export const SEND_MESSAGE_ERROR = 'SEND_MESSAGE_ERROR';
11+
export const UNMATCH = 'UNMATCH';
12+
export const UNMATCH_SUCCESS = 'UNMATCH_SUCCESS';
13+
export const UNMATCH_ERROR = 'UNMATCH_ERROR';
1114
export const UPDATE_POINTER = 'UPDATE_POINTER';
1215
export const ALL_DATA_FETCHED = 'ALL_DATA_FETCHED';
1316
export const FETCH_MATCHES_DATA = 'FETCH_MATCHES_DATA';

app/containers/Messages/index.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { createStructuredSelector } from 'reselect';
2929
import {
3030
selectPersonAction,
3131
sendMessage,
32+
unmatch,
3233
fetchMatchData,
3334
fetchMatchDataLocally,
3435
dumpAllInit,
@@ -63,35 +64,39 @@ export class Messages extends React.Component { // eslint-disable-line react/pre
6364
}
6465

6566
mapMatches() {
66-
return this.props.selectMatches && this.props.selectMatches.map((each) => {
67-
return (<MessengerCard
67+
return this.props.selectMatches && this.props.selectMatches.map((each) =>
68+
<MessengerCard
6869
onClick={this.props.selectPerson}
6970
key={each._id}
7071
data={each}
7172
isReply={each.messages.length !== 0 && each.messages.slice(-1)[0].from === this.props.currentUserId}
7273
isNew={each.person && each.person._id && this.props.newMatches.indexOf(each.person._id) !== -1}
73-
/>);
74-
});
74+
/>
75+
);
7576
}
7677

7778
mapMessages() {
78-
return this.props.matchMessages.map((each) => {
79-
return (<MessageBubble
79+
return this.props.matchMessages.map((each) =>
80+
<MessageBubble
8081
key={each.payload._id}
8182
from={each.from}
8283
date={each.payload.sent_date}
8384
>
8485
{each.payload.message}
85-
</MessageBubble>);
86-
})
86+
</MessageBubble>
87+
)
8788
.concat(this.props.selectOptimistic.map((each) => {
88-
if (each.id === this.props.currentPerson.id) {
89-
return (<MessageBubble
90-
key={each.message}
91-
from="you">
89+
if (each.id !== this.props.currentPerson.id) {
90+
return null;
91+
}
92+
93+
return (
94+
<MessageBubble
95+
key={each.message}
96+
from="you"
97+
>
9298
{each.message}
9399
</MessageBubble>);
94-
}
95100
}));
96101
}
97102

@@ -102,7 +107,8 @@ export class Messages extends React.Component { // eslint-disable-line react/pre
102107
if (this.props.selectMatches) {
103108
return <FormattedMessage {...messages.whenLoadedData} />;
104109
}
105-
return <FormattedMessage {...messages.whenNoDataisFound} />;
110+
111+
return <FormattedMessage {...messages.whenNoDataisFound} />;
106112
}
107113

108114
render() {
@@ -154,6 +160,8 @@ export class Messages extends React.Component { // eslint-disable-line react/pre
154160
<DetailView
155161
data={this.props.currentPerson.person}
156162
imageData={this.props.matchDetailImages}
163+
unmatch={this.props.onUnmatch}
164+
matchId={this.props.currentPerson && this.props.currentPerson._id}
157165
/> :
158166
<Panel hasMatches targetGender={this.props.targetGender} />}
159167
</div>
@@ -169,6 +177,7 @@ function mapDispatchToProps(dispatch) {
169177
return {
170178
selectPerson: (id) => dispatch(selectPersonAction(id)),
171179
onSendMessage: (id, message) => dispatch(sendMessage(id, message)),
180+
onUnmatch: (id) => dispatch(unmatch(id)),
172181
fetchHistory: () => dispatch(fetchMatchData()),
173182
fetchHistoryLocally: () => dispatch(fetchMatchDataLocally()),
174183
dumpAll: () => dispatch(dumpAllInit()),
@@ -199,6 +208,7 @@ Messages.propTypes = {
199208
matchMessages: PropTypes.array,
200209
matchDetailImages: PropTypes.array,
201210
onSendMessage: PropTypes.func,
211+
onUnmatch: PropTypes.func,
202212
fetchHistory: PropTypes.func,
203213
selectOptimisticUI: PropTypes.func,
204214
selectOptimistic: PropTypes.array,

app/containers/Messages/reducer.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
SEND_MESSAGE,
1111
SEND_MESSAGE_ERROR,
1212
SEND_MESSAGE_SUCCESS,
13+
UNMATCH,
1314
UPDATE_POINTER,
1415
ALL_DATA_FETCHED,
1516
FETCH_MATCHES_DATA,
@@ -60,10 +61,15 @@ function messagesReducer(state = initialState, action) {
6061
return state
6162
.set('isSending', true)
6263
.set('optimisticUI', action.payload.message.match(/gif/) ? state.get('optimisticUI') : state.get('optimisticUI').concat(action.payload));
63-
case SEND_MESSAGE_ERROR:
64-
return state.set('isSending', false);
6564
case SEND_MESSAGE_SUCCESS:
6665
return state.set('isSending', false);
66+
case SEND_MESSAGE_ERROR:
67+
return state.set('isSending', false);
68+
case UNMATCH:
69+
return state
70+
.set('isFetching', true)
71+
.set('optimisticUI', [])
72+
.set('currentPerson', null);
6773
case UPDATE_POINTER:
6874
return state.set('pointer', state.get('pointer') + 1);
6975
case ALL_DATA_FETCHED:
@@ -75,7 +81,7 @@ function messagesReducer(state = initialState, action) {
7581
case LOCATION_CHANGE:
7682
return state
7783
.set('optimisticUI', [])
78-
.set('currentPerson', '');
84+
.set('currentPerson', null);
7985
case RELOAD_DATA_PLEASE:
8086
return state
8187
.set('optimisticUI', []);

app/containers/Messages/sagas.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { selectAuthToken } from 'containers/Auth/selectors';
99

1010
import {
1111
SEND_MESSAGE,
12+
UNMATCH,
1213
FETCH_MATCHES_LOCALLY,
1314
DUMP_ALL_SUCCESS,
1415
DUMP_ALL_INIT,
@@ -19,6 +20,8 @@ import { selectPointer, selectMatches } from './selectors';
1920
import {
2021
sendMessageSuccess,
2122
sendMessageError,
23+
unmatchSuccess,
24+
unmatchError,
2225
updatePointer,
2326
allDataFetched,
2427
fetchMatchData,
@@ -109,6 +112,40 @@ export function* loadLocalData(additionalFunction = false) {
109112
}
110113

111114
// Individual exports for testing
115+
export function* doUnmatch(payload) {
116+
const userToken = yield select(selectAuthToken());
117+
const { id } = payload;
118+
const postURL = `${AUTH_URL}/tinder/unmatch/${id}`;
119+
try {
120+
const result = yield call(postRequest, postURL, { userToken });
121+
if (result.status === 200) {
122+
yield put(unmatchSuccess());
123+
124+
const unmatchedId = result.data.id;
125+
126+
const userID = yield select(selectUserID());
127+
const matchesList = yield getToken(`matchesList_${userID}`);
128+
129+
yield storeToken(`matchesList_${userID}`, matchesList.filter((each) => each !== unmatchedId));
130+
131+
yield call(loadLocalData, reloadDataPlease);
132+
}
133+
} catch (error) {
134+
yield put(unmatchError(error));
135+
yield put(newNotification(error));
136+
yield put(newNotificationAdded());
137+
}
138+
}
139+
140+
function* unmatchWatcher() {
141+
const unmatchWatch = yield actionChannel(UNMATCH);
142+
143+
while (true) {
144+
const { payload } = yield take(unmatchWatch);
145+
yield doUnmatch(payload);
146+
}
147+
}
148+
112149
export function* sendMessageData(payload) {
113150
const userToken = yield select(selectAuthToken());
114151
const { id } = payload;
@@ -144,7 +181,6 @@ export function* sendMessageData(payload) {
144181
}
145182
}
146183

147-
148184
function* sendMessageWatcher() {
149185
const messageWatch = yield actionChannel(SEND_MESSAGE);
150186

@@ -175,13 +211,15 @@ export function* reloadWatcher() {
175211

176212
export function* messageSaga() {
177213
const messageWatcher = yield fork(sendMessageWatcher);
214+
const unmatchWatch = yield fork(unmatchWatcher);
178215
const reloadWatch = yield fork(reloadWatcher);
179216
const dataDumpWatch = yield fork(dumpDataWatcher);
180217
const dataLoadLocalWatch = yield fork(dataLoadLocalWatcher);
181218

182219
yield take(LOCATION_CHANGE);
183220
yield cancel(reloadWatch);
184221
yield cancel(messageWatcher);
222+
yield cancel(unmatchWatch);
185223
yield cancel(dataLoadLocalWatch);
186224
yield take(DUMP_ALL_SUCCESS);
187225
yield cancel(dataDumpWatch);

server/api/api.js

+9
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ router.post('/tinder/message/:id', (req, res) => {
178178
.catch((error) => res.status(400).json(error));
179179
});
180180

181+
router.post('/tinder/unmatch/:id', (req, res) => {
182+
const client = new tinder.TinderClient();
183+
const { userToken } = req.body;
184+
const id = req.params.id;
185+
client.setAuthToken(userToken);
186+
tinderPromise.unmatch(client, id)
187+
.then(() => res.status(200).json({ id }))
188+
.catch((error) => res.status(400).json(error));
189+
});
181190

182191
router.post('/tinder/update/profile', (req, res) => {
183192
const client = new tinder.TinderClient();

0 commit comments

Comments
 (0)