Skip to content

Commit

Permalink
Resolve PR comments in the example
Browse files Browse the repository at this point in the history
  • Loading branch information
takameyer committed Jun 14, 2023
1 parent 4d68048 commit e5be15f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
1 change: 0 additions & 1 deletion example/app/AppNonSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {TaskManager} from './components/TaskManager';
import {useQuery} from '@realm/react';

export const AppNonSync = () => {
debugger;
const [showDone, setShowDone] = React.useState(false);
const tasks = useQuery(
Task,
Expand Down
16 changes: 9 additions & 7 deletions example/app/AppSync.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from 'react';
import {useApp, useUser} from '@realm/react';
import {useApp, useAuth, useQuery, useRealm, useUser} from '@realm/react';
import {Pressable, StyleSheet, Text} from 'react-native';

import {Task} from './models/Task';
Expand All @@ -9,9 +9,6 @@ import {shadows} from './styles/shadows';
import colors from './styles/colors';
import {OfflineModeButton} from './components/OfflineModeButton';

import {useRealm, useQuery} from '@realm/react';
import {useAuth} from '@realm/react';

export const AppSync: React.FC = () => {
const realm = useRealm();
const user = useUser();
Expand All @@ -28,9 +25,14 @@ export const AppSync: React.FC = () => {
);

useEffect(() => {
realm.subscriptions.update(mutableSubs => {
mutableSubs.add(tasks);
});
const asyncThing = async () => {
await tasks.subscribe();
};

asyncThing();
() => {
realm.unsubscribe();
};
}, [realm, tasks]);

return (
Expand Down
1 change: 0 additions & 1 deletion example/app/AppWrapperSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const AppWrapperSync: React.FC<{
timeOut: 1000,
timeOutBehavior: OpenRealmTimeOutBehavior.OpenLocalRealm,
},
onError: (_, error) => console.error('sync error', error),
}}>
<AppSync />
</RealmProvider>
Expand Down
27 changes: 9 additions & 18 deletions example/app/components/LoginScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useState} from 'react';
import React, {useState} from 'react';
import {View, Text, StyleSheet, TextInput, Pressable} from 'react-native';
import colors from '../styles/colors';
import {shadows} from '../styles/shadows';
Expand All @@ -11,14 +11,6 @@ export const LoginScreen = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const handleLogin = useCallback(() => {
logInWithEmailPassword({email, password});
}, [logInWithEmailPassword, email, password]);

const handleRegister = useCallback(() => {
register({email, password});
}, [register, email, password]);

return (
<View style={styles.content}>
<View style={styles.inputContainer}>
Expand All @@ -45,29 +37,28 @@ export const LoginScreen = () => {
/>
</View>

{result.error && result.error.operation === AuthOperationName.LogIn && (
{result?.error?.operation === AuthOperationName.LogIn && (
<Text style={[styles.error]}>
There was an error logging in, please try again{' '}
</Text>
)}

{result.error &&
result.error.operation === AuthOperationName.Register && (
<Text style={[styles.error]}>
There was an error registering, please try again
</Text>
)}
{result?.error?.operation === AuthOperationName.Register && (
<Text style={[styles.error]}>
There was an error registering, please try again
</Text>
)}

<View style={styles.buttons}>
<Pressable
onPress={handleLogin}
onPress={() => logInWithEmailPassword(email, password)}
style={[styles.button, result.pending && styles.buttonDisabled]}
disabled={result.pending}>
<Text style={buttonStyles.text}>Login</Text>
</Pressable>

<Pressable
onPress={handleRegister}
onPress={() => register(email, password)}
style={[
styles.button,
result.pending && styles.buttonDisabled,
Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @format
*/

import 'react-native-get-random-values';
import React from 'react';
import {AppRegistry} from 'react-native';
import {AppWrapperNonSync} from './app/AppWrapperNonSync';
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5be15f

Please sign in to comment.