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

Add PageEvent.next_event #192

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def auth_login_content(kind: LoginKind) -> list[AnyComponent]:
)
),
c.Paragraph(text='(Passwords are not saved and is email stored in the browser via a JWT only)'),
c.ModelForm(model=LoginForm, submit_url='/api/auth/login'),
c.ModelForm(model=LoginForm, submit_url='/api/auth/login', display_mode='page'),
]
case 'github':
return [
Expand Down
6 changes: 5 additions & 1 deletion src/npm-fastui/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function useFireEvent(): { fireEvent: (event?: AnyEvent) => void } {
}
const detail: PageEventDetail = { clear: event.clear || false, context: event.context }
document.dispatchEvent(new CustomEvent(pageEventType(event), { detail }))
if (event.nextEvent) {
fireEventImpl(event.nextEvent)
}
break
}
case 'go-to':
Expand Down Expand Up @@ -61,6 +64,8 @@ export function useFireEvent(): { fireEvent: (event?: AnyEvent) => void } {
}
}

// fireEventImpl is recursive, but it doens't make sense for fireEvent to have fireEventImpl as a dep
// eslint-disable-next-line react-hooks/exhaustive-deps
const fireEvent = useCallback(fireEventImpl, [location])

return { fireEvent }
Expand Down Expand Up @@ -97,7 +102,6 @@ export function usePageEventListen(event?: PageEvent, initialContext: ContextTyp
}

const onEvent = (e: Event) => {
console.log('event:', e)
const event = e as CustomEvent<PageEventDetail>
const { context, clear } = event.detail
if (clear) {
Expand Down
1 change: 1 addition & 0 deletions src/npm-fastui/src/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface PageEvent {
pushPath?: string
context?: ContextType
clear?: boolean
nextEvent?: PageEvent | GoToEvent | BackEvent | AuthEvent
type: 'page'
}
export interface ContextType {
Expand Down
1 change: 1 addition & 0 deletions src/python-fastui/fastui/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PageEvent(BaseModel):
push_path: Union[str, None] = Field(default=None, serialization_alias='pushPath')
context: Union[ContextType, None] = None
clear: Union[bool, None] = None
next_event: 'Union[AnyEvent, None]' = Field(default=None, serialization_alias='nextEvent')
type: Literal['page'] = 'page'


Expand Down
Loading