Files
UT-Registration-Plus/src/shared/util/updateBadgeText.ts
Sriram Hariharan a5e9e3c214 feat: update badge count when schedule changes (#150)
* feat: update badge count when schedule changes

* fix: fixed linting issues
2024-03-12 00:59:14 -05:00

35 lines
1.2 KiB
TypeScript

import { colors } from './themeColors';
import { MILLISECOND } from './time';
/** How long should we flash the badge when it changes value */
export const POPUP_FLASH_TIME = 200 * MILLISECOND;
/** The maximum number to show in the badge, after which we show a '+' */
export const BADGE_LIMIT = 10;
/**
* Updates the badge text based on the given value.
* If the value is greater than the badge limit, it sets the badge text to the badge limit followed by a '+'.
* @param value - The value to be displayed in the badge.
*/
export default function updateBadgeText(value: number): void {
let badgeText = '';
if (value > 0) {
if (value > BADGE_LIMIT) {
badgeText = `${BADGE_LIMIT}+`;
} else {
badgeText = `${value}`;
}
}
chrome.action.setBadgeText({ text: badgeText });
flashBadgeColor();
}
/**
* Flashes the badge color by setting the badge background color to a color and then resetting it after a short delay.
*/
function flashBadgeColor() {
chrome.action.setBadgeBackgroundColor({ color: colors.ut.burntorange });
setTimeout(() => chrome.action.setBadgeBackgroundColor({ color: colors.ut.orange }), POPUP_FLASH_TIME);
}