buddypress / next-template-packs

is this the next BuddyPress template pack?
35 stars 9 forks source link

Showing active filters on the activity stream. #1

Open BoweFrankema opened 8 years ago

BoweFrankema commented 8 years ago

One thing that I've always found confusing and problematic (especially for novice users) is the applying of filters to the activity stream. It is VERY easy to overlook that you have a certain filter applied and since the last filter is saved as a cookie this could easily lead to users missing important updates. For my WeFoster theme I've fixed this by adding a little bit of jQuery. The result is a little message that shows when a filter is currently active:

screenshot 2016-04-10 17 04 15

This was achieved by using one hook:

    /**
     * Show a message when an activity stream filter is active
     *
     * @since 1.0.0
     */
    if ( ! function_exists( 'wff_activity_filter_warning' ) ) {
        function wff_activity_filter_warning() {
            ?>
            <div id="activity-filter-notice">
                <i class="fa fa-lightbulb-o"></i> <?php _e( 'You are filtering your newsfeed to only see <span></span>. <a href="#" id="reset">Click here to reset</a>', 'wefoster' ); ?>
            </div>
            <?php
        }

        add_action( 'bp_after_activity_post_form', 'wff_activity_filter_warning' );
    }

And the following JS

    //See if a user has a filter enabled
    $('#activity-filter-by,#activity-filter-select').on('change', function() {
      if (this.value === '-1' || this.value === 0) {
        // Everything is selected
        $("#activity-filter-notice").removeClass('visible').hide();
      } else {
        // Filter is on
        $("#activity-filter-notice").addClass('visible');
        var text = $("#activity-filter-by option[value='" + $(this).val() + "']").html();
        $("#activity-filter-notice span").html(text);
      }
    }).trigger('change');

I'm sure it can be improved but it really helps!

imath commented 8 years ago

I agree :)