Documentation ¶
Overview ¶
Common functions, constants, and structures package for the frontend.
Index ¶
- Constants
- Variables
- func Fetch(input *map[string]interface{}) (*string, int, error)
- func FetchData(input *CallInput, output *Response) bool
- func FetchSSE(ch chan string)
- func LoadUser(user *models.User, ctx *app.Context) error
- func LoadUser2(encoded string, user *models.User) error
- func ReadFile(file app.Value) (data []byte, err error)
- func SaveUser(user *models.User, ctx *app.Context) error
- func SaveUser2(plain *string, user *models.User) error
- func ShowGenericToast(pl *ToastPayload)
- type CallInput
- type Event
- type Response
- type Toast
- type ToastInterface
- type ToastPayload
Constants ¶
const ( // Event-related (non-)error messages. MSG_SERVER_START = "The server has just (re)started." MSG_SERVER_RESTART = "The server is restarting now..." MSG_NEW_POLL = "New poll has been just added." MSG_NEW_POST = "New post added by %s." MSG_STATE_OFFLINE = "You have gone offline. Check your Internet connection." MSG_STATE_ONLINE = "You are back online." // Flow/Posts-related error messages. ERR_INVALID_REPLY = "No valid content was entered." ERR_POST_UNAUTH_DELETE = "You can only delete your own posts." ERR_POST_NOT_FOUND = "Post not found (may be deleted)." ERR_USER_NOT_FOUND = "User not found." ERR_PRIVATE_ACC = "This account is private." // Generic error messages on the FE. ERR_CANNOT_REACH_BE = "littr can't connect to the server." ERR_CANNOT_GET_DATA = "littr can't read the data." ERR_LOGIN_AGAIN = "Please log in again." // Login-related error messages. MSG_USER_ACTIVATED = "The user has been successfully activated, try logging in." ERR_ALL_FIELDS_REQUIRED = "All fields are required." ERR_LOGIN_CHARS_LIMIT = "Only characters a-z, A-Z and numbers can be used." ERR_ACCESS_DENIED = "Incorrect login details entered." ERR_LOCAL_STORAGE_USER_FAIL = "littr can't save user data to your browser." ERR_ACTIVATION_INVALID_UUID = "Invalid activation UUID entered." ERR_ACTIVATION_EXPIRED_UUID = "Expired activation UUID entered." // Notification-related (non-)error messages. MSG_SUBSCRIPTION_UPDATED = "Subscription updated." MSG_UNSUBSCRIBED_SUCCESS = "Successfully unsubscribed, notifications are off." ERR_SUBSCRIPTION_UPDATE_FAIL = "Your subscription could not be updated, please try again later." ERR_NOTIF_PERMISSION_DENIED = "User notification denied." ERR_NOTIF_UNSUPPORTED_BROWSER = "Notifications are not supported in this browser." // Polls-related (non-)error messages. MSG_NO_POLL_TO_SHOW = "No poll to display, click here to create one." ERR_POLL_UNAUTH_DELETE = "You can delete your own polls only." ERR_POLL_OPTION_MISMATCH = "Such an option is not associated with this poll." // Post-related (non-)error messages. MSG_IMAGE_READY = "Image is ready to upload." ERR_LOCAL_STORAGE_LOAD_FAIL = "Unable to decode user data." ERR_POST_TEXTAREA_EMPTY = "No valid content was entered." ERR_POLL_FIELDS_REQUIRED = "A poll question and at least two options are required." ERR_POST_UNKNOWN_TYPE = "Unknown post type." // Register-related error messages. ERR_REGISTER_FIELDS_REQUIRED = "All fields are required." ERR_REGISTER_CHARSET_LIMIT = "Only characters a-z, A-Z and numbers can be used." ERR_WRONG_EMAIL_FORMAT = "Invalid e-mail address format entered." // Reset-related (non-)error messages. MSG_RESET_PASSPHRASE_SUCCESS = "Your passphrase has been changed, check your e-mail inbox." MSG_RESET_REQUEST_SUCCESS = "A request to reset your passphrase has been sent, please check your inbox." ERR_RESET_FIELD_REQUIRED = "E-mail address is required." ERR_RESET_UUID_FIELD_EMPTY = "An UUID string is required to continue, please check your inbox." ERR_RESET_INVALID_INPUT_DATA = "Invalid input data entered." // Settings-related (non-)error messages. MSG_PASSPHRASE_UPDATED = "The passphrase was successfully updated." MSG_ABOUT_TEXT_UPDATED = "The About text has been successfully updated." MSG_WEBSITE_UPDATED = "The website has been successfully updated." MSG_SUBSCRIPTION_REQ_SUCCESS = "Successfully subscribed to notifications." MSG_LOCAL_TIME_TOGGLE = "Local time mode changed." MSG_PRIVATE_MODE_TOGGLE = "Private mode changed." MSG_AVATAR_CHANGE_SUCCESS = "Avatar has been successfully updated." ERR_PASSPHRASE_MISMATCH = "Passphrases do not match." ERR_PASSPHRASE_MISSING = "The passphrase field must be filled in." ERR_ABOUT_TEXT_UNCHANGED = "The About text area is empty or the text has not changed." ERR_ABOUT_TEXT_CHAR_LIMIT = "The About text must be less than 100 characters." ERR_WEBSITE_UNCHANGED = "Website URL must be filled in or changed." ERR_WEBSITE_REGEXP_FAIL = "Failed to check the website format." ERR_WEBSITE_INVALID = "The website is probably not a valid URL." ERR_SUBSCRIPTION_BLANK_UUID = "Blank UUID string." ERR_SUBSCRIPTION_REQ_FAIL = "Failed to subscribe to notifications: " // Users-related (non-)error messages. MSG_USER_UPDATED_SUCCESS = "User updated, request deleted." MSG_FOLLOW_REQUEST_REMOVED = "Follow request deleted." MSG_REQ_TO_FOLLOW_SUCCESS = "The follow request was sent successfully." MSG_USER_FOLLOW_ADD_FMT = "User %s followed now." MSG_USER_FOLLOW_REMOVE_FMT = "User %s unfollowed." MSG_SHADE_SUCCESSFUL = "User was (un)shaded successfully." )
const ( GENERIC_TOAST_NAME = "snackbar-general-bottom" GENERIC_TOAST_LINK = "snackbar-general-bottom-link" GENERIC_TOAST_TIMEOUT = 5000 DISMISS_LOCK = "dismissLock" )
const ( JS_LITTR_SSE = "littrServiceSSE" JS_LITTR_EVENT = "littrEventSSE" )
const ( // Toast type error = red10. TTYPE_ERR = "error" // Toast type info = blue10. TTYPE_INFO = "info" // Toast type success = green10. TTYPE_SUCCESS = "success" )
Variables ¶
var ( // Those vars are used during the build --- linker (ld) bakes the values in. AppVersion string AppPepper string VapidPublicKey string )
var DefaultRequestInit = map[string]interface{}{ "body": nil, "cache": "default", "credentials": "same-origin", "headers": map[string]interface{}{}, "keepalive": false, "method": "GET", "mode": "cors", "priority": "auto", "redirect": "follow", "referrer": "about:client", "referrerPolicy": "", "signal": nil, "url": "", }
RequestInit object. Usable map for export to JSValue via app.ValueOf(x)
var ToastColor = func(ttype string) string { switch ttype { case TTYPE_SUCCESS: return "green10" case TTYPE_ERR: return "red10" case TTYPE_INFO: default: return "blue10" } return "blue10" }
ToastColor is a helper function reference to define the colour palette for such toast types.
Functions ¶
func Fetch ¶ added in v0.44.40
Fetch is a raw implementation of http.Client to omit the `net/*` packages completely. The main purpose is to further optimize the disk and memory space needed by the WASM app client.
func FetchData ¶ added in v0.42.0
FetchData is a metafunction for input options conversion for the main, lighter Fetch() function.
func FetchSSE ¶ added in v0.44.40
func FetchSSE(ch chan string)
FetchSSE is an early implementation of the SSE client using only await fetch() as the base function.
func LoadUser ¶ added in v0.41.8
LoadUser uses the app.Context pointer to load the encoded user string from the LocalStorage to decode it back to the models.User struct.
func SaveUser ¶ added in v0.41.8
SaveUser uses the app.Context pointer to save the given pointer to models.User and encode it into a JSON string.
func ShowGenericToast ¶ added in v0.44.41
func ShowGenericToast(pl *ToastPayload)
ShowGenericToast is a helper function to show requested toast/snackbar. At the moment, the concept is that there are two nodes loaded in DOM (top and bottom toast/snack) to show common response (top), or system alerts (bottom).
Types ¶
type CallInput ¶
type CallInput struct { Method string Url string CallerID string PageNo int HideReplies bool // Payload body for the API call. Data interface{} }
DTO-in structure for the API call.
type Event ¶ added in v0.44.40
func NewSSEEvent ¶ added in v0.44.40
type Response ¶ added in v0.42.0
type Response struct { Code int Error error Message string `json:"message"` Timestamp int64 `json:"timestamp"` // Custom Data field per the app component. Must be referenced via the inner pointer too when the output is required. // // Example: // output := &common.Response{&model.User} // Data interface{} `json:"data"` }
Standardized common response from API.
type Toast ¶ added in v0.41.1
type Toast struct { // AppContext is a pointer reference to the application context. AppContext *app.Context // TLink is a field to hold the hypertext link. TLink string // TText is a filed to hold the very text message to display. TText string // TType defines the message type (error, info, success). TType string // TID is a filed to hold the toast's UUID. TID int64 }
func (*Toast) Context ¶ added in v0.41.1
Context sets the application context pointer reference. Returns itself.
func (*Toast) Dispatch ¶ added in v0.41.1
func (t *Toast) Dispatch(...interface{})
Dispatch is a wrapper function that wraps the function ShowGenericToast() from pkg/frontend/common/snack.go.
func (*Toast) Link ¶ added in v0.41.1
Link sets the string input as the TLink content. Returns itself.
type ToastInterface ¶ added in v0.41.1
type ToastInterface interface { // Context method sets the application context pointer reference. Context(*app.Context) *Toast // Text method write the input string to the TText field. Text(string) *Toast // Link method writes the input string to the TLink field. Link(string) *Toast // Type method writes the input string to the TType field. Type(string) *Toast // SetPrefix method enables to set the logging prefix. Can be removed afterwards. SetPrefix(string) *Toast // RemovePrefix method removes the previously added logging prefix. RemovePrefix() *Toast // Dispatch sends the instance itself to the Content type of a view. This method is the final one. Dispatch(interface{}, func(*Toast, interface{})) }