How to use the @rematch/core.dispatch.leaders function in @rematch/core

To help you get started, we’ve selected a few @rematch/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EvanBacon / Expo-Pillar-Valley / client / src / screens / LeaderboardScreen.js View on Github external
makeRemoteRequest = async () => {
    // console.log('makeRemoteRequest', Object.keys(Fire.shared));
    if (!Fire.shared.uid) {
      return;
    }

    if (this.state.refreshing) {
      return;
    }

    const timeout = setTimeout(() => {
      this.setState({ refreshing: false });
    }, 5000);
    this.setState({ refreshing: true });

    dispatch.leaders.getPagedAsync({
      start: this.lastKnownKey,
      size: Settings.leaderPageSize,
      callback: ({ cursor, noMore }) => {
        clearTimeout(timeout);

        this.setState({ noMore, refreshing: false });
        this.lastKnownKey = cursor;
      },
    });
  };
github EvanBacon / Expo-Pillar-Valley / client / src / ExpoParty / Fire.js View on Github external
init = () => {
    if (!Settings.isFirebaseEnabled) {
      return;
    }

    firebase.initializeApp(Secret);
    firebase.firestore().settings({ timestampsInSnapshots: true });
    dispatch.user.observeAuth();

    // DEBUG
    if (!Settings.debug) {
      dispatch.leaders.clear();
    }

    // dispatch.players.clear();
    // dispatch.user.clear();
  };
github EvanBacon / Expo-Pillar-Valley / client / src / rematch / models.js View on Github external
firebase.auth().onAuthStateChanged((user) => {
        if (!user) {
          // TODO: Evan: Y tho...
          dispatch.user.clear();
          dispatch.user.signInAnonymously();
        } else {
          dispatch.user.getAsync();
          dispatch.leaders.getAsync({ uid: user.uid });
        }
      });
    },
github EvanBacon / Expo-Pillar-Valley / client / src / rematch / models.js View on Github external
} else {
            const _data = doc.data();
            const uid = doc.id;
            data.push({
              uid,
              user: {
                key: uid,
                uid,
                displayName: parseName(_data.displayName, _data.deviceName),
                ..._data,
              },
            });
          }
        });
        console.log('Batch update', data.length, { data });
        dispatch.leaders.batchUpdate(data);
        const cursor = querySnapshot.docs[querySnapshot.docs.length - 1];
        if (callback) callback({ data, cursor, noMore: data.length < size });
        return;
      } catch (error) {
        console.error('Error getting documents: ', error);
      }
      if (callback) callback({});
    },
    getAsync: async ({ uid, callback }) => {
github EvanBacon / Expo-Pillar-Valley / client / src / rematch / models.js View on Github external
const nUser = {
              rank: 999999,
              displayName: _displayName,
              photoURL: currentUser.photoURL || '',
              score: 0,
              timestamp: Date.now(),
            };
            ref.set(nUser);
            if (callback) callback(nUser);
            return;
          }
          console.log(`No document: leaders/${uid}`);
        } else {
          const user = doc.data();
          console.log('got leader', user);
          dispatch.leaders.update({ uid, user });
          if (callback) callback(user);
          return;
        }
      } catch ({ message }) {
        console.log('Error: leaders.get', message);
        alert(message);
      }
      if (callback) callback(null);
    },
  },
github EvanBacon / Expo-Pillar-Valley / client / src / rematch / models.js View on Github external
);

            const user = {
              rank: 999999,
              displayName: _displayName,
              score: 0,
              timestamp: Date.now(),
            };
            if (currentUser.photoURL) {
              user.photoURL = currentUser.photoURL;
            }
            ref.add(user);
            dispatch.players.update({ uid, user });
            if (callback) callback(user);
          } else {
            dispatch.leaders.getAsync({
              uid,
              callback: (user) => {
                if (user) {
                  dispatch.players.update({ uid, user });
                }
                if (callback) callback(user);
              },
            });
          }
        } else {
          const user = doc.data();
          console.log('got player', user);
          dispatch.players.update({ uid, user });
          if (callback) callback(user);
        }
      } catch ({ message }) {