spaces icon indicating copy to clipboard operation
spaces copied to clipboard

Feature Request: `autoEnter` for SpaceProvider

Open pchr-srf opened this issue 2 years ago • 8 comments

Would it be possible to optionally enter spaces automatically? Personally, I see more use cases where I immediately want to enter a space than not.

Suggestion:

  <SpacesProvider client={spaces}>
    <SpaceProvider name="my-space" autoEnter={true} user={{ name: 'Luigi'}}>
      <App />
    </SpaceProvider>
  </SpacesProvider>

Right now we're solving this in a "hacky" way so we don't have to do it in each component separately:

<SpacesProvider client={spaces}>
  <SpaceProvider name="my-space">
    <EnterSpace user={user}>
      {children}
    </EnterSpace>
  </SpaceProvider>
</SpacesProvider>

...

const EnterSpace = ({ children, user }) => {
  const { space } = useSpace();
  const [spaceEntered, setSpaceEntered] = useState(false);
  useEffect(() => {
    const enterSpace = async () => {
      await space.enter(user);
      setSpaceEntered(true);
    };
    const leaveSpace = async () => {
      await space.leave();
    };
    if (space) {
      enterSpace();
    }
    return () => {
      if (space) {
        leaveSpace();
      }
    };
  }, [space, user]);

  if (!spaceEntered) {
    return <LoadingIndicator />
  }

  return <>{children}</>;
};

Or is there something we're missing?

pchr-srf avatar Nov 06 '23 20:11 pchr-srf

Thanks for the suggested improvement @pchr-srf. One of our React engineers will reply shortly.

mattheworiordan avatar Nov 15 '23 12:11 mattheworiordan

Thanks, @pchr-srf. This looks like a very practical improvement. I imagine you'd expect a way to pass something like <LoadingIndicator /> too.

I'll put this forward to our product team.

dpiatek avatar Nov 15 '23 12:11 dpiatek

Hi @dpiatek and @mattheworiordan ! yeah exactly, that would be the idea 🙂 Thanks!

pchr-srf avatar Nov 15 '23 15:11 pchr-srf