Skip to content

Commit

Permalink
Merge pull request #345 from SquareTable/344-change-screens-to-use-ne…
Browse files Browse the repository at this point in the history
…w-data-from-changed-apis

Changed screens to use changed data from new APIs
  • Loading branch information
Sebastian-Webster authored Jan 14, 2024
2 parents 6764239 + e9d219d commit cfaba4d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
6 changes: 3 additions & 3 deletions screens/AccountFollowRequestsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ const AccountFollowRequestsScreen = ({navigation, route}) => {

axios.get(url).then(async response => {
const result = response.data;
const {skip, requesters, noMoreItems} = result.data;
const {skip, items, noMoreItems} = result.data;

Promise.allSettled(
requesters.map(requester => {
items.map(requester => {
if (requester.profileImageKey && requester.profileImageKey !== "") {
return axios.get(serverUrl + '/getImageOnServer/' + requester.profileImageKey)
}

return Promise.resolve('SocialSquare');
})
).then(pfps => {
const users = requesters.map((requester, index) => {
const users = items.map((requester, index) => {
console.warn(pfps[index].value.data)
return {
...requester,
Expand Down
12 changes: 6 additions & 6 deletions screens/ActivityScreens/PostUpvoteDownvoteActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ const PostUpvoteDownvoteActivity = ({navigation, route}) => {

axios.post(url, toSend, {signal: abortController.current.signal}).then(result => {
const response = result.data;
const {data, message} = response;
const {posts, lastVoteId, noMoreVotes} = data;
const {data} = response;
const {items, lastVoteId, noMoreItems} = data;

if (posts.length === 0) {
if (items.length === 0) {
dispatch({type: 'noMorePosts'})
}

lastVoteIdRef.current = lastVoteId

const processedPosts = []

posts.forEach((item, index, dataArray) => {
items.forEach((item, index, dataArray) => {
async function loadImages() {
const post = dataArray[index];

Expand All @@ -84,9 +84,9 @@ const PostUpvoteDownvoteActivity = ({navigation, route}) => {
}


if (processedPosts.length === posts.length) {
if (processedPosts.length === items.length) {
dispatch({type: 'addPosts', posts: processedPosts})
if (noMoreVotes) {
if (noMoreItems) {
dispatch({type: 'noMorePosts'})
}
}
Expand Down
4 changes: 2 additions & 2 deletions screens/FindScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ const FindScreen = ({navigation}) => {
const result = response.data;
const {data} = result;

const {categories, noMoreCategories} = data;
const {items, noMoreItems} = data;

console.log(data)
layoutCategoriesFound(categories, noMoreCategories)
layoutCategoriesFound(items, noMoreItems)
console.log('Category search was a success')

}).catch(error => {
Expand Down
16 changes: 8 additions & 8 deletions screens/ProfilePages.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ const ProfilePages = ({ route, navigation }) => {
}

const layoutImagePosts = (data) => {
var imageData = data.data.posts
var imageData = data.data.items
console.log("The Image data")
console.log(imageData)
console.log(imageData.length)
Expand Down Expand Up @@ -614,7 +614,7 @@ const ProfilePages = ({ route, navigation }) => {
posts: posts
})

if (data.data.noMorePosts) {
if (data.data.noMoreItems) {
dispatchImages({type: 'noMorePosts'})
}
}).catch(error => {
Expand Down Expand Up @@ -670,7 +670,7 @@ const ProfilePages = ({ route, navigation }) => {
}

const layoutPollPosts = (data) => {
const {posts: pollData, noMorePosts} = data;
const {items: pollData, noMoreItems} = data;

console.log('Poll Data:', pollData)
console.log('Number of polls received:', pollData.length)
Expand Down Expand Up @@ -776,7 +776,7 @@ const ProfilePages = ({ route, navigation }) => {
}
getPfpImageForPollWithAsync()
});
if (noMorePosts) {
if (noMoreItems) {
dispatchPolls({type: 'noMorePosts'})
}
}
Expand Down Expand Up @@ -819,7 +819,7 @@ const ProfilePages = ({ route, navigation }) => {
}

const layoutThreadPosts = (data) => {
var threadData = data.data.posts
var threadData = data.data.items
console.log("The Thread data")
console.log(threadData)
console.log(threadData.length)
Expand Down Expand Up @@ -893,7 +893,7 @@ const ProfilePages = ({ route, navigation }) => {
})
).then(posts => {
dispatchThreads({type: 'addPosts', posts})
if (data.data.noMorePosts) {
if (data.data.noMoreItems) {
dispatchThreads({type: 'noMorePosts'})
}
}).catch(error => {
Expand Down Expand Up @@ -940,7 +940,7 @@ const ProfilePages = ({ route, navigation }) => {

const layoutCategoriesFound = (data) => {
console.log('DATA:', data)
var allData = data.categories
var allData = data.items

Promise.all(
allData.map(category => {
Expand Down Expand Up @@ -983,7 +983,7 @@ const ProfilePages = ({ route, navigation }) => {
})
})
).then(categories => {
dispatchCategories({type: 'addCategories', categories, noMoreCategories: data.noMoreCategories})
dispatchCategories({type: 'addCategories', categories, noMoreCategories: data.noMoreItems})
}).catch(error => {
dispatchCategories({type: 'error', error: String(error)})
})
Expand Down
16 changes: 8 additions & 8 deletions screens/ProfileScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ const Welcome = ({navigation, route}) => {
}

const layoutImagePosts = (data) => {
var imageData = data.data.posts
var imageData = data.data.items
console.log("The Image data")
console.log(imageData)
console.log(imageData.length)
Expand Down Expand Up @@ -469,7 +469,7 @@ const Welcome = ({navigation, route}) => {
posts: posts
})

if (data.data.noMorePosts) {
if (data.data.noMoreItems) {
dispatchImages({type: 'noMorePosts'})
}
}).catch(error => {
Expand Down Expand Up @@ -525,7 +525,7 @@ const Welcome = ({navigation, route}) => {
}

const layoutPollPosts = (data) => {
const {posts: pollData, noMorePosts} = data;
const {items: pollData, noMoreItems} = data;

console.log('Poll Data:', pollData)
console.log('Number of polls received:', pollData.length)
Expand Down Expand Up @@ -631,7 +631,7 @@ const Welcome = ({navigation, route}) => {
}
getPfpImageForPollWithAsync()
});
if (noMorePosts) {
if (noMoreItems) {
dispatchPolls({type: 'noMorePosts'})
}
}
Expand Down Expand Up @@ -673,7 +673,7 @@ const Welcome = ({navigation, route}) => {
}

const layoutThreadPosts = (data) => {
var threadData = data.data.posts
var threadData = data.data.items
console.log("The Thread data")
console.log(threadData)
console.log(threadData.length)
Expand Down Expand Up @@ -747,7 +747,7 @@ const Welcome = ({navigation, route}) => {
})
).then(posts => {
dispatchThreads({type: 'addPosts', posts})
if (data.data.noMorePosts) {
if (data.data.noMoreItems) {
dispatchThreads({type: 'noMorePosts'})
}
}).catch(error => {
Expand Down Expand Up @@ -794,7 +794,7 @@ const Welcome = ({navigation, route}) => {

const layoutCategoriesFound = (data) => {
console.log('DATA:', data)
var allData = data.categories
var allData = data.items

Promise.all(
allData.map(category => {
Expand Down Expand Up @@ -837,7 +837,7 @@ const Welcome = ({navigation, route}) => {
})
})
).then(categories => {
dispatchCategories({type: 'addCategories', categories, noMoreCategories: data.noMoreCategories})
dispatchCategories({type: 'addCategories', categories, noMoreCategories: data.noMoreItems})
}).catch(error => {
dispatchCategories({type: 'error', error: String(error)})
})
Expand Down
6 changes: 3 additions & 3 deletions screens/SafetySettings/BlockedAccountsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const BlockedAccountsScreen = ({navigation}) => {
const result = response.data;
const {data} = result;

const {blockedAccounts, noMoreItems} = data || {};
const {items, noMoreItems} = data || {};

const profileImageKeys = blockedAccounts.map(user => user.profileImageKey).filter(key => typeof key === 'string' && key.length > 1)
const profileImageKeys = items.map(user => user.profileImageKey).filter(key => typeof key === 'string' && key.length > 1)

const profileImageData = {};

Expand All @@ -57,7 +57,7 @@ const BlockedAccountsScreen = ({navigation}) => {
}
})

dispatch({type: 'addUsers', users: blockedAccounts})
dispatch({type: 'addUsers', users: items})
dispatch({type: 'addProfilePictures', profilePictures: profileImageData})
if (noMoreItems) dispatch({type: 'noMoreUsers'})
})
Expand Down
7 changes: 3 additions & 4 deletions screens/SelectCategorySearchScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ const SelectCategorySearchScreen = ({route, navigation}) => {
const result = response.data;
const {data} = result;

const {categories, noMoreCategories} = data;
const {items, noMoreItems} = data;

if (categories?.length === 0) return dispatch({type: 'noMoreCategories'})
if (items?.length === 0) return dispatch({type: 'noMoreCategories'})

console.log(categories)
layoutCategoriesFound(categories, noMoreCategories)
layoutCategoriesFound(items, noMoreItems)
console.log('Search complete.')

}).catch(error => {
Expand Down

0 comments on commit cfaba4d

Please sign in to comment.