Skip to content

Conversation

@zeripath
Copy link
Contributor

@zeripath zeripath commented Apr 4, 2020

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 [email protected]

@zeripath zeripath added the topic/ui Change the appearance of the Gitea UI label Apr 4, 2020
@zeripath zeripath added this to the 1.12.0 milestone Apr 4, 2020
@codecov-io
Copy link

codecov-io commented Apr 4, 2020

Codecov Report

Merging #10961 into master will decrease coverage by 0.00%.
The diff coverage is 40.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
modules/setting/setting.go 45.28% <ø> (ø)
routers/user/notification.go 39.70% <25.00%> (-5.46%) ⬇️
modules/templates/helper.go 43.03% <100.00%> (+0.84%) ⬆️
services/pull/update.go 52.54% <0.00%> (-6.78%) ⬇️
services/pull/temp_repo.go 31.62% <0.00%> (-2.57%) ⬇️
services/pull/pull.go 33.20% <0.00%> (-0.20%) ⬇️
modules/git/repo.go 51.88% <0.00%> (+3.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e74c4e1...edc068d. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 4, 2020
@6543
Copy link
Member

6543 commented Apr 5, 2020

Did not worked at all :/
-> only open related issue works
if you klick on pin/read/unread it also open the related issue/pull

@zeripath
Copy link
Contributor Author

zeripath commented Apr 5, 2020

@6543 what browser are you using? Are you sure that you cleaned out your service worker?

@6543
Copy link
Member

6543 commented Apr 5, 2020

@6543 what browser are you using? Are you sure that you cleaned out your service worker?

Crome and Firefox; and yes

@zeripath
Copy link
Contributor Author

zeripath commented Apr 5, 2020

@6543 I'm confused because it genuinely works here. Are you able to just double check that the index.js contains #notification_table?

@techknowlogick
Copy link
Member

@6543 is service worker caching the old JS for you?

@6543
Copy link
Member

6543 commented Apr 5, 2020

sorry for the late responce I'll thest this again ... EDIT: no I'm sure it doesnt work :(

@6543
Copy link
Member

6543 commented Apr 5, 2020

update fix: e1d913c5b76cf20ab88a5f0b1ad3e5d799826c0c worked
and 5ef3dd983946e54748c975d04a03a6b35deb0581 do the job 👍

Copy link
Member

@6543 6543 left a 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

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 5, 2020
@zeripath zeripath added the pr/wip This PR is not ready for review label Apr 5, 2020
@zeripath zeripath changed the title do ajax calls for notification pinning/mark-read WIP: do ajax calls for notification pinning/mark-read Apr 5, 2020
Copy link
Contributor

@jaqra jaqra left a 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 <[email protected]>
@zeripath zeripath force-pushed the notifications-ajax branch from 5ef3dd9 to 2d23ad7 Compare April 21, 2020 17:11
@zeripath zeripath changed the title WIP: do ajax calls for notification pinning/mark-read Use AJAX for notifications table Apr 21, 2020
@zeripath zeripath removed the pr/wip This PR is not ready for review label Apr 21, 2020
Signed-off-by: Andrew Thornton <[email protected]>
@6543
Copy link
Member

6543 commented Apr 21, 2020

I'll have a look at this later :)

Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
@jolheiser
Copy link
Member

Is there supposed to be an ever-present label?
0

Also, perhaps they can be hidden on-click? I tend to open my notifications with middle-click (open in a new tab), which then means I end up with something like this.
1

Copy link
Member

@jolheiser jolheiser left a 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.

@jolheiser
Copy link
Member

Sorry, I looked into the CSS classes a little more. hide does work, however it's being overridden by .ui.label whereas .hidden uses !important 🙃

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 <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Copy link
Member

@6543 6543 left a 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 <[email protected]>
@6543
Copy link
Member

6543 commented Apr 22, 2020

thanks 👍 ... one thing 😅 a config option need it's documentation :D

Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 22, 2020
@6543
Copy link
Member

6543 commented Apr 22, 2020

I would say kind/feature ?

@6543
Copy link
Member

6543 commented Apr 22, 2020

this pull close #10198

@silverwind
Copy link
Member

silverwind commented Apr 23, 2020

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,

zeripath and others added 2 commits April 23, 2020 15:19
Fix @Etzelia update notification table request
Fix @silverwind comments

Co-Authored-By: silverwind <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
@guillep2k guillep2k merged commit b10c416 into go-gitea:master Apr 24, 2020
@zeripath zeripath deleted the notifications-ajax branch April 24, 2020 11:55
@jamesorlakin jamesorlakin mentioned this pull request Jun 25, 2020
11 tasks
ydelafollye pushed a commit to ydelafollye/gitea that referenced this pull request Jul 31, 2020
* Use AJAX for notifications table

Signed-off-by: Andrew Thornton <[email protected]>

* move to separate js

Signed-off-by: Andrew Thornton <[email protected]>

* placate golangci-lint

Signed-off-by: Andrew Thornton <[email protected]>

* Add autoupdating notification count

Signed-off-by: Andrew Thornton <[email protected]>

* Fix wipeall

Signed-off-by: Andrew Thornton <[email protected]>

* placate tests

Signed-off-by: Andrew Thornton <[email protected]>

* Try hidden

Signed-off-by: Andrew Thornton <[email protected]>

* Try hide and hidden

Signed-off-by: Andrew Thornton <[email protected]>

* 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 <[email protected]>

* string comparison!

Signed-off-by: Andrew Thornton <[email protected]>

* as per @silverwind

Signed-off-by: Andrew Thornton <[email protected]>

* add configurability as per @6543

Signed-off-by: Andrew Thornton <[email protected]>

* Add documentation as per @6543

Signed-off-by: Andrew Thornton <[email protected]>

* Use CSRF header not query

Signed-off-by: Andrew Thornton <[email protected]>

* Further JS improvements

Fix @Etzelia update notification table request
Fix @silverwind comments

Co-Authored-By: silverwind <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>

* Simplify the notification count fns

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: silverwind <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/ui Change the appearance of the Gitea UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants