mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: do not refresh page on problem star
This commit is contained in:
1 parent
e3e89ca43f
commit
2f9a8b70bd
1 file changed
+3
-2
@@ -0,0 +1,35 @@
|
||||
import $ from 'jquery';
|
||||
import { AutoloadPage } from 'vj/misc/Page';
|
||||
import { request } from 'vj/utils';
|
||||
|
||||
function setStarButtonState($starButton: JQuery<any>, star: boolean) {
|
||||
if (star) {
|
||||
$starButton.addClass('activated');
|
||||
} else {
|
||||
$starButton.removeClass('activated');
|
||||
}
|
||||
}
|
||||
|
||||
const starPage = new AutoloadPage('starPage', () => {
|
||||
$(document).on('click', '.star', (ev) => {
|
||||
ev.preventDefault();
|
||||
const $button = $(ev.currentTarget);
|
||||
const currentState = $button.hasClass('activated');
|
||||
const $form = $button.closest('form');
|
||||
const $op = $form.find('[name="operation"]');
|
||||
if (!['star', 'unstar'].includes($op.val() as any)) return;
|
||||
$op.val(currentState ? 'unstar' : 'star');
|
||||
setStarButtonState($button, !currentState);
|
||||
request
|
||||
.post($form.attr('action'), $form)
|
||||
.then((data) => {
|
||||
setStarButtonState($button, data.star);
|
||||
})
|
||||
.catch(() => {
|
||||
// TODO: notify failure
|
||||
setStarButtonState($button, currentState);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
export default starPage;
|
||||
Reference in new issue
Block a user