perf(modal): unify cancellable frontend modal flows

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-05 02:04:55 +08:00
co-authored by Claude Fable 5
parent 25ce1d8f43
commit 5375ad6429
36 changed files with 2623 additions and 1806 deletions
+1 -37
View File
@@ -164,7 +164,7 @@ class Home {
if (!empty($settings['badge']['enabled']) && !empty($settings['badge']['public_display'])) {
$limit = max(1, (int) ($settings['badge']['limit'] ?? 3));
if (class_exists('AKSRT\\User\\Badges')) {
$list = Badges::list_for_user($user_id, true);
$list = Badges::list_for_user($user_id);
$badge_count = 0;
$done = false;
foreach ((array) ($list['categories'] ?? []) as $cat) {
@@ -191,42 +191,6 @@ class Home {
break;
}
}
} else {
$badge_map = [];
foreach ((array) ($settings['badge']['dictionary'] ?? []) as $item) {
if (!empty($item['slug'])) {
$badge_map[(string) $item['slug']] = $item;
}
}
$assigned = get_user_meta($user_id, 'aksrt_user_badges', true);
// Storage shape: associative map slug => grant time.
$assigned = is_array($assigned) ? array_keys($assigned) : [];
$wear = sanitize_key((string) get_user_meta($user_id, 'aksrt_wear_badge', true));
$assigned = array_values(array_filter(array_map(static function ($slug) {
return sanitize_key((string) $slug);
}, (array) $assigned)));
if ($wear !== '' && in_array($wear, $assigned, true) && isset($badge_map[$wear])) {
$assigned = array_values(array_unique(array_merge([$wear], $assigned)));
}
$badge_count = 0;
foreach ($assigned as $slug) {
if ($slug === '' || !isset($badge_map[$slug])) {
continue;
}
$signals[] = [
'type' => 'badge',
'slug' => $slug,
'label' => (string) $badge_map[$slug]['label'],
'icon' => 'award',
'tone' => (string) ($badge_map[$slug]['tone'] ?? 'neutral'),
'icon_url' => (string) ($badge_map[$slug]['icon_url'] ?? ''),
'wear' => ($wear !== '' && $slug === $wear),
];
$badge_count++;
if ($badge_count >= $limit) {
break;
}
}
}
}