-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use AJAX for notifications table #10961
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10961 +/- ##
==========================================
- Coverage 43.34% 43.33% -0.01%
==========================================
Files 601 601
Lines 85675 85694 +19
==========================================
+ Hits 37133 37139 +6
- Misses 43956 43969 +13
Partials 4586 4586
Continue to review full report at Codecov.
|
Did not worked at all :/ |
@6543 what browser are you using? Are you sure that you cleaned out your service worker? |
Crome and Firefox; and yes |
@6543 I'm confused because it genuinely works here. Are you able to just double check that the index.js contains |
@6543 is service worker caching the old JS for you? |
sorry for the late responce I'll thest this again ... EDIT: no I'm sure it doesnt work :( |
update fix: e1d913c5b76cf20ab88a5f0b1ad3e5d799826c0c worked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make ajax first - ged rid of page.reload() after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$notificationTable
will be never null
Signed-off-by: Andrew Thornton <art27@cantab.net>
5ef3dd9
to
2d23ad7
Compare
Signed-off-by: Andrew Thornton <art27@cantab.net>
I'll have a look at this later :) |
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the class for hiding is actually hidden
Alternatively there is invisible
if you only want to make them invisible.
Sorry, I looked into the CSS classes a little more. |
Only run checker on pages that have a count Change starting checker to 10s with a back-off to 60s if there is no change Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realy like this pull 👍
Signed-off-by: Andrew Thornton <art27@cantab.net>
thanks 👍 ... one thing 😅 a config option need it's documentation :D |
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
I would say kind/feature ? |
this pull close #10198 |
Some suggestions: diff --git a/.eslintrc b/.eslintrc
index 8fd53d54a..a8f7f1ae2 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -54,8 +54,9 @@ rules:
no-new: [0]
no-param-reassign: [0]
no-plusplus: [0]
no-restricted-syntax: [0]
+ no-return-await: [0]
no-shadow: [0]
no-unused-vars: [2, {args: all, argsIgnorePattern: ^_, varsIgnorePattern: ^_, ignoreRestSiblings: true}]
no-use-before-define: [0]
no-var: [2]
diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js
index 37369df2e..f2bde28a0 100644
--- a/web_src/js/features/notification.js
+++ b/web_src/js/features/notification.js
@@ -1,19 +1,19 @@
const {AppSubUrl, csrf, NotificationSettings} = window.config;
export function initNotificationsTable() {
- $('#notification_table .button').click(function () {
- updateNotification(
+ $('#notification_table .button').on('click', async function () {
+ const data = await updateNotification(
$(this).data('url'),
$(this).data('status'),
$(this).data('page'),
$(this).data('q'),
$(this).data('notification-id')
- ).then((data) => {
- $('#notification_div').replaceWith(data);
- initNotificationsTable();
- updateNotificationCount();
- });
+ );
+
+ $('#notification_div').replaceWith(data);
+ initNotificationsTable();
+ await updateNotificationCount();
return false;
});
}
@@ -24,63 +24,61 @@ export function initNotificationCount() {
if ($('.notification_count').length > 0) {
const lastCount = $('.notification_count').text();
const fn = (callback, timeout, lastCount) => {
- setTimeout(() => {
- updateNotificationCount(callback, timeout, lastCount);
+ setTimeout(async () => {
+ await updateNotificationCount(callback, timeout, lastCount);
}, timeout);
};
fn(fn, NotificationSettings.MinTimeout, lastCount);
}
}
-function updateNotificationCount(callback, timeout, lastCount) {
- const currentCount = $('.notification_count').text();
+async function updateNotificationCount(callback, timeout, lastCount) {
+ let currentCount = $('.notification_count').text();
if (callback && (lastCount !== currentCount)) {
callback(callback, NotificationSettings.MinTimeout, currentCount);
return;
}
- $.ajax({
+
+ const data = await $.ajax({
type: 'GET',
url: `${AppSubUrl}/api/v1/notifications/new`,
headers: {
'X-Csrf-Token': csrf,
},
- }).then((data) => {
- const notificationCount = $('.notification_count');
- const notificationDependent = $('.notification_dependent');
- if (data.new === 0) {
- notificationCount.addClass('hidden');
- notificationDependent.addClass('hide');
- } else {
- notificationCount.removeClass('hidden');
- notificationDependent.removeClass('hide');
- }
- const currentCount = $('.notification_count').text();
- if (lastCount !== `${data.new}` || currentCount !== `${data.new}`) {
- notificationCount.text(data.new);
- timeout = NotificationSettings.MinTimeout;
- } else if (timeout < NotificationSettings.MaxTimeout) {
- timeout += NotificationSettings.TimeoutStep;
- }
- return {
- timeout,
- nextCount: `${data.new}`,
- };
- }).then((data) => {
- if (callback) {
- callback(callback, data.timeout, data.nextCount);
- }
});
+
+ const notificationCount = $('.notification_count');
+ const notificationDependent = $('.notification_dependent');
+ if (data.new === 0) {
+ notificationCount.addClass('hidden');
+ notificationDependent.addClass('hide');
+ } else {
+ notificationCount.removeClass('hidden');
+ notificationDependent.removeClass('hide');
+ }
+
+ currentCount = $('.notification_count').text();
+ if (lastCount !== `${data.new}` || currentCount !== `${data.new}`) {
+ notificationCount.text(data.new);
+ timeout = NotificationSettings.MinTimeout;
+ } else if (timeout < NotificationSettings.MaxTimeout) {
+ timeout += NotificationSettings.TimeoutStep;
+ }
+
+ if (callback) {
+ callback(callback, timeout, `${data.new}`);
+ }
}
async function updateNotification(url, status, page, q, notificationID) {
if (status !== 'pinned') {
$(`#notification_${notificationID}`).remove();
}
- return $.ajax({
+ return await $.ajax({
type: 'POST',
url,
data: {
_csrf: csrf, |
Fix @Etzelia update notification table request Fix @silverwind comments Co-Authored-By: silverwind <me@silverwind.io> Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Use AJAX for notifications table Signed-off-by: Andrew Thornton <art27@cantab.net> * move to separate js Signed-off-by: Andrew Thornton <art27@cantab.net> * placate golangci-lint Signed-off-by: Andrew Thornton <art27@cantab.net> * Add autoupdating notification count Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix wipeall Signed-off-by: Andrew Thornton <art27@cantab.net> * placate tests Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hide and hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * More auto-update improvements Only run checker on pages that have a count Change starting checker to 10s with a back-off to 60s if there is no change Signed-off-by: Andrew Thornton <art27@cantab.net> * string comparison! Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * add configurability as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add documentation as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Use CSRF header not query Signed-off-by: Andrew Thornton <art27@cantab.net> * Further JS improvements Fix @Etzelia update notification table request Fix @silverwind comments Co-Authored-By: silverwind <me@silverwind.io> Signed-off-by: Andrew Thornton <art27@cantab.net> * Simplify the notification count fns Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io>
Use AJAX to update the notifications count and table.
Delay calculating notification count until rendering to prevent initial incorrect display of notification count.
Signed-off-by: Andrew Thornton art27@cantab.net