Skip to content

Commit

Permalink
Merge pull request #74 from Grad-Squad/cleanup/general
Browse files Browse the repository at this point in the history
fix: final fixes
  • Loading branch information
rameziophobia authored Feb 6, 2022
2 parents 10d6ee5 + 10b582f commit 81cb5ff
Show file tree
Hide file tree
Showing 93 changed files with 22,549 additions and 29,310 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/cdRelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CD_Release

on:
release:
types: [published]

jobs:
Continous_Deployment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: 16

- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci

- name: Setup Expo and EAS
uses: expo/expo-github-action@v7
with:
expo-version: 5.x
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}

- name: Build app and push app to play store
run: eas build --non-interactive --auto-submit --platform android

- uses: sarisia/actions-status-discord@v1
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16

- uses: actions/cache@v2
with:
Expand Down
6 changes: 4 additions & 2 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { Colors } from 'styles';
import ErrorSnackbarProvider from 'common/ErrorSnackbar/ErrorSnackbarProvider';
import ReactQueryClient from 'components/ReactQueryClient/ReactQueryClient';
import { Provider as ReduxProvider } from 'react-redux';
import { Platform, UIManager } from 'react-native';
import { LogBox, Platform, UIManager } from 'react-native';
import { LocalizationProvider } from './localization';
import initStyles from './styles/init';
import RootNavigator from './navigation/RootNavigator';
import store from './globalStore/store';

LogBox.ignoreLogs(['Setting a timer']);

const theme = {
...DefaultTheme,
colors: {
Expand Down Expand Up @@ -44,7 +46,7 @@ function App() {
Sentry.init({
dsn: process.env.SENTRY_DSN,
enableInExpoDevelopment: true,
enableNative: false,
// enableNative: false,
debug: true, // TODO set to false in production
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ exports[`should match snapshot when profilePicture={ uri: 'https://picsum.photos
}
>
<Image
resizeMode="cover"
source={
Object {
"uri": "https://picsum.photos/200/300",
}
}
style={
Object {
"alignSelf": "center",
"borderRadius": 50,
"height": 50,
"width": 50,
Expand Down Expand Up @@ -109,9 +111,11 @@ exports[`should match snapshot when profilePicture=null 1`] = `
}
>
<Image
resizeMode="cover"
source={1}
style={
Object {
"alignSelf": "center",
"borderRadius": 50,
"height": 50,
"width": 50,
Expand Down
4 changes: 3 additions & 1 deletion __test__/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';

jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
Expand Down
22 changes: 18 additions & 4 deletions api/AxiosProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useLocalization } from 'localization/LocalizationProvider';
import { useNetInfo } from '@react-native-community/netinfo';
import ScreenNames from 'navigation/ScreenNames';
import { Alert } from 'react-native';
import LoadingIndicator from 'common/LoadingIndicator';
import unauthorizedRedirectBlacklist from './unauthorizedRedirectBlacklist';
import endpoints from './endpoints/endpoints';

Expand All @@ -30,14 +31,22 @@ const AxiosProvider = ({ navigationRef, children }) => {
const { t } = useLocalization();

const [accessToken, setAccessToken] = useState('');
const [hasCheckedAccessToken, SetHasCheckedAccessToken] = useState(false);
const [refreshToken, setRefreshToken] = useState('');
const [onAccessTokenChangeCallbacks, setOnAccessTokenChangeCallbacks] =
useState([]);

useEffect(() => {
(async () => {
setAccessToken(await getItemFromStorage(localStorageKeys.access_token));
setRefreshToken(await getItemFromStorage(localStorageKeys.refresh_token));
const newAccessToken = await getItemFromStorage(
localStorageKeys.access_token
);
const newRefreshToken = await getItemFromStorage(
localStorageKeys.refresh_token
);
setAccessToken(newAccessToken);
setRefreshToken(newRefreshToken);
SetHasCheckedAccessToken(true);
})();
}, []);

Expand Down Expand Up @@ -82,7 +91,7 @@ const AxiosProvider = ({ navigationRef, children }) => {
index: 0,
routes: [{ name: ScreenNames.LOGIN }],
});
Alert.alert('Sorry, You have to login again');
Alert.alert(t('Sorry, You have to log in again'));
}
} else {
const refreshData = await newAxios.post(endpoints.auth.refresh, {
Expand Down Expand Up @@ -140,9 +149,14 @@ const AxiosProvider = ({ navigationRef, children }) => {
addOnAccessTokenChangeCallback: (callback) => {
setOnAccessTokenChangeCallbacks((prev) => [...prev, callback]);
},
isLoggedIn: !!accessToken,
}}
>
{children}
{hasCheckedAccessToken ? (
children
) : (
<LoadingIndicator fullScreen size="large" />
)}
</AxiosContext.Provider>
);
};
Expand Down
15 changes: 2 additions & 13 deletions api/endpoints/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMutation } from 'react-query';
import { formatString } from 'utility';
import endpoints from './endpoints';

const onSuccessUpdateTokens =
export const onSuccessUpdateTokens =
(
updateAccessToken,
updateRefreshToken,
Expand Down Expand Up @@ -126,12 +126,7 @@ export const useAPIRefreshToken = (mutationConfig) => {
};

export const useAPIRegister = (mutationConfig) => {
const {
axios,
updateAccessToken,
updateRefreshToken,
addOnAccessTokenChangeCallback,
} = useAxios();
const { axios } = useAxios();
return useMutation(
async ({ email, password, name }) => {
const { data } = await axios.post(endpoints.auth.register, {
Expand All @@ -149,12 +144,6 @@ export const useAPIRegister = (mutationConfig) => {
},
{
...mutationConfig,
onSuccess: onSuccessUpdateTokens(
updateAccessToken,
updateRefreshToken,
addOnAccessTokenChangeCallback,
mutationConfig
),
}
);
};
Expand Down
1 change: 1 addition & 0 deletions api/endpoints/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default Object.freeze({
profileById: '/profiles/{0}',
update: '/profiles/{0}',
followers: '/profiles/{0}/followers',
followed: '/profiles/me/followed',
postsByProfileId: '/profiles/{0}/posts',
followProfile: '/profiles/{0}/follow',
AddPostToBookmark: '/profiles/{0}/bookmarks/add/{1}',
Expand Down
18 changes: 18 additions & 0 deletions api/endpoints/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ export const useAPIGetProfileFollowers = (profileId) => {
);
};

export const profilesFollowedKey = 'profilesFollowed';
export const useAPIGetProfilesFollowed = () => {
const { axios } = useAxios();
return useInfiniteQuery(
profilesFollowedKey,
async ({ pageParam = 1 }) => {
const { data } = await axios.get(endpoints.profile.followed, {
params: {
page: pageParam,
limit: 10,
},
});
return data;
},
{ getNextPageParam: (lastPage) => lastPage.nextPage }
);
};

export const profileByIdQueryKey = (profileId) => ['profile by id', profileId];
export const useAPIGetProfileById = (profileId, options) => {
const { axios } = useAxios();
Expand Down
12 changes: 6 additions & 6 deletions api/endpoints/ratings.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export const useAPIUnvotePost = (mutationConfig) =>{

export const useAPIUpvoteComment = (mutationConfig) =>{
const { axios } = useAxios();
return useMutation( async ({commentId, ratingId}) => {
return useMutation( async ({postId, ratingId}) => {
const {
data,
} = await axios.patch(formatString(endpoints.comments.ratings,commentId,ratingId), {
} = await axios.patch(formatString(endpoints.comments.ratings,postId,ratingId), {
type: 'upvoted',
});
return data;
Expand All @@ -53,10 +53,10 @@ export const useAPIUpvoteComment = (mutationConfig) =>{

export const useAPIDownvoteComment = (mutationConfig) =>{
const { axios } = useAxios();
return useMutation( async ({commentId, ratingId}) => {
return useMutation( async ({postId, ratingId}) => {
const {
data,
} = await axios.patch(formatString(endpoints.comments.ratings,commentId,ratingId), {
} = await axios.patch(formatString(endpoints.comments.ratings,postId,ratingId), {
type: 'downvoted',
});
return data;
Expand All @@ -65,10 +65,10 @@ export const useAPIDownvoteComment = (mutationConfig) =>{

export const useAPIUnvoteComment = (mutationConfig) =>{
const { axios } = useAxios();
return useMutation( async ({commentId, ratingId}) => {
return useMutation( async ({postId, ratingId}) => {
const {
data,
} = await axios.patch(formatString(endpoints.comments.ratings,commentId,ratingId), {
} = await axios.patch(formatString(endpoints.comments.ratings,postId,ratingId), {
type: 'none',
});
return data;
Expand Down
63 changes: 53 additions & 10 deletions api/endpoints/search.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
import { useAxios } from 'api/AxiosProvider';
import { useQuery } from 'react-query';
import { useInfiniteQuery } from 'react-query';
import { useSelector } from 'react-redux';
import { formatString } from 'utility';
import endpoints from './endpoints';

export const searchQueryKey = (searchText, params) => [
'search text',
export const searchPeopleQueryKey = (searchText, params) => [
'search text people',
searchText,
JSON.stringify(params),
];
export const useAPIGetSearchResult = (searchText, options) => {
export const useAPISearchPeople = (searchText, options) => {
const { axios } = useAxios();
const params = useSelector((state) => state.search.params);
return useQuery(
searchQueryKey(searchText, params),
async () => {
return useInfiniteQuery(
searchPeopleQueryKey(searchText, params),
async ({ pageParam = 1 }) => {
const { data } = await axios.get(
formatString(endpoints.search.search, searchText),
{ params }
{
params: {
...params,
postslimit: 1,
profilesLimit: 10,
postsPage: 1,
profilesPage: pageParam,
},
}
);
return data;
return data.profiles;
},
options
{
getNextPageParam: (lastPage) => lastPage?.nextPage,
...options,
}
);
};

export const searchPostsQueryKey = (searchText, params) => [
'search text posts',
searchText,
JSON.stringify(params),
];
export const useAPISearchPosts = (searchText, options) => {
const { axios } = useAxios();
const params = useSelector((state) => state.search.params);
return useInfiniteQuery(
searchPostsQueryKey(searchText, params),
async ({ pageParam = 1 }) => {
const { data } = await axios.get(
formatString(endpoints.search.search, searchText),
{
params: {
...params,
postslimit: 10,
profilesLimit: 1,
postsPage: pageParam,
profilesPage: 1,
},
}
);
return data.posts;
},
{
getNextPageParam: (lastPage) => lastPage?.nextPage,
...options,
}
);
};
2 changes: 1 addition & 1 deletion api/unauthorizedRedirectBlacklist.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import endpoints from './endpoints/endpoints';

export default [endpoints.auth.login];
export default [endpoints.auth.login, endpoints.auth.verifyCode];
12 changes: 12 additions & 0 deletions api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export const replaceItemInPages = (oldData, id, newItem) => {
});
return copy;
};
export const updateItemInPages = (oldData, id, callback) => {
const copy = deepCopy(oldData);
copy.pages.every((page) => {
const itemToUpdateIndex = page.data.findIndex((item) => item.id === id);
if (itemToUpdateIndex !== -1) {
page.data[itemToUpdateIndex] = callback(page.data[itemToUpdateIndex]);
return false;
}
return true;
});
return copy;
};

// https://stackoverflow.com/questions/7492921/how-can-i-implement-a-search-using-regex
export const searchUtil = (find, within) => {
Expand Down
Loading

0 comments on commit 81cb5ff

Please sign in to comment.