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

Implement resolve_relations to the refactored code #16

Open
fcisio opened this issue May 14, 2021 · 1 comment
Open

Implement resolve_relations to the refactored code #16

fcisio opened this issue May 14, 2021 · 1 comment

Comments

@fcisio
Copy link

fcisio commented May 14, 2021

Hi, I was super happy to see the migration to hooks and bridge V2.
Makes everything way easier to manage.

I did notice one thing that was previously covered, that now isn't.

Before, we had this snippet handling the relations on input change:

window.storyblok.on(['input'], (event) => {
  if (event.story && event.story.content._uid === reactComponent.state.blok._uid) {
    let commentContent = window.storyblok.addComments(event.story.content, event.story.id)
    window.storyblok.resolveRelations(event.story, sbConfig.resolveRelations, () => {
      reactComponent.setState({ blok: commentContent })
    })
  }
})

This has not been ported while refactoring:

storyblokInstance.on(['input'], (event) => {
  // live updates when editing
  if (event.story._uid === story._uid) {
    setStory(event.story)
  }
}) 

Here are the outputs before and now:

// Before
projects: [
  { name: "First Project", ... },
  { name: "Other Project", ... }
]

// Now
projects: ["e429d7ff-9368-436e-a3ea-449e4d70361b", "ce8c728a-5787-4f24-9f6c-4dadf2b95861"]

So we need a way to catch resolve_relations & possibly resolve_links on input change.
I'm having issues implementing this on my own, and the js-client documentation doesn't mention the functions in question.

Thanks

@fcisio
Copy link
Author

fcisio commented May 14, 2021

I have found the solution!

resolve_relations & resolve_links need to be passed in the bridge instance.
new StoryblokBridge({ resolve_relations: [] })

I've submitted a PR that fixes this along with other stuff #17

Basically, the sbConfig should be passed in StoryblokBridge and get('/...'). That way, the configs can be set in one place and will work everywhere.

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