Skip to content

Commit

Permalink
refactor: replace some of the hooks imported from react-use by react-…
Browse files Browse the repository at this point in the history
…hookz
  • Loading branch information
arianrhodsandlot committed Oct 20, 2023
1 parent 5e59044 commit 013de4a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@microsoft/microsoft-graph-client": "3.0.7",
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-tooltip": "1.0.7",
"@react-hookz/web": "23.1.0",
"@zip.js/zip.js": "2.7.30",
"clsx": "2.0.0",
"date-fns": "2.30.0",
Expand Down
28 changes: 25 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/views/components/common/cloud-service-login-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useIntervalEffect } from '@react-hookz/web'
import clsx from 'clsx'
import mitt from 'mitt'
import { useRef, useState } from 'react'
import { useAsync, useAsyncFn, useInterval } from 'react-use'
import { useAsync, useAsyncFn } from 'react-use'
import { type CloudService, detectNeedsLogin, getAuthorizeUrl, getTokenStorageKey } from '../../../core'
import { BaseButton } from '../primitives/base-button'
import { ReturnToHomeButton } from './return-to-home-button'
Expand Down Expand Up @@ -37,7 +38,7 @@ export function CloudServiceLoginButton({
const authorizeWindow = useRef<Window | null>(null)
const [isAuthWindowOpening, setIsAuthWindowOpening] = useState(false)

useInterval(() => {
useIntervalEffect(() => {
const newIsAuthWindowOpening = authorizeWindow.current ? !authorizeWindow.current?.closed : false
setIsAuthWindowOpening(newIsAuthWindowOpening)
if (isAuthWindowOpening && !newIsAuthWindowOpening) {
Expand Down
10 changes: 6 additions & 4 deletions src/views/components/home-screen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMeasure } from '@react-hookz/web'
import { useAtom, useAtomValue, useSetAtom, useStore } from 'jotai'
import { some } from 'lodash-es'
import { useEffect, useState } from 'react'
import { useAsync, useAsyncRetry, useMeasure } from 'react-use'
import { useAsync, useAsyncRetry } from 'react-use'
import { getHistoryRoms, getSystemRoms, getSystems, peekHistoryRoms, peekSystemRoms, peekSystems } from '../../../core'
import { isGameLaunchedAtom } from '../atoms'
import { currentSystemNameAtom, romsAtom, systemsAtom } from './atoms'
Expand Down Expand Up @@ -58,9 +59,11 @@ export function HomeScreen() {
const isGameLaunched = useAtomValue(isGameLaunchedAtom)
const store = useStore()
const [currentSystemName, setCurrentSystemName] = useAtom(currentSystemNameAtom)
const [gridContainerRef, { width: gridWidth, height: gridHeight }] = useMeasure<HTMLDivElement>()
const [measurements = { width: 0, height: 0 }, gridContainerRef] = useMeasure<HTMLDivElement>()
const [isRetrying, setIsRetrying] = useState(false)

const { width: gridWidth, height: gridHeight } = measurements

const columnCount = getColumnCount(gridWidth)

// load systems from cache
Expand Down Expand Up @@ -155,7 +158,7 @@ export function HomeScreen() {
rowHeight={columnWidth}
width={gridWidth}
/>

<InputTips />
<GameLaunching />
</div>
)}
Expand All @@ -166,7 +169,6 @@ export function HomeScreen() {
{isGameLaunched ? (
<>
<GameMenus />
<InputTips />
<VirtualController />
</>
) : null}
Expand Down
8 changes: 4 additions & 4 deletions src/views/components/home-screen/input-tips/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEventListener } from '@react-hookz/web'
import delay from 'delay'
import { AnimatePresence, motion } from 'framer-motion'
import $ from 'jquery'
import { useRef, useState } from 'react'
import { useEvent } from 'react-use'
import { InputTipsContent } from './input-tips-content'

async function hasIntersection(element1: HTMLElement, element2: HTMLElement) {
Expand All @@ -28,9 +28,10 @@ export function InputTips() {
const [shouldMoveToLeft, setShouldMoveToLeft] = useState(false)
const ref = useRef(null)

useEvent(
useEventListener(
document.body,
'focus',
async (e) => {
async (e: FocusEvent) => {
const button = e.target as HTMLButtonElement
if (!button || !ref.current) {
return
Expand All @@ -47,7 +48,6 @@ export function InputTips() {
setShouldMoveToLeft(false)
}
},
document.body,
{ capture: true },
)

Expand Down
4 changes: 2 additions & 2 deletions src/views/components/setup-wizard/animated-icons.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useIntervalEffect } from '@react-hookz/web'
import clsx from 'clsx'
import delay from 'delay'
import { useState } from 'react'
import { useInterval } from 'react-use'

export function AnimatedIcons({ wait = 0, children }: { wait?: number; children: any }) {
const [frames, setFrames] = useState(0)
const [enableAnimation, setEnableAnimation] = useState(true)

useInterval(async () => {
useIntervalEffect(async () => {
if (wait) {
await delay(wait)
}
Expand Down

0 comments on commit 013de4a

Please sign in to comment.