Skip to content

Commit

Permalink
Merge pull request #173 from musehq/dev
Browse files Browse the repository at this point in the history
v2.12.1
  • Loading branch information
spacesvr authored May 11, 2023
2 parents 7e7ca61 + af40397 commit 14bb8bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spacesvr",
"version": "2.12.0",
"version": "2.12.1",
"private": true,
"description": "A standardized reality for future of the 3D Web",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/layers/Environment/ui/PauseMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function PauseMenu(props: PauseMenuProps) {
const PAUSE_ITEMS: MenuItem[] = [
...pauseMenuItems,
{
text: "v2.12.0",
text: "v2.12.1",
link: "https://www.npmjs.com/package/spacesvr",
},
...menuItems,
Expand Down
1 change: 1 addition & 0 deletions src/layers/Toolbelt/ideas/ToolSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Container = styled.div<{ open: boolean }>`
z-index: 2;
padding: ${FIXED_PADDING}px ${FIXED_PADDING}px 0 ${FIXED_PADDING}px;
border-radius: ${OUTER_BORDER_RADIUS}px;
pointer-events: ${(props) => (props.open ? "all" : "none")};
display: flex;
max-width: calc(100% - 80px);
Expand Down
28 changes: 18 additions & 10 deletions src/logic/toggle.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import { useCallback, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import Timeout = NodeJS.Timeout;

/**
* A hook that allows you to toggle a boolean value.
* @param delay time in ms
*/
export const useDelayedToggle = (delay = 1000) => {
const lastTimeSet = useRef(0);
const timeoutId = useRef<Timeout | null>(null);
const [active, setActiveState] = useState(false);

if (active && Date.now() - lastTimeSet.current > delay) {
lastTimeSet.current = Date.now();
setActiveState(!active);
}

const setActive = useCallback(() => {
if (timeoutId.current !== null) {
clearTimeout(timeoutId.current);
}

setActiveState(true);
lastTimeSet.current = Date.now();
setTimeout(() => {
if (Date.now() - lastTimeSet.current > delay) setActiveState(false);

timeoutId.current = setTimeout(() => {
setActiveState(false);
}, delay);
}, [delay]);

useEffect(() => {
return () => {
if (timeoutId.current !== null) {
clearTimeout(timeoutId.current);
}
};
}, []);

return { active, setActive };
};

1 comment on commit 14bb8bf

@vercel
Copy link

@vercel vercel bot commented on 14bb8bf May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.