Skip to content

Commit

Permalink
Allow hiding completed badges
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jul 4, 2024
1 parent e7bdc02 commit a268bbe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ button.prpl-info-icon {
/*------------------------------------*\
Dashboard widget styles.
\*------------------------------------*/
#progress_planner_dashboard_widget_score .prpl-dashboard-widget {
#progress_planner_dashboard_widget_score .prpl-dashboard-widget.show-badges {
display: grid;
grid-template-columns: 1fr 1px 140px;
grid-gap: calc(var(--prpl-gap) / 2);
Expand Down
38 changes: 29 additions & 9 deletions classes/admin/class-dashboard-widget-score.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@ protected function get_title() {
*/
public function render_widget() {
Page::enqueue_styles();

$show_badges = (
$this->get_badge_details( 'content' )['progress']['progress'] ||
$this->get_badge_details( 'streak' )['progress']['progress']
);
?>
<div class="prpl-dashboard-widget">
<div class="prpl-dashboard-widget<?php echo ( $show_badges ) ? ' show-badges' : ''; ?>">
<div class="prpl-score-gauge">
<?php \Progress_Planner\Widgets\Website_Activity_Score::print_score_gauge( '#ffffff', '<p>' . \esc_html__( 'Website activity score', 'progress-planner' ) . '</p>' ); ?>
</div>

<div class="grid-separator"></div>

<div class="prpl-badges">
<h3><?php \esc_html_e( 'Next badges', 'progress-planner' ); ?></h3>
<?php $this->the_badge( 'content' ); ?>
<?php $this->the_badge( 'streak' ); ?>
</div>
<?php if ( $show_badges ) : ?>
<div class="grid-separator"></div>
<div class="prpl-badges">
<h3><?php \esc_html_e( 'Next badges', 'progress-planner' ); ?></h3>
<?php $this->the_badge( 'content' ); ?>
<?php $this->the_badge( 'streak' ); ?>
</div>
<?php endif; ?>
</div>

<div class="prpl-dashboard-widget-latest-activities">
Expand Down Expand Up @@ -121,6 +126,9 @@ public function render_widget() {
*/
protected function the_badge( $category = 'content' ) {
$details = $this->get_badge_details( $category );
if ( 100 <= (int) $details['progress']['progress'] ) {
return;
}
?>
<div class="prpl-badges-columns-wrapper">
<div class="prpl-badge-wrapper">
Expand Down Expand Up @@ -152,6 +160,15 @@ class="prpl-badge-gauge"
* @return array
*/
public function get_badge_details( $category = 'content' ) {
$cached = [
'content' => false,
'streak' => false,
];

if ( $cached[ $category ] ) {

Check failure on line 168 in classes/admin/class-dashboard-widget-score.php

View workflow job for this annotation

GitHub Actions / Static Analysis

If condition is always false.
return $cached[ $category ];
}

$result = [];
$badges = [
'content' => [ 'wonderful-writer', 'bold-blogger', 'awesome-author' ],
Expand All @@ -175,6 +192,9 @@ public function get_badge_details( $category = 'content' ) {
if ( $result['progress']['progress'] > 75 ) {
$result['color'] = 'var(--prpl-color-accent-green)';
}

$cached[ $category ] = $result;

return $result;
}
}

0 comments on commit a268bbe

Please sign in to comment.