Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve something from partykit storage from the front end #11

Open
mheaversmozilla opened this issue Feb 12, 2024 · 0 comments

Comments

@mheaversmozilla
Copy link

Hi - I'm trying to wrap my brain around partykit and nextjs.

I have a working instance of this repo and what I want to do is, in each room created, store a unique prompt that all people in the chatroom should respond to - like "write about your earliest memory". In my code I'm calling this a 'challenge':

How do I either ensure that the users in the room are served this storage item, or vice versa ensure that when a user joins they retrieve the item from storage be displayed on the frontend component?

On the backend, in chatRoom.ts - I am successfully creating the prompt:

// chatRoom.ts (backend)

async onConnect(connection: ChatConnection) {
 await this.ensureChallenge();
})

async ensureChallenge() {
 if (!this.challenge) {
   let challenge = await this.party.storage.get<string>(
       'challenge'
     );
   if (!challenge) { 
     this.challenge = this.generateChallenge();
     await this.party.storage.put<string>(
       'challenge',
       challenge
     );
   }
 }
}

and on chat/[roomId]/page.tsx - I want to be able to display it to anyone in the room. Not sure how to make that connection of data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant