Skip to content

Commit

Permalink
Merge branch 'trunk' into add/reorderable-status-react
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgeatches authored Jul 9, 2024
2 parents 0917f89 + d05242a commit 412ea47
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2,324 deletions.
58 changes: 29 additions & 29 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ module.exports = {
jest: true,
},
rules: {
"no-prototype-builtins": 0,
"no-eval": 0,
"complexity": 0,
"camelcase": 0,
"no-undef": 0,
"wpcalypso/import-docblock": 0,
"valid-jsdoc": 0,
"react/prop-types": 0,
"react/react-in-jsx-scope": 0,
"react-hooks/rules-of-hooks": 0,
"no-redeclare": 0,
"no-shadow": 0,
"no-nested-ternary": 0,
"no-var": 0,
"no-unused-vars": 0,
"no-useless-escape": 0,
"prefer-const": 0,
"no-global-assign": 0,
"no-constant-binary-expression": 0,
"valid-typeof": 0,
"eqeqeq": 0,
"radix": 0,
"no-eq-null": 0,
"array-callback-return": 0,
"no-unused-expressions": 0,
"no-alert": 0,
"no-lonely-if": 0,
'no-prototype-builtins': 0,
'no-eval': 0,
complexity: 0,
camelcase: 0,
'no-undef': 0,
'wpcalypso/import-docblock': 0,
'valid-jsdoc': 0,
'react/prop-types': 0,
'react/react-in-jsx-scope': 0,
'react-hooks/rules-of-hooks': 0,
'no-redeclare': 0,
'no-shadow': 0,
'no-nested-ternary': 0,
'no-var': 0,
'no-unused-vars': 0,
'no-useless-escape': 0,
'prefer-const': 0,
'no-global-assign': 0,
'no-constant-binary-expression': 0,
'valid-typeof': 0,
eqeqeq: 0,
radix: 0,
'no-eq-null': 0,
'array-callback-return': 0,
'no-unused-expressions': 0,
'no-alert': 0,
'no-lonely-if': 0,
},
"parser": "@babel/eslint-parser",
"parser": "@babel/eslint-parser",
"parserOptions": {
"babelOptions": {
"presets": ["@babel/preset-react"]
},
}
},
};
91 changes: 1 addition & 90 deletions modules/notifications/lib/notifications.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,5 @@
jQuery( document ).ready( function ( $ ) {
$( '#vw-post_following_users_box ul' ).listFilterizer();

const params = {
action: 'save_notifications',
post_id: $( '#post_ID' ).val(),
};

const toggle_warning_badges = function ( container, response ) {
// Remove any existing badges
if ( $( container ).siblings( 'span' ).length ) {
$( container ).siblings( 'span' ).remove();
}

// "No Access" If this user was flagged as not having access
const user_has_no_access = response.data.subscribers_with_no_access.includes(
parseInt( $( container ).val() )
);
if ( user_has_no_access ) {
var span = $( '<span />' ).addClass( 'post_following_list-no_access' );
span.text( vw_notifications_localization.no_access );
$( container ).parent().prepend( span );
warning_background = true;
}
// "No Email" If this user was flagged as not having an email
const user_has_no_email = response.data.subscribers_with_no_email.includes(
parseInt( $( container ).val() )
);
if ( user_has_no_email ) {
var span = $( '<span />' ).addClass( 'post_following_list-no_email' );
span.text( vw_notifications_localization.no_email );
$( container ).parent().prepend( span );
warning_background = true;
}
};

$( document ).on(
'click',
'.vw-post_following_list li input:checkbox, .vw-following_usergroups li input:checkbox',
function () {
const user_group_ids = [];
const parent_this = $( this );
params.vw_notifications_name = $( this ).attr( 'name' );
params._nonce = $( '#vw_notifications_nonce' ).val();

$( this )
.parents( '.vw-post_following_list' )
.find( 'input:checked' )
.map( function () {
user_group_ids.push( $( this ).val() );
} );

params.user_group_ids = user_group_ids;

$.ajax( {
type: 'POST',
url: ajaxurl ? ajaxurl : wpListL10n.url,
data: params,

success( response ) {
// Reset background color (set during toggle_warning_badges if there's a warning)
warning_background = false;

// Toggle the warning badges ("No Access" and "No Email") to signal the user won't receive notifications
if ( undefined !== response.data ) {
toggle_warning_badges( $( parent_this ), response );
}
// Green 40% by default
var backgroundHighlightColor = '#90d296';
if ( warning_background ) {
// Red 40% if there's a warning
var backgroundHighlightColor = '#ea8484';
}
const backgroundColor = parent_this.css( 'background-color' );
$( parent_this.parents( 'li' ) )
.animate( { backgroundColor: backgroundHighlightColor }, 200 )
.animate( { backgroundColor }, 200 );

// This event is used to show an updated list of who will be notified of status updates.
$( '#vw-post_following_box' ).trigger( 'following_list_updated' );
},
error( r ) {
$( '#vw-post_following_users_box' )
.prev()
.append( ' <p class="error">There was an error. Please reload the page.</p>' );
},
} );
}
);

// TODO: Should change this to _not_ use JQuery
// ToDo: Switch this to be react based once the custom status module's settings are converted to react.
const webhookUrl = $( 'input#webhook_url' ).closest( 'tr' );
const sendToWebhook = $( 'select#send_to_webhook' );
if ( sendToWebhook.val() === 'off' ) {
Expand Down
Loading

0 comments on commit 412ea47

Please sign in to comment.