Project

General

Profile

Bug #15877

Fix 'Follow' button behavior on new Sites directory

Added by Boone Gorges 3 months ago. Updated about 1 month ago.

Status:
Resolved
Priority name:
Normal
Assignee:
Category name:
Blogs (BuddyPress)
Target version:
Start date:
2022-04-08
Due date:
% Done:

0%

Estimated time:

Description

As part of the Sites directory redesign, I tried mimicking the Follow button as it currently appears on the Commons production site. See https://github.com/cuny-academic-commons/cac/blob/098681fbec154d02e58d0e5e6fb15c44001e5ce2/wp-content/themes/bp-nelo/functions.php#L1499=

But the button doesn't work. It seems like the buddypress-followers JS is broken in a couple ways:
a. It doesn't appear to have a listener for the blogs/sites directory
b. The way it identifies the nonce requires parsing the URL in a particular way - the ampersand has to appear in a certain way. This is a bit wonky.
c. I managed to work around a and b https://github.com/cuny-academic-commons/cac/blob/098681fbec154d02e58d0e5e6fb15c44001e5ce2/wp-content/themes/bp-nelo/assets/js/directory.js#L20= but I got a 400 error - like maybe the AJAX handler wasn't set up properly.

Ray, I didn't want to touch buddypress-followers itself, and I thought you might have a clearer idea what I'm doing wrong. Thanks in advance for your help!

ajax-follow-site.gif (62.2 KB) ajax-follow-site.gif Raymond Hoh, 2022-05-09 09:02 PM

History

#1 Updated by Raymond Hoh 3 months ago

On the Commons currently, we do not use AJAX for the follow sites button.

Most importantly, the follow AJAX and JS functionality is currently only coded for the members component and I believe we have disabled the follow members portion on the Commons, so the follow AJAX handlers would also not be registered causing the 400 error.

I can make some adjustments to allow AJAX to work for the follow sites button as well.

#2 Updated by Boone Gorges 3 months ago

Most importantly, the follow AJAX and JS functionality is currently only coded for the members component and I believe we have disabled the follow members portion on the Commons, so the follow AJAX handlers would also not be registered causing the 400 error.

This all explains why it didn't work :)

I don't think AJAX is absolutely necessary, but if we don't have AJAX (and I guess even if we do, as fallback) then the redirect behavior should be more logical. The Follow buttons I have in place currently work, but you end up on the home page.

Thanks for having a look!

#3 Updated by Raymond Hoh 2 months ago

I don't think AJAX is absolutely necessary, but if we don't have AJAX (and I guess even if we do, as fallback) then the redirect behavior should be more logical. The Follow buttons I have in place currently work, but you end up on the home page.

For now, I've opted to fix the Follow button on the Sites Directory page without AJAX support - https://github.com/cuny-academic-commons/cac/commit/7f13480c8ee57616eee0a68953a5cb28b4755e9b.

Refactoring BP Follow's JS to add in Sites support would require quite a few changes since the nonces to validate the AJAX action are different for the components. It would probably be easier to write a custom AJAX follow sites handler specifically for bp-nelo. More to come.

#4 Updated by Raymond Hoh about 2 months ago

I've added AJAX functionality for the Follow button on the Sites Directory, as well as on your profile's "Sites" pages: https://github.com/cuny-academic-commons/cac/compare/6e0b084...48dc398da8

I opted to add a separate JS and AJAX handler for following sites. Main changes to buddypress-followers here: https://github.com/r-a-y/buddypress-followers/compare/6baa72b...7f5c01c.

This is available for testing on cdev. I've attached a GIF for those that cannot access cdev.

#5 Updated by Boone Gorges about 2 months ago

Nice! I've tested and this works well for me.

#6 Updated by Boone Gorges about 1 month ago

  • Status changed from Staged for Production Release to Resolved

Also available in: Atom PDF