Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Commit 9490025

Browse files
committed
Fixed edge case where contacts weren't loaded
1 parent d277423 commit 9490025

File tree

3 files changed

+32
-36
lines changed

3 files changed

+32
-36
lines changed

src/react/Actions/contacts.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import fs from "../ImportWrappers/fs";
88

99
export const STORED_CONTACTS = "BUNQDESKTOP_STORED_CONTACTS";
1010

11-
export function contactsSetInfoType(contacts, type, BunqJSClient = false) {
11+
export function contactsSetInfoType(contacts, type) {
1212
return {
1313
type: "CONTACTS_SET_INFO_TYPE",
1414
payload: {
15-
BunqJSClient,
1615
type: type,
1716
contacts: contacts
1817
}
@@ -122,7 +121,7 @@ export function contactInfoUpdateGoogle(BunqJSClient, accessToken) {
122121
}
123122

124123
// set the contacts
125-
dispatch(contactsSetInfoType(collectedEntries, "GoogleContacts", BunqJSClient));
124+
dispatch(contactsSetInfoType(collectedEntries, "GoogleContacts"));
126125
dispatch(contactsNotLoading());
127126
})
128127
.catch(error => {
@@ -202,7 +201,7 @@ export function contactInfoUpdateOffice365(BunqJSClient, accessToken) {
202201
}
203202

204203
// set the contacts
205-
dispatch(contactsSetInfoType(collectedEntries, "Office365", BunqJSClient));
204+
dispatch(contactsSetInfoType(collectedEntries, "Office365"));
206205
dispatch(contactsNotLoading());
207206
})
208207
.catch(error => {
@@ -284,7 +283,7 @@ export function contactInfoUpdateApple(BunqJSClient, files) {
284283
});
285284

286285
// set the contacts
287-
dispatch(contactsSetInfoType(collectedEntries, "AppleContacts", BunqJSClient));
286+
dispatch(contactsSetInfoType(collectedEntries, "AppleContacts"));
288287
dispatch(contactsNotLoading());
289288
};
290289
}

src/react/Pages/Contacts/Contacts.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ const mapDispatchToProps = (dispatch, props) => {
203203
contactInfoUpdateGoogle: accessToken => dispatch(contactInfoUpdateGoogle(BunqJSClient, accessToken)),
204204
contactInfoUpdateApple: filePaths => dispatch(contactInfoUpdateApple(BunqJSClient, filePaths)),
205205
contactInfoUpdateOffice365: accessToken => dispatch(contactInfoUpdateOffice365(BunqJSClient, accessToken)),
206-
contactsSetInfoType: (contacts, type) => dispatch(contactsSetInfoType(contacts, type, BunqJSClient)),
206+
contactsSetInfoType: (contacts, type) => dispatch(contactsSetInfoType(contacts, type)),
207207
clearContacts: (type = false) => dispatch(contactsClear(BunqJSClient, type)),
208208
openSnackbar: message => dispatch(openSnackbar(message))
209209
};

src/react/Reducers/contacts.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ const uniqueArray = a => {
1212

1313
export default function reducer(state = defaultState, action) {
1414
switch (action.type) {
15-
case "CONTACTS_SET_INFO_TYPE":
15+
case "CONTACTS_SET_INFO_TYPE": {
16+
const currentContactState = { ...state.contacts };
1617
const contacts = action.payload.contacts;
17-
const stateContacts = state.contacts[action.payload.type];
18-
const currentContacts = stateContacts ? [...stateContacts] : [];
18+
const contactType = action.payload.type;
19+
20+
const currentContacts = currentContactState[contactType] ? currentContactState[contactType] : [];
1921

2022
// go through all contacts and combine theme
2123
contacts.map(newContact => {
@@ -50,42 +52,37 @@ export default function reducer(state = defaultState, action) {
5052
});
5153

5254
// set the new combined contacts for this type
53-
stateContacts[action.payload.type] = sortedCombinedContacts;
54-
55-
// store the data if we have access to the bunqjsclient
56-
if (action.payload.BunqJSClient) {
57-
const BunqDesktopClient = window.BunqDesktopClient;
58-
BunqDesktopClient.storeEncrypt(
59-
{
60-
items: stateContacts
61-
},
62-
STORED_CONTACTS
63-
)
64-
.then(() => {})
65-
.catch(() => {});
66-
}
55+
currentContactState[action.payload.type] = sortedCombinedContacts;
56+
57+
const BunqDesktopClient = window.BunqDesktopClient;
58+
BunqDesktopClient.storeEncrypt(
59+
{
60+
items: currentContactState
61+
},
62+
STORED_CONTACTS
63+
)
64+
.then(() => {})
65+
.catch(() => {});
6766

6867
return {
6968
...state,
7069
last_update: new Date().getTime(),
71-
contacts: stateContacts
70+
contacts: currentContactState
7271
};
72+
}
7373

7474
case "CONTACTS_SET_INFO": {
7575
const contacts2 = action.payload.contacts;
7676

77-
// store the data if we have access to the bunqjsclient
78-
if (action.payload.BunqJSClient) {
79-
const BunqDesktopClient = window.BunqDesktopClient;
80-
BunqDesktopClient.storeEncrypt(
81-
{
82-
items: contacts2
83-
},
84-
STORED_CONTACTS
85-
)
86-
.then(() => {})
87-
.catch(() => {});
88-
}
77+
const BunqDesktopClient = window.BunqDesktopClient;
78+
BunqDesktopClient.storeEncrypt(
79+
{
80+
items: contacts2
81+
},
82+
STORED_CONTACTS
83+
)
84+
.then(() => {})
85+
.catch(() => {});
8986

9087
return {
9188
...state,

0 commit comments

Comments
 (0)