refactor: deps cleanup

This commit is contained in:
enes 2024-12-26 16:42:11 +01:00
parent 4bf9787660
commit ad3d069ad5
3 changed files with 20 additions and 6 deletions

View File

@ -1,11 +1,12 @@
import { RouterProvider } from 'react-router-dom'
import { useEffect } from 'react'
import { routerWithNdkContext } from 'routes'
import { useEffect, useMemo } from 'react'
import { routerWithNdkContext as routerWithState } from 'routes'
import { useNDKContext } from 'hooks'
import './styles/styles.css'
function App() {
const ndkContext = useNDKContext()
const router = useMemo(() => routerWithState(ndkContext), [ndkContext])
useEffect(() => {
// Find the element with id 'root'
@ -24,7 +25,7 @@ function App() {
}
}, [])
return <RouterProvider router={routerWithNdkContext(ndkContext)} />
return <RouterProvider router={router} />
}
export default App

View File

@ -44,7 +44,7 @@ export const Layout = () => {
})
}
}
}, [ndk, dispatch])
}, [dispatch, ndk])
// calculate user's wot
useEffect(() => {
@ -60,7 +60,7 @@ export const Layout = () => {
toast.error('An error occurred in calculating user web-of-trust!')
})
}
}, [ndk, userState.user, dispatch])
}, [dispatch, ndk, userState.user?.pubkey])
// get site's wot level
useEffect(() => {
@ -106,7 +106,7 @@ export const Layout = () => {
})
}
}
}, [userState.user, dispatch, fetchEventFromUserRelays])
}, [dispatch, fetchEventFromUserRelays, userState.user?.pubkey])
return (
<>

View File

@ -274,3 +274,16 @@ export function orderEventsChronologically(
return events
}
/**
* Receives two events and returns the "correct" event to use.
* #nip-33
*/
export default function dedup(event1: NDKEvent, event2: NDKEvent) {
// return the newest of the two
if (event1.created_at! > event2.created_at!) {
return event1
}
return event2
}