Skip to content

Commit 9d1ffa9

Browse files
committed
Fixed handling of class names
1 parent 5222490 commit 9d1ffa9

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

widget/src/_standalone/tidy_feedback/index.svelte

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
return {};
2020
})();
2121
22+
const MESSAGE_TYPE_INFO = 'info';
23+
const MESSAGE_TYPE_DANGER = 'danger';
24+
const MESSAGE_TYPE_ERROR = 'error';
25+
const MESSAGE_TYPE_SUCCESS = 'success';
26+
2227
let formContainer;
2328
let region;
2429
let formHidden = $state(true);
@@ -27,12 +32,12 @@
2732
2833
let messageTimeout = null;
2934
let message = $state('');
30-
let messageType = $state('info');
35+
let messageType = $state(MESSAGE_TYPE_INFO);
3136
const messageHideDelay = config.messageHideDelay ?? 0;
3237
3338
const t = (text) => config.messages?.[text] ?? text + ' (missing translation)';
3439
35-
const showMessage = (msg, type = 'info') => {
40+
const showMessage = (msg, type = MESSAGE_TYPE_INFO) => {
3641
if (messageTimeout) {
3742
clearTimeout(messageTimeout);
3843
}
@@ -75,7 +80,6 @@
7580
7681
const submitForm = async (target) => {
7782
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement#instance_methods
78-
// @todo This does not actually validate the form elements!
7983
const isValid = form.reportValidity();
8084
if (isValid) {
8185
const data = {};
@@ -97,7 +101,7 @@
97101
data.image = image;
98102
} catch (error) {
99103
console.error(error);
100-
showMessage('Error taking screenshot', 'danger');
104+
showMessage('Error taking screenshot', MESSAGE_TYPE_DANGER);
101105
}
102106
103107
const formData = new FormData(form);
@@ -136,17 +140,19 @@
136140
.then((response) => {
137141
if (201 === response.status) {
138142
hideForm(true);
139-
showMessage(t('Feedback created'), 'success');
143+
showMessage(t('Feedback created'), MESSAGE_TYPE_SUCCESS);
140144
} else {
141145
response
142146
.json()
143147
.then((data) =>
144-
showMessage('Error creating feedback: ' + JSON.stringify(data), 'danger')
148+
showMessage('Error creating feedback: ' + JSON.stringify(data), MESSAGE_TYPE_DANGER)
145149
)
146-
.catch((error) => showMessage('Error creating feedback: ' + error, 'danger'));
150+
.catch((error) =>
151+
showMessage('Error creating feedback: ' + error, MESSAGE_TYPE_DANGER)
152+
);
147153
}
148154
})
149-
.catch((reason) => showMessage(reason, 'error'));
155+
.catch((reason) => showMessage(reason, MESSAGE_TYPE_ERROR));
150156
}
151157
};
152158
@@ -192,11 +198,21 @@
192198

193199
<div data-capture="exclude">
194200
{#if message}
195-
<div class="tidy-feedback-message-wrapper container position-fixed top">
201+
<div class="tidy-feedback-message-wrapper container position-fixed top-0">
196202
<row class="row">
197203
<div class="col-md-6 offset-md-3 mt-3">
198204
<div
199-
class="tidy-feedback-message alert alert-{messageType} alert-dismissible"
205+
class={[
206+
'tidy-feedback-message',
207+
'alert',
208+
'alert-dismissible',
209+
{
210+
'alert-info': MESSAGE_TYPE_INFO === messageType,
211+
'alert-danger': MESSAGE_TYPE_DANGER === messageType,
212+
'alert-error': MESSAGE_TYPE_ERROR === messageType,
213+
'alert-sucess': MESSAGE_TYPE_SUCCESS === messageType
214+
}
215+
]}
200216
role="alert"
201217
>
202218
{message}

0 commit comments

Comments
 (0)