Skip to content

feat(location): add back function capability in the location #520

Open
vctrths wants to merge 4 commits into
alineacms:v2from
vctrths:feat/location-func
Open

feat(location): add back function capability in the location #520
vctrths wants to merge 4 commits into
alineacms:v2from
vctrths:feat/location-func

Conversation

@vctrths

@vctrths vctrths commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/alinea@520

commit: d38bf6e

Comment on lines +685 to +737
function useResolvedEntryPickerLocation(
options: Partial<EntryPickerOptions>,
fallbackLocation: EditorLocation | undefined
): EditorLocation | undefined {
const graph = useGraph()
const entry = useEntry()
const [location, setLocation] = useState(() =>
typeof options.location === 'function'
? fallbackLocation
: (options.location ?? fallbackLocation)
)

useEffect(() => {
if (typeof options.location !== 'function') {
setLocation(options.location ?? fallbackLocation)
return
}

if (!entry) {
setLocation(fallbackLocation)
return
}

let cancelled = false
const info: EditorInfo = {graph, entry}
Promise.resolve(options.location(info))
.then(location => {
if (!cancelled) setLocation(location ?? fallbackLocation)
})
.catch(error => {
console.error('Failed to resolve entry picker location', error)
if (!cancelled) setLocation(fallbackLocation)
})

return () => {
cancelled = true
}
}, [
entry?.id,
entry?.locale,
entry?.parentId,
entry?.root,
entry?.type,
entry?.workspace,
fallbackLocation?.parentId,
fallbackLocation?.root,
fallbackLocation?.workspace,
graph,
options.location
])

return location
}

@benmerckx benmerckx Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be an atom not an effect

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

Successfully merging this pull request may close these issues.

2 participants