π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat: smooth dynamic timer bar
httpjamesm81328324d232
diff --git a/apps/cast/src/components/TimerBar.tsx b/apps/cast/src/components/TimerBar.tsxnew file mode 100644index 0000000000..0d0a07e6bd--- /dev/null+++ b/apps/cast/src/components/TimerBar.tsx@@ -0,0 +1,30 @@+import { useEffect, useState } from 'react';++export default function TimerBar({ percentage }: { percentage: number }) {+ const okColor = '#75C157';+ const warningColor = '#FFC000';+ const lateColor = '#FF0000';++ const [backgroundColor, setBackgroundColor] = useState(okColor);++ useEffect(() => {+ if (percentage >= 40) {+ setBackgroundColor(okColor);+ } else if (percentage >= 20) {+ setBackgroundColor(warningColor);+ } else {+ setBackgroundColor(lateColor);+ }+ }, [percentage]);++ return (+ <div+ style={{+ width: `${percentage}%`, // Set the width based on the time left+ height: '10px', // Same as the border thickness+ backgroundColor, // The color of the moving border+ transition: 'width 1s linear', // Smooth transition for the width change+ }}+ />+ );+}diff --git a/apps/cast/src/pages/index.tsx b/apps/cast/src/pages/index.tsxindex 25a897fb89..5e87bf70a4 100644--- a/apps/cast/src/pages/index.tsx+++ b/apps/cast/src/pages/index.tsx@@ -8,6 +8,7 @@ import {} from '@ente/shared/crypto/internal/libsodium';import { useRouter } from 'next/router';import { SESSION_KEYS, setKey } from '@ente/shared/storage/sessionStorage';+import TimerBar from 'components/TimerBar';const colourPool = ['#87CEFA', // Light Blue@@ -56,6 +57,10 @@ export default function PairingMode() {const [publicKeyB64, setPublicKeyB64] = useState('');+ const [codeGeneratedAt, setCodeGeneratedAt] = useState<Date | null>(null);++ const [borderWidthPercentage, setBorderWidthPercentage] = useState(100);+useEffect(() => {init();const interval = setInterval(() => {@@ -133,6 +138,8 @@ export default function PairingMode() {} catch (e) {return;}++ setCodeGeneratedAt(new Date());};const router = useRouter();@@ -161,6 +168,27 @@ export default function PairingMode() {advertisePublicKey(publicKeyB64);}, [publicKeyB64]);+ useEffect(() => {+ if (!codeGeneratedAt) return;++ // compute border width based on time left until next code regenerates+ const interval = setInterval(() => {+ const now = new Date();+ const timeLeft =+ codeGeneratedAt.getTime() + 45 * 1000 - now.getTime();++ if (timeLeft > 0) {+ const percentage = (timeLeft / (45 * 1000)) * 100;++ setBorderWidthPercentage(percentage);+ }+ }, 250);++ return () => {+ clearInterval(interval);+ };+ }, [codeGeneratedAt]);+return (<><div@@ -184,44 +212,50 @@ export default function PairingMode() {}}>Enter this code on <b>ente</b> to pair this TV</h1>- <table+ <divstyle={{- fontSize: '4rem',- fontWeight: 'bold',- fontFamily: 'monospace',- display: 'flex',borderRadius: '10px',overflow: 'hidden',}}>- {digits.map((digit, i) => (- <tr- key={i}- style={{- display: 'flex',- flexDirection: 'column',- alignItems: 'center',- padding: '0.5rem',- // alternating background- backgroundColor:- i % 2 === 0 ? '#2e2e2e' : '#5e5e5e',- }}>- <span- style={{- color: colourPool[- i % colourPool.length- ],- }}>- {digit}- </span>- <span+ <table+ style={{+ fontSize: '4rem',+ fontWeight: 'bold',+ fontFamily: 'monospace',+ display: 'flex',+ position: 'relative',+ }}>+ {digits.map((digit, i) => (+ <tr+ key={i}style={{- fontSize: '1rem',+ display: 'flex',+ flexDirection: 'column',+ alignItems: 'center',+ padding: '0.5rem',+ // alternating background+ backgroundColor:+ i % 2 === 0 ? '#2e2e2e' : '#5e5e5e',}}>- {i + 1}- </span>- </tr>- ))}- </table>+ <span+ style={{+ color: colourPool[+ i % colourPool.length+ ],+ }}>+ {digit}+ </span>+ <span+ style={{+ fontSize: '1rem',+ }}>+ {i + 1}+ </span>+ </tr>+ ))}+ </table>+ <TimerBar percentage={borderWidthPercentage} />+ </div><pstyle={{fontSize: '1.2rem',