Skip to content

Commit 583ee42

Browse files
committed
add presets for notifications about go toolchain releases, and fadeout current page while loading next or when making api calls
1 parent 8b621fa commit 583ee42

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

index.html

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
.signupoptions { display: flex; gap: 4em; max-width: none; }
3434
.signupoptions > * { max-width: 50em; }
3535
}
36+
.loading { opacity: 0.1; animation: fadeout 1s ease-out; }
37+
@keyframes fadein { 0% { opacity: 0 } 100% { opacity: 1 } }
38+
@keyframes fadeout { 0% { opacity: 1 } 100% { opacity: 0.1 } }
3639
</style>
3740
</head>
3841
<body>

index.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ const zindexes = {
872872
};
873873
const check = async (elem, fn) => {
874874
elem.disabled = true;
875+
document.body.classList.toggle('loading', true);
875876
try {
876877
return await fn();
877878
}
@@ -881,6 +882,7 @@ const check = async (elem, fn) => {
881882
throw err;
882883
}
883884
finally {
885+
document.body.classList.toggle('loading', false);
884886
elem.disabled = false;
885887
}
886888
};
@@ -1041,21 +1043,26 @@ const subscriptionPopup = (sub, subscriptions, hookconfigs, render) => {
10411043
render();
10421044
close();
10431045
});
1044-
}, fieldset = dom.fieldset(modulegomod = dom.div(dom.label(style({ display: 'flex', justifyContent: 'space-between' }), dom.div('Module '), sub.ID ? [] : [
1045-
dom.a(attr.href('#'), style({ fontSize: '.9em' }), 'Subscribe to dependencies of a go.mod file', function click(e) {
1046-
e.preventDefault();
1047-
dom._kids(modulegomod, dom.label('Contents of go.mod', gomod = dom.textarea(attr.required(''), attr.rows('12'))), dom.div(dom._class('explain'), 'Paste the contents of your go.mod. Subscriptions will be created for all direct dependencies.'), dom.label(indirect = dom.input(attr.type('checkbox')), ' Also subscribe to indirect dependencies'), dom.br());
1048-
dom._kids(submitbtn, 'Add subscriptions for dependencies');
1049-
}),
1050-
]), dom.div(module = dom.input(attr.required(''), attr.value(sub.Module), function change() {
1046+
}, fieldset = dom.fieldset(modulegomod = dom.div(sub.ID ? [] : dom.div(style({ textAlign: 'right' }), dom.a(attr.href('#'), style({ fontSize: '.9em' }), 'Subscribe to dependencies of a go.mod file', function click(e) {
1047+
e.preventDefault();
1048+
dom._kids(modulegomod, dom.label('Contents of go.mod', gomod = dom.textarea(attr.required(''), attr.rows('12'))), dom.div(dom._class('explain'), 'Paste the contents of your go.mod. Subscriptions will be created for all direct dependencies.'), dom.label(indirect = dom.input(attr.type('checkbox')), ' Also subscribe to indirect dependencies'), dom.br());
1049+
dom._kids(submitbtn, 'Add subscriptions for dependencies');
1050+
})), dom.label(style({ display: 'flex', justifyContent: 'space-between' }), dom.div('Module '), dom.a(attr.href('#'), style({ fontSize: '.9em' }), 'Presets for new Go toolchains', attr.title('Presets to get a notification when a new Go toolchain is released.'), function click(e) {
1051+
e.preventDefault();
1052+
module.value = 'golang.org/toolchain';
1053+
belowModule.checked = false;
1054+
olderVersions.checked = true;
1055+
prerelease.checked = true;
1056+
pseudo.checked = false;
1057+
})), dom.div(module = dom.input(attr.required(''), attr.value(sub.Module), function change() {
10511058
// User may input a URL, better fix it for them instead of making the user fix it.
10521059
module.value = module.value.replace(/^https?:\/\//, '');
10531060
module.value = module.value.replace(/\/*$/, '');
10541061
}), dom.div(dom._class('explain'), 'Enter a single module as you would use in a Go import statement.', dom.br(), 'Example: github.com/mjl-/gopherwatch, github.com/mjl- or golang.org.'))), dom.br(), dom.b('Notify about ...'), dom.label(belowModule = dom.input(attr.type('checkbox'), sub.BelowModule ? attr.checked('') : []), ' ', dom.span('Sub modules', attr.title('E.g. if subscribed to github.com/mjl-, whether to match github.com/mjl-/gopherwatch.'))), dom.label(olderVersions = dom.input(attr.type('checkbox'), sub.OlderVersions ? attr.checked('') : []), ' ', dom.span('Older versions than already seen', attr.title('Can happen when an old version (tag) is requested through the Go module proxy after a later tag, not uncommon after forking a repository and pushing all historic tags.'))), dom.label(prerelease = dom.input(attr.type('checkbox'), sub.Prerelease ? attr.checked('') : []), ' Prereleases such as v1.2.3-beta1'), dom.label(pseudo = dom.input(attr.type('checkbox'), sub.Pseudo ? attr.checked('') : [], function change() {
10551062
if (pseudo.checked) {
10561063
prerelease.checked = true;
10571064
}
1058-
}), ' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'), attr.title('Pseudo versions are always prereleases. In order to match a pseudoversion, prerelease must also be checked.'), dom.br(), dom.label('Comment',
1065+
}), ' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'), attr.title('Pseudo versions are also prereleases. In order to match a pseudoversion, prerelease must also be checked.'), dom.br(), dom.label('Comment',
10591066
// explicit String to prevent special scriptswitch handling
10601067
comment = dom.textarea(new String(sub.Comment))), dom.br(), dom.label('Delivery method', dom.div(webhookconfig = dom.select(dom.option('Email', attr.value('0')), hookconfigs.map(hc => dom.option('Webhook ' + hc.Name, attr.value('' + hc.ID), sub.HookConfigID === hc.ID ? attr.selected('') : []))))), dom.br(), dom.div(submitbtn = dom.submitbutton(sub.ID ? 'Save subscription' : 'Add subscription')))));
10611068
module.focus();
@@ -1429,11 +1436,15 @@ const route0 = async () => {
14291436
};
14301437
const route = async () => {
14311438
try {
1439+
document.body.classList.toggle('loading', true);
14321440
await route0();
14331441
}
14341442
catch (err) {
14351443
window.alert('Error loading page: ' + errmsg(err));
14361444
}
1445+
finally {
1446+
document.body.classList.toggle('loading', false);
1447+
}
14371448
};
14381449
const init = () => {
14391450
window.addEventListener('hashchange', route);

index.ts

+30-16
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const zindexes = {
77

88
const check = async <T>(elem: { disabled: boolean }, fn: () => Promise<T>): Promise<T> => {
99
elem.disabled = true
10+
document.body.classList.toggle('loading', true)
1011
try {
1112
return await fn()
1213
} catch (err) {
1314
console.log('error', err)
1415
window.alert('Error: ' + errmsg(err))
1516
throw err
1617
} finally {
18+
document.body.classList.toggle('loading', false)
1719
elem.disabled = false
1820
}
1921
}
@@ -263,24 +265,33 @@ const subscriptionPopup = (sub: api.Subscription, subscriptions: api.Subscriptio
263265
},
264266
fieldset=dom.fieldset(
265267
modulegomod=dom.div(
268+
sub.ID ? [] : dom.div(
269+
style({textAlign: 'right'}),
270+
dom.a(attr.href('#'), style({fontSize: '.9em'}), 'Subscribe to dependencies of a go.mod file', function click(e: MouseEvent) {
271+
e.preventDefault()
272+
dom._kids(modulegomod,
273+
dom.label(
274+
'Contents of go.mod',
275+
gomod=dom.textarea(attr.required(''), attr.rows('12')),
276+
),
277+
dom.div(dom._class('explain'), 'Paste the contents of your go.mod. Subscriptions will be created for all direct dependencies.'),
278+
dom.label(indirect=dom.input(attr.type('checkbox')), ' Also subscribe to indirect dependencies'),
279+
dom.br(),
280+
)
281+
dom._kids(submitbtn, 'Add subscriptions for dependencies')
282+
}),
283+
),
266284
dom.label(
267285
style({display: 'flex', justifyContent: 'space-between'}),
268286
dom.div('Module '),
269-
sub.ID ? [] : [
270-
dom.a(attr.href('#'), style({fontSize: '.9em'}), 'Subscribe to dependencies of a go.mod file', function click(e: MouseEvent) {
271-
e.preventDefault()
272-
dom._kids(modulegomod,
273-
dom.label(
274-
'Contents of go.mod',
275-
gomod=dom.textarea(attr.required(''), attr.rows('12')),
276-
),
277-
dom.div(dom._class('explain'), 'Paste the contents of your go.mod. Subscriptions will be created for all direct dependencies.'),
278-
dom.label(indirect=dom.input(attr.type('checkbox')), ' Also subscribe to indirect dependencies'),
279-
dom.br(),
280-
)
281-
dom._kids(submitbtn, 'Add subscriptions for dependencies')
282-
}),
283-
],
287+
dom.a(attr.href('#'), style({fontSize: '.9em'}), 'Presets for new Go toolchains', attr.title('Presets to get a notification when a new Go toolchain is released.'), function click(e: MouseEvent) {
288+
e.preventDefault()
289+
module.value = 'golang.org/toolchain'
290+
belowModule.checked = false
291+
olderVersions.checked = true
292+
prerelease.checked = true
293+
pseudo.checked = false
294+
}),
284295
),
285296
dom.div(
286297
module=dom.input(attr.required(''), attr.value(sub.Module), function change() {
@@ -307,7 +318,7 @@ const subscriptionPopup = (sub: api.Subscription, subscriptions: api.Subscriptio
307318
},
308319
),
309320
' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'),
310-
attr.title('Pseudo versions are always prereleases. In order to match a pseudoversion, prerelease must also be checked.'),
321+
attr.title('Pseudo versions are also prereleases. In order to match a pseudoversion, prerelease must also be checked.'),
311322
dom.br(),
312323
dom.label(
313324
'Comment',
@@ -1155,9 +1166,12 @@ const route0 = async () => {
11551166

11561167
const route = async () => {
11571168
try {
1169+
document.body.classList.toggle('loading', true)
11581170
await route0()
11591171
} catch (err) {
11601172
window.alert('Error loading page: ' + errmsg(err))
1173+
} finally {
1174+
document.body.classList.toggle('loading', false)
11611175
}
11621176
}
11631177

0 commit comments

Comments
 (0)