Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
c7933df2
Commit
c7933df2
authored
Mar 07, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate ToastMessenger to TypeScript
parent
594a1130
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
33 deletions
+30
-33
toast-messenger.ts
src/sidebar/services/toast-messenger.ts
+30
-33
No files found.
src/sidebar/services/toast-messenger.
j
s
→
src/sidebar/services/toast-messenger.
t
s
View file @
c7933df2
import
{
generateHexString
}
from
'../../shared/random'
;
import
type
{
SidebarStore
}
from
'../store'
;
// How long toast messages should be displayed before they are dismissed, in ms
const
MESSAGE_DISPLAY_TIME
=
5000
;
...
...
@@ -7,13 +8,19 @@ const MESSAGE_DISMISS_DELAY = 500;
/**
* Additional control over the display of a particular message.
*
* @typedef MessageOptions
* @prop {boolean} [autoDismiss=true] - Whether the toast message automatically disappears.
* @prop {string} [moreInfoURL=''] - Optional URL for users to visit for "more info"
* @prop {boolean} [visuallyHidden=false] - When `true`, message will be visually
* hidden but still available to screen readers.
*/
type
MessageOptions
=
{
/** Whether the toast message automatically disappears. */
autoDismiss
?:
boolean
;
/** Optional URL for users to visit for "more info" */
moreInfoURL
?:
string
;
/**
* When `true`, message will be visually hidden but still available to screen
* readers.
*/
visuallyHidden
?:
boolean
;
};
/**
* A service for managing toast messages. The service will auto-dismiss and
...
...
@@ -22,10 +29,9 @@ const MESSAGE_DISMISS_DELAY = 500;
*/
// @inject
export
class
ToastMessengerService
{
/**
* @param {import('../store').SidebarStore} store
*/
constructor
(
store
)
{
private
_store
:
SidebarStore
;
constructor
(
store
:
SidebarStore
)
{
this
.
_store
=
store
;
}
...
...
@@ -34,10 +40,10 @@ export class ToastMessengerService {
* it after a bit. This allows effects/animations to happen before the
* message is removed entirely.
*
* @param
{string} messageId - The value of the `id` property for the
*
message that is
to be dismissed.
* @param
messageId - The value of the `id` property for the message that is
* to be dismissed.
*/
dismiss
(
messageId
)
{
dismiss
(
messageId
:
string
)
{
const
message
=
this
.
_store
.
getToastMessage
(
messageId
);
if
(
message
&&
!
message
.
isDismissed
)
{
this
.
_store
.
updateToastMessage
({
...
message
,
isDismissed
:
true
});
...
...
@@ -52,15 +58,15 @@ export class ToastMessengerService {
* after some time. This method will not add a message that is already
* extant in the store's collection of toast messages (i.e. has the same
* `type` and `message` text of an existing message).
*
* @param {('error'|'success'|'notice')} type
* @param {string} messageText - The message to be rendered
* @param {MessageOptions} options
*/
_addMessage
(
type
,
messageText
,
{
autoDismiss
=
true
,
moreInfoURL
=
''
,
visuallyHidden
=
false
}
=
{}
private
_addMessage
(
type
:
'error'
|
'success'
|
'notice'
,
messageText
:
string
,
{
autoDismiss
=
true
,
moreInfoURL
=
''
,
visuallyHidden
=
false
,
}:
MessageOptions
=
{}
)
{
// Do not add duplicate messages (messages with the same type and text)
if
(
this
.
_store
.
hasToastMessage
(
type
,
messageText
))
{
...
...
@@ -93,31 +99,22 @@ export class ToastMessengerService {
/**
* Add an error toast message with `messageText`
*
* @param {string} messageText
* @param {MessageOptions} [options]
*/
error
(
messageText
,
o
ptions
)
{
error
(
messageText
:
string
,
options
?:
MessageO
ptions
)
{
this
.
_addMessage
(
'error'
,
messageText
,
options
);
}
/**
* Add a success toast message with `messageText`
*
* @param {string} messageText
* @param {MessageOptions} [options]
*/
success
(
messageText
,
o
ptions
)
{
success
(
messageText
:
string
,
options
?:
MessageO
ptions
)
{
this
.
_addMessage
(
'success'
,
messageText
,
options
);
}
/**
* Add a warn/notice toast message with `messageText`
*
* @param {string} messageText
* @param {MessageOptions} [options]
*/
notice
(
messageText
,
o
ptions
)
{
notice
(
messageText
:
string
,
options
?:
MessageO
ptions
)
{
this
.
_addMessage
(
'notice'
,
messageText
,
options
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment