Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fixed linter
Browse files Browse the repository at this point in the history
  • Loading branch information
redreceipt committed Jul 22, 2021
1 parent db56c96 commit 92ba465
Show file tree
Hide file tree
Showing 42 changed files with 323 additions and 341 deletions.
5 changes: 4 additions & 1 deletion apolloschurchapp/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
root: true,
extends: "@react-native-community",
extends: '@react-native-community',
env: {
'jest/globals': true,
},
};
10 changes: 5 additions & 5 deletions apolloschurchapp/__mocks__/@apollosproject/ui-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';

module.exports = {
track: () => '',
AnalyticsConsumer: ({ children }) => children({ test: jest.fn() }),
AnalyticsProvider: ({ children }) => children,
CoreNavigationAnalytics: ({ children }) =>
children({ onNavigationStateChange: jest.fn() }),
AnalyticsConsumer: ({children}) => children({test: jest.fn()}),
AnalyticsProvider: ({children}) => children,
CoreNavigationAnalytics: ({children}) =>
children({onNavigationStateChange: jest.fn()}),
TrackEventWhenLoaded: () => null,
withTrackOnPress: (Component) => (props) => <Component {...props} />,
withTrackOnPress: Component => props => <Component {...props} />,
};
6 changes: 3 additions & 3 deletions apolloschurchapp/__mocks__/@apollosproject/ui-media-player.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
MediaPlayerSpacer: ({ children }) => children,
MediaPlayerSpacer: ({children}) => children,
MediaPlayer: () => 'MediaPlayer',
MediaPlayerProvider: ({ children }) => children,
MediaPlayerProvider: ({children}) => children,
playVideoMutation: 'mutation { playVideo }',
withTabBarMediaSpacer: () => ({ children }) => children,
withTabBarMediaSpacer: () => ({children}) => children,
};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { NotificationsProvider: ({ children }) => children };
module.exports = {NotificationsProvider: ({children}) => children};
29 changes: 16 additions & 13 deletions apolloschurchapp/__mocks__/@react-native-community/async-storage.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
let cache = {};
export default {
setItem: (key, value) =>
new Promise((resolve, reject) =>
typeof key !== 'string' || typeof value !== 'string'
? reject(new Error('key and value must be string'))
: resolve((cache[key] = value))
new Promise(
(resolve, reject) =>
typeof key !== 'string' || typeof value !== 'string'
? reject(new Error('key and value must be string'))
: resolve((cache[key] = value)),
),
getItem: (key, value) =>
new Promise((resolve) =>
cache.hasOwnProperty(key) ? resolve(cache[key]) : resolve(null)
new Promise(
resolve =>
cache.hasOwnProperty(key) ? resolve(cache[key]) : resolve(null),
),
removeItem: (key) =>
new Promise((resolve, reject) =>
cache.hasOwnProperty(key)
? resolve(delete cache[key])
: reject('No such key!')
removeItem: key =>
new Promise(
(resolve, reject) =>
cache.hasOwnProperty(key)
? resolve(delete cache[key])
: reject('No such key!'),
),
clear: (key) => new Promise((resolve, reject) => resolve((cache = {}))),
clear: key => new Promise((resolve, reject) => resolve((cache = {}))),

getAllKeys: (key) =>
getAllKeys: key =>
new Promise((resolve, reject) => resolve(Object.keys(cache))),
};
8 changes: 4 additions & 4 deletions apolloschurchapp/__mocks__/react-native-safe-area-context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
SafeAreaConsumer: ({ children }) =>
children({ top: 0, bottom: 0, left: 0, right: 0 }),
SafeAreaProvider: ({ children }) => children,
SafeAreaConsumer: ({children}) =>
children({top: 0, bottom: 0, left: 0, right: 0}),
SafeAreaProvider: ({children}) => children,
SafeAreaView: jest.requireActual('react-native').SafeAreaView,
useSafeAreaInsets: () => ({ top: 3 }),
useSafeAreaInsets: () => ({top: 3}),
};
2 changes: 1 addition & 1 deletion apolloschurchapp/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './loadConfig';
import { AppRegistry, YellowBox } from 'react-native';
import {AppRegistry, YellowBox} from 'react-native';
import ApollosConfig from '@apollosproject/config';

// temp fix for the promise.finally
Expand Down
10 changes: 5 additions & 5 deletions apolloschurchapp/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Animated } from 'react-native';
import {Animated} from 'react-native';
import ApollosConfig from '@apollosproject/config';
import FRAGMENTS from '@apollosproject/ui-fragments';
import 'react-native/Libraries/Animated/src/bezier';
Expand All @@ -9,16 +9,16 @@ ApollosConfig.loadJs({
});

Animated.timing = (value, config) => ({
start: (callback) => {
start: callback => {
value.setValue(config.toValue);
callback && callback({ finished: true });
callback && callback({finished: true});
},
stop: () => ({}),
});
Animated.spring = (value, config) => ({
start: (callback) => {
start: callback => {
value.setValue(config.toValue);
callback && callback({ finished: true });
callback && callback({finished: true});
},
stop: () => ({}),
});
Expand Down
8 changes: 4 additions & 4 deletions apolloschurchapp/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import fragmentTypes from './src/client/fragmentTypes.json';
// If UniversalContentItem implements Node, Card, and ContentNode,
// our typemap would be { UniversalContentItem: ['Node', 'Card', 'ContentNode'] }
const TYPEMAP = fragmentTypes.__schema.types.reduce((acc, curr) => {
const { name } = curr;
const {name} = curr;
const types = Object.fromEntries(
curr.possibleTypes.map((type) => [type.name, name])
curr.possibleTypes.map(type => [type.name, name]),
);
Object.keys(types).forEach((key) => {
Object.keys(types).forEach(key => {
acc[key] = acc[key] ? [...acc[key], types[key]] : [types[key]];
});
return acc;
}, {});

ApollosConfig.loadJs({ FRAGMENTS, TYPEMAP });
ApollosConfig.loadJs({FRAGMENTS, TYPEMAP});
12 changes: 6 additions & 6 deletions apolloschurchapp/scripts/get-introspection-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getIntrospectionData = async () => {
try {
const query = await fetch(process.env.APP_DATA_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
query: `
{
Expand All @@ -29,26 +29,26 @@ const getIntrospectionData = async () => {
}),
});

const { data } = await query.json();
const {data} = await query.json();

/* eslint no-underscore-dangle: 0 */
data.__schema.types = await data.__schema.types.filter(
(type) => type.possibleTypes !== null
type => type.possibleTypes !== null,
);

await fs.writeFileSync(
Path.resolve(__dirname, '../src/client/fragmentTypes.json'),
JSON.stringify(data)
JSON.stringify(data),
);

console.log('Successfully wrote fragmentTypes!');
} catch (e) {
if (attempts < maxAttempts) {
console.log(
`Error writing fragmentTypes (-api probably hasn't started yet). Trying again after wait. Attempt: ${attempts +
1} of ${maxAttempts}`
1} of ${maxAttempts}`,
);
await new Promise((resolve) => setTimeout(resolve, timeBetweenAttempts)); // try again after waiting
await new Promise(resolve => setTimeout(resolve, timeBetweenAttempts)); // try again after waiting
getIntrospectionData();
} else {
// throw new Error('Error writing fragmentTypes file', e);
Expand Down
36 changes: 18 additions & 18 deletions apolloschurchapp/src/Providers.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';
import ApollosConfig from '@apollosproject/config';
import { NavigationService } from '@apollosproject/ui-kit';
import { AuthProvider } from '@apollosproject/ui-auth';
import { AnalyticsProvider } from '@apollosproject/ui-analytics';
import { NotificationsProvider } from '@apollosproject/ui-notifications';
import {NavigationService} from '@apollosproject/ui-kit';
import {AuthProvider} from '@apollosproject/ui-auth';
import {AnalyticsProvider} from '@apollosproject/ui-analytics';
import {NotificationsProvider} from '@apollosproject/ui-notifications';
import {
LiveProvider,
ACCEPT_FOLLOW_REQUEST,
} from '@apollosproject/ui-connected';
import { checkOnboardingStatusAndNavigate } from '@apollosproject/ui-onboarding';
import {checkOnboardingStatusAndNavigate} from '@apollosproject/ui-onboarding';

import ClientProvider, { client } from './client';
import ClientProvider, {client} from './client';

const AppProviders = (props) => (
const AppProviders = props => (
<ClientProvider {...props}>
<NotificationsProvider
oneSignalKey={ApollosConfig.ONE_SIGNAL_KEY}
// TODO deprecated prop
navigate={NavigationService.navigate}
handleExternalLink={(url) => {
handleExternalLink={url => {
const path = url.split('app-link/')[1];
const [route, location] = path.split('/');
if (route === 'content')
NavigationService.navigate('ContentSingle', { itemId: location });
if (route === 'nav')
if (route === 'content') {
NavigationService.navigate('ContentSingle', {itemId: location});
}
if (route === 'nav') {
NavigationService.navigate(
// turns "home" into "Home"
location[0].toUpperCase() + location.substring(1)
location[0].toUpperCase() + location.substring(1),
);
}
}}
actionMap={{
// accept a follow request when someone taps "accept" in a follow request push notification
acceptFollowRequest: ({ requestPersonId }) =>
acceptFollowRequest: ({requestPersonId}) =>
client.mutate({
mutation: ACCEPT_FOLLOW_REQUEST,
variables: { personId: requestPersonId },
variables: {personId: requestPersonId},
}),
}}
>
}}>
<AuthProvider
navigateToAuth={() => NavigationService.navigate('Auth')}
navigate={NavigationService.navigate}
Expand All @@ -47,8 +48,7 @@ const AppProviders = (props) => (
client,
navigation: NavigationService,
})
}
>
}>
<AnalyticsProvider>
<LiveProvider>{props.children}</LiveProvider>
</AnalyticsProvider>
Expand Down
12 changes: 6 additions & 6 deletions apolloschurchapp/src/client/cache.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { InMemoryCache } from '@apollo/client/cache';
import {InMemoryCache} from '@apollo/client/cache';
import AsyncStorage from '@react-native-community/async-storage';
import { CachePersistor } from 'apollo3-cache-persist';
import {CachePersistor} from 'apollo3-cache-persist';
import ApollosConfig from '@apollosproject/config';

// NOTE: this file is generated at runtime
// eslint-disable-next-line
import introspectionQueryResultData from "./fragmentTypes.json";

const finalPossibleTypes = {};
introspectionQueryResultData.__schema.types.forEach((supertype) => {
introspectionQueryResultData.__schema.types.forEach(supertype => {
if (supertype.possibleTypes) {
finalPossibleTypes[supertype.name] = [
...supertype.possibleTypes.map((subtype) => subtype.name),
...supertype.possibleTypes.map(subtype => subtype.name),
];
}
});
Expand All @@ -21,8 +21,8 @@ introspectionQueryResultData.__schema.types.forEach((supertype) => {
const SCHEMA_VERSION = `${ApollosConfig.SCHEMA_VERSION}-1`; // Must be a string.
const SCHEMA_VERSION_KEY = 'apollo-schema-version';

const nodeCacheRedirect = (_, { id }, { getCacheKey }) =>
id ? getCacheKey({ __typename: id.split(':')[0], id }) : null;
const nodeCacheRedirect = (_, {id}, {getCacheKey}) =>
id ? getCacheKey({__typename: id.split(':')[0], id}) : null;

const cache = new InMemoryCache({
possibleTypes: finalPossibleTypes,
Expand Down
20 changes: 11 additions & 9 deletions apolloschurchapp/src/client/httpLink.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { Platform } from 'react-native';
import { createUploadLink } from 'apollo-upload-client';
import {Platform} from 'react-native';
import {createUploadLink} from 'apollo-upload-client';
import ApollosConfig from '@apollosproject/config';
import { split, createHttpLink } from '@apollo/client';
import { getMainDefinition } from '@apollo/client/utilities';
import {split, createHttpLink} from '@apollo/client';
import {getMainDefinition} from '@apollo/client/utilities';

let uri = ApollosConfig.APP_DATA_URL;
const androidUri = ApollosConfig.ANDROID_URL || '10.0.2.2';

// Android's emulator requires localhost network traffic to go through 10.0.2.2
if (Platform.OS === 'android') uri = uri.replace('localhost', androidUri);
if (Platform.OS === 'android') {
uri = uri.replace('localhost', androidUri);
}

export default split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
({query}) => {
const {kind, operation} = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'mutation';
},
createUploadLink({ uri }),
createUploadLink({uri}),
createHttpLink({
uri,
useGETForQueries: true,
Expand All @@ -25,5 +27,5 @@ export default split(
// https://docs.fastly.com/en/guides/configuring-caching#do-not-cache
'Cache-Control': 'no-cache, no-store',
},
})
}),
);
21 changes: 10 additions & 11 deletions apolloschurchapp/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React, { PureComponent } from 'react';
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import { ApolloProvider, ApolloClient, ApolloLink } from '@apollo/client';
import { getVersion, getApplicationName } from 'react-native-device-info';
import {ApolloProvider, ApolloClient, ApolloLink} from '@apollo/client';
import {getVersion, getApplicationName} from 'react-native-device-info';

import { authLink, buildErrorLink } from '@apollosproject/ui-auth';
import {authLink, buildErrorLink} from '@apollosproject/ui-auth';

import { NavigationService } from '@apollosproject/ui-kit';
import { resolvers, schema, defaults, GET_ALL_DATA } from '../store';
import {NavigationService} from '@apollosproject/ui-kit';
import {resolvers, schema, defaults, GET_ALL_DATA} from '../store';

import httpLink from './httpLink';
import cache, { ensureCacheHydration } from './cache';
import cache, {ensureCacheHydration} from './cache';
import MARK_CACHE_LOADED from './markCacheLoaded';

const goToAuth = () => NavigationService.resetToAuth();
const wipeData = () =>
cache.writeQuery({ query: GET_ALL_DATA, data: defaults });
const wipeData = () => cache.writeQuery({query: GET_ALL_DATA, data: defaults});

let clearStore;
let storeIsResetting = false;
Expand Down Expand Up @@ -87,12 +86,12 @@ class ClientProvider extends PureComponent {
} catch (e) {
throw e;
} finally {
client.mutate({ mutation: MARK_CACHE_LOADED });
client.mutate({mutation: MARK_CACHE_LOADED});
}
}

render() {
const { children, ...otherProps } = this.props;
const {children, ...otherProps} = this.props;
return (
<ApolloProvider {...otherProps} client={client}>
{children}
Expand Down
Loading

0 comments on commit 92ba465

Please sign in to comment.