Documentation
¶
Index ¶
- Variables
- type PopupEvent
- type PopupEventType
- type PopupForm
- type PopupManager
- func (p *PopupManager) Answer(ctx context.Context, request *apiv1.SubmitPopupAnswerRequest) error
- func (p *PopupManager) DismissActivePopup(id string) error
- func (p *PopupManager) GetCurrentPopup() *apiv1.PopupForm
- func (p *PopupManager) ShowPopup(popup PopupForm) (string, error)
- func (p *PopupManager) Subscribe() (<-chan PopupEvent, func())
- func (p *PopupManager) Validate(ctx context.Context, request *apiv1.ValidatePopupAnswerRequest) (*apiv1.ValidatePopupAnswerResponse, error)
- type TextPopupForm
- func (t *TextPopupForm) Answer(_ context.Context, req *apiv1.SubmitPopupAnswerRequest) (string, error)
- func (t *TextPopupForm) BuildProtoForm(id string) *apiv1.PopupForm
- func (t *TextPopupForm) Validate(_ context.Context, req *apiv1.ValidatePopupAnswerRequest) (*apiv1.ValidatePopupAnswerResponse, error)
Constants ¶
This section is empty.
Variables ¶
var ( // NoCurrentPopup indicates that an operation was attempted when no popup was active. NoCurrentPopup = fmt.Errorf("no active current popup") // CurrentPopupIsntMatchingWithGivenId indicates that the requested popup ID does not match the active popup. CurrentPopupIsntMatchingWithGivenId = fmt.Errorf("given id is not matching with the current popup") )
Functions ¶
This section is empty.
Types ¶
type PopupEvent ¶ added in v0.58.2
type PopupEvent struct {
Type PopupEventType
Form *apiv1.PopupForm
}
PopupEvent represents a popup lifecycle event delivered to subscribers.
type PopupEventType ¶ added in v0.58.2
type PopupEventType int
PopupEventType represents the lifecycle state change of a popup form.
const ( // PopupEventTypeOpened indicates a new popup has been displayed. PopupEventTypeOpened PopupEventType = iota // PopupEventTypeDismissed indicates the active popup has been closed or answered. PopupEventTypeDismissed )
type PopupForm ¶
type PopupForm interface {
// BuildProtoForm constructs the proto message for this popup with the given ID.
BuildProtoForm(id string) *apiv1.PopupForm
// Validate handles answer validation for this popup.
Validate(ctx context.Context, req *apiv1.ValidatePopupAnswerRequest) (*apiv1.ValidatePopupAnswerResponse, error)
// Answer handles answer submission for this popup. Returns the resolved result string for ShowPopup.
Answer(ctx context.Context, req *apiv1.SubmitPopupAnswerRequest) (string, error)
}
PopupForm is a polymorphic interface for backend popup implementations.
type PopupManager ¶
type PopupManager struct {
// contains filtered or unexported fields
}
PopupManager manages questions shown to user from frontend.
var Instance *PopupManager = NewPopupManager()
Instance is the singleton instance of PopupManager.
func NewPopupManager ¶
func NewPopupManager() *PopupManager
NewPopupManager creates an initialized instance of PopupManager.
func (*PopupManager) Answer ¶
func (p *PopupManager) Answer(ctx context.Context, request *apiv1.SubmitPopupAnswerRequest) error
Answer processes the finalized answer for the active popup.
func (*PopupManager) DismissActivePopup ¶ added in v0.58.2
func (p *PopupManager) DismissActivePopup(id string) error
DismissActivePopup dismisses the active popup from the server side without waiting for user submission.
func (*PopupManager) GetCurrentPopup ¶
func (p *PopupManager) GetCurrentPopup() *apiv1.PopupForm
GetCurrentPopup returns currently active popup proto data needed in frontend side to show the popup.
func (*PopupManager) ShowPopup ¶
func (p *PopupManager) ShowPopup(popup PopupForm) (string, error)
ShowPopup shows the popup UI on frontend side and waits until receiving the input.
func (*PopupManager) Subscribe ¶ added in v0.58.2
func (p *PopupManager) Subscribe() (<-chan PopupEvent, func())
Subscribe registers a listener for popup lifecycle events. It returns a receive-only channel and an unsubscribe function to clean up resources.
func (*PopupManager) Validate ¶
func (p *PopupManager) Validate(ctx context.Context, request *apiv1.ValidatePopupAnswerRequest) (*apiv1.ValidatePopupAnswerResponse, error)
Validate receives form input and checks if the request is valid to receive.
type TextPopupForm ¶ added in v0.58.2
type TextPopupForm struct {
Title string
Description string
Placeholder string
Validator func(value string) string
}
TextPopupForm represents a standard text input popup.
func (*TextPopupForm) Answer ¶ added in v0.58.2
func (t *TextPopupForm) Answer(_ context.Context, req *apiv1.SubmitPopupAnswerRequest) (string, error)
Answer implements PopupForm.
func (*TextPopupForm) BuildProtoForm ¶ added in v0.58.2
func (t *TextPopupForm) BuildProtoForm(id string) *apiv1.PopupForm
BuildProtoForm implements PopupForm.
func (*TextPopupForm) Validate ¶ added in v0.58.2
func (t *TextPopupForm) Validate(_ context.Context, req *apiv1.ValidatePopupAnswerRequest) (*apiv1.ValidatePopupAnswerResponse, error)
Validate implements PopupForm.