Skip to content

Commit

Permalink
Hide TTS health via opacity when sufficiently high
Browse files Browse the repository at this point in the history
  • Loading branch information
DJDavid98 committed Dec 23, 2023
1 parent 23b60cb commit b7cce28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/js/chat/TtsHealth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ export const TtsHealth: FC<TtsHealthProps> = ({ token }) => {
return { maxChars, usedChars };
}, [subscriptionData]);

const ttsUsedPercent = limits.maxChars > 0 ? limits.usedChars / limits.maxChars : 1;
const charsAvailable = limits.maxChars - limits.usedChars;
const progressBarStyle = useMemo(() => ({ width: limits.maxChars > 0 ? (100 * (charsAvailable / limits.maxChars)).toFixed(2) + '%' : '' }), [charsAvailable, limits.maxChars]);
const style = useMemo(() => ({ opacity: ttsUsedPercent < .9 ? 0 : 1 }), [ttsUsedPercent]);
const progressBarStyle = useMemo(() => ({ width: (100 * (1 - ttsUsedPercent)).toFixed(2) + '%' }), [ttsUsedPercent]);

if (limits.maxChars === 0) return null;


return <div className={styles['tts-health']}>
return <div className={styles['tts-health']} style={style}>
<label className={styles['tts-label']}>
<div className={styles['tts-name']}>❤️ TTS Health</div>
{limits.maxChars > 0 &&
<div className={styles['tts-percent']}>{nf.format(charsAvailable)} / {nf.format(limits.maxChars)} &bull; {pf.format(1 - limits.usedChars / limits.maxChars)}</div>}
<div className={styles['tts-percent']}>{nf.format(charsAvailable)} / {nf.format(limits.maxChars)} &bull; {pf.format(1 - ttsUsedPercent)}</div>}
</label>
<div className={styles['progress']}>
<div className={styles['progress-bar']} style={progressBarStyle}></div>
Expand Down
6 changes: 6 additions & 0 deletions src/scss/modules/TtsHealth.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
border-radius: .4em;
font-size: .6em;
width: calc(100% - 2em);
transition: opacity .3s linear;
cursor: pointer;

&:hover {
opacity: 1 !important;
}

.tts-label {
display: flex;
Expand Down

0 comments on commit b7cce28

Please sign in to comment.