-
Notifications
You must be signed in to change notification settings - Fork 20
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
chore(release-overlay-previews): add simple release overlay previews #2084
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
bundlesPerspective: string[] | ||
} | ||
|
||
const PostMessageReleases: FC<PostMessageReleasesProps> = (props) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This component will be used only inside the studio right? In PresentationTool
Maybe we could reuse here the releases from import {useReleases} from 'sanity'
, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case, the studio will be responsible for providing the list of releases, which will change a bit in the near future. And you won't need to do this here.
If it's inside the context of the studio the hook should work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah awesome — this works! I initially used a simple query as eventually we would like to try this out in custom overlay components and it was good research, but we don't need it here. Have updated :)
if (overlayDocumentReleases.length > 0) { | ||
const asapReleases = overlayDocumentReleases.filter((r) => r.metadata.releaseType === 'asap') | ||
|
||
const scheduledReleases = overlayDocumentReleases.filter( | ||
(r) => r.metadata.releaseType === 'scheduled', | ||
) | ||
|
||
if (asapReleases.length > 0) { | ||
const asapReleasesSorted = asapReleases.sort( | ||
(a, b) => new Date(a._createdAt).getTime() - new Date(b._createdAt).getTime(), | ||
) | ||
|
||
nearestUpcomingRelease = asapReleasesSorted[0] | ||
} else if (scheduledReleases.length > 0) { | ||
const scheduledReleasesSorted = scheduledReleases.sort( | ||
(a, b) => | ||
new Date(a.metadata.intendedPublishAt).getTime() - | ||
new Date(b.metadata.intendedPublishAt).getTime(), | ||
) | ||
|
||
nearestUpcomingRelease = scheduledReleasesSorted[0] | ||
|
||
timeTilNextRelease = getTimeDifferenceInDays( | ||
nearestUpcomingRelease.metadata.intendedPublishAt, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for sorting we also need to consider the release.publishAt date, which will be added once the release is scheduled.
So
const scheduledReleasesSorted = scheduledReleases.sort(
(a, b) =>
new Date(a.publishAt || a.metadata.intendedPublishAt).getTime() -
new Date(b.publishAt || b.metadata.intendedPublishAt).getTime(),
)
And we could also have releases that are neither asap or scheduled, which are the undecided
Maybe it's easier for now to copy this from sanity
to use the same sort mechanism. https://github.com/sanity-io/sanity/blob/corel/packages/sanity/src/core/releases/hooks/utils.ts#L6-L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you are using releases from useReleases
you can trust that they will be sorted, so you could use the first match found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using useReleases
now so all sorting logic is removed. Great call out!
} | ||
|
||
run() | ||
}, [comlink, perspective, bundlesPerspective]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will probably want here releases.data
as a dependency ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops sorry good catch 👍
68848ba
to
9f33145
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @georgedoescode ! It is amazing to see the releases in the overlays.
…2084) * chore(release-overlay-previews): add simple release overlay previews wip improve data fetching wip ui tidy up comments tidy up postmessagereleases ensure preview is only shown when data attribute is set * chore(release-overlay-previews): use useReleases hook * chore(release-overlay-previews): add releases.data to comlink useEffect deps * fix: update how the nearestRelease is obtained --------- Co-authored-by: pedrobonamin <[email protected]>
…2084) * chore(release-overlay-previews): add simple release overlay previews wip improve data fetching wip ui tidy up comments tidy up postmessagereleases ensure preview is only shown when data attribute is set * chore(release-overlay-previews): use useReleases hook * chore(release-overlay-previews): add releases.data to comlink useEffect deps * fix: update how the nearestRelease is obtained --------- Co-authored-by: pedrobonamin <[email protected]>
No description provided.