Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const LoginForm = ({ history, loading: authLoading }) => {
const client = useApolloClient()
const [login, { error, loading }] = useMutation(LOGIN_MUTATION, {
onCompleted: data => {
setCookie(data.login.token)
// Force a reload of all current queries now that user is
// logged in
client.cache.reset().then(() => {
history.push('/home')
})
},
onError: err => console.error(err)
})
if (loading || authLoading) {
return
const useCachedQuery = (query, cacheKey, maxAge) => {
// fetch data no more than once every maxAge
const [stash, setStash] = useState(getStorageWithExpire(cacheKey, maxAge))
const client = useApolloClient()
useEffect(() => {
async function fetchData() {
const { data } = await client.query({ query })
if (data) {
setStash(data)
setStorageWithTimeStamp(cacheKey, data)
}
}
if (!stash) fetchData()
}, []) // eslint-disable-line
return stash
}
const TodoPublicList = (props: publicListProps) => {
const [olderTodosAvailable, setOlderTodosAvailable] = useState(props.latestTodo ? true : false)
const [newTodosCount, setNewTodosCount] = useState(0)
const [error, setError] = useState(false);
const [todos, setTodos] = useState([]);
let oldestTodoId = useRef(props.latestTodo && props.latestTodo.id ? props.latestTodo.id + 1 : 0);
let newestTodoId = useRef(props.latestTodo && props.latestTodo.id ? props.latestTodo.id : 0);
if(todos && todos.length) {
oldestTodoId.current = todos[todos.length - 1].id
newestTodoId.current = todos[0].id;
}
const client = useApolloClient();
const loadOlder = async () => {
const GET_OLD_PUBLIC_TODOS = gql`
query getOldPublicTodos($oldestTodoId: Int!) {
todos(
where: { is_public: { _eq: true }, id: { _lt: $oldestTodoId } }
limit: 7
order_by: { created_at: desc }
) {
id
title
created_at
user {
name
}
}
const useInitChat = (channelId) => {
const client = useApolloClient();
const [loadChats, query] = useLazyQuery(GET_CHAT_LOGS, {
variables: { channelId },
fetchPolicy: 'no-cache',
});
const cleanChatCache = () => {
client.writeQuery({
query: GET_CHAT_CACHED,
data: {
chatLogs: {
__typename: 'chatLogs',
logs: [],
changeType: null,
sortType: CHAT_SORT_BY_RECENT,
},
},
});
const WeatherGeolocationConsentScreen = ({
navigation,
}: NavigationInjectedProps) => {
const apolloClient = useApolloClient()
const onConsentPress = async () => {
const result = await requestLocationPermission(apolloClient)
if (result === RESULTS.BLOCKED) {
Alert.alert(
'Location permission',
'Location permission is blocked in the device ' +
'settings. Allow the app to access location to ' +
'see location-based weather.',
[
{
text: 'OK',
onPress: () => {
Linking.openSettings()
},
},
],
function App({ cookies }) {
const client = useApolloClient();
const myInfo = cookies.get('myInfo');
client.writeData({
data: {
isLoggedIn: !!myInfo,
},
});
const { data } = useQuery(IS_LOGGED_IN);
return (
function useWriteQuery({ query, variables }) {
const client = useApolloClient()
const queryField = getQueryField(query)
return function writeQuery(data) {
client.writeQuery({
query,
...(variables ? { variables } : {}),
data: { [queryField]: data }
})
}
}