Skip to content

Commit 946bae7

Browse files
committed
Disable command copy and transition in mobile device
1 parent 5d0fc0b commit 946bae7

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

theme/components/version-card/index.module.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,23 @@
103103

104104
.command {
105105
padding: 10px 16px;
106+
cursor: default;
107+
108+
&:hover {
109+
background: rgba(255, 255, 255, 0.1);
110+
111+
.copyButton {
112+
opacity: 0;
113+
}
114+
}
106115
}
107116

108117
.commandText {
109118
font-size: 12px;
119+
transition: none;
120+
}
121+
122+
.copyButton {
123+
display: none;
110124
}
111125
}

theme/components/version-card/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@ const VersionCard: FC = () => {
77
const [currentCommand, setCurrentCommand] = useState(0);
88
const [isHovered, setIsHovered] = useState(false);
99
const [isFading, setIsFading] = useState(false);
10+
const [isMobile, setIsMobile] = useState(false);
1011
const intervalRef = useRef<NodeJS.Timeout>();
1112

13+
useEffect(() => {
14+
const checkMobile = () => {
15+
setIsMobile(window.innerWidth <= 600);
16+
};
17+
18+
checkMobile();
19+
window.addEventListener('resize', checkMobile);
20+
21+
return () => window.removeEventListener('resize', checkMobile);
22+
}, []);
23+
1224
const commands = [
1325
'curl https://aiscript.dev/install.sh | sh',
1426
'cargo install aiscript'
1527
];
1628

1729
const handleCopy = useCallback(() => {
30+
if (isMobile) return;
1831
navigator.clipboard.writeText(commands[currentCommand]).then(() => {
1932
setCopied(true);
2033
setTimeout(() => setCopied(false), 2000);
2134
});
22-
}, [currentCommand, commands]);
35+
}, [currentCommand, commands, isMobile]);
2336

2437
const switchCommand = useCallback(() => {
2538
setIsFading(true);
@@ -30,15 +43,15 @@ const VersionCard: FC = () => {
3043
}, [commands.length]);
3144

3245
useEffect(() => {
33-
if (!isHovered) {
46+
if (!isHovered && !isMobile) {
3447
intervalRef.current = setInterval(switchCommand, 3000);
3548
}
3649
return () => {
3750
if (intervalRef.current) {
3851
clearInterval(intervalRef.current);
3952
}
4053
};
41-
}, [isHovered, switchCommand]);
54+
}, [isHovered, switchCommand, isMobile]);
4255

4356
const handleMouseEnter = useCallback(() => {
4457
setIsHovered(true);

0 commit comments

Comments
 (0)