forked from Archives/Athou_commafeed
replace old client with new client from commafeed-ui repository
This commit is contained in:
34
commafeed-client/src/hooks/useAppLoading.ts
Normal file
34
commafeed-client/src/hooks/useAppLoading.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { t } from "@lingui/macro"
|
||||
import { useAppSelector } from "app/store"
|
||||
|
||||
interface Step {
|
||||
label: string
|
||||
done: boolean
|
||||
}
|
||||
|
||||
export const useAppLoading = () => {
|
||||
const profile = useAppSelector(state => state.user.profile)
|
||||
const settings = useAppSelector(state => state.user.settings)
|
||||
const rootCategory = useAppSelector(state => state.tree.rootCategory)
|
||||
|
||||
const steps: Step[] = [
|
||||
{
|
||||
label: t`Loading settings...`,
|
||||
done: !!settings,
|
||||
},
|
||||
{
|
||||
label: t`Loading profile...`,
|
||||
done: !!profile,
|
||||
},
|
||||
{
|
||||
label: t`Loading subscriptions...`,
|
||||
done: !!rootCategory,
|
||||
},
|
||||
]
|
||||
|
||||
const loading = steps.some(s => !s.done)
|
||||
const loadingPercentage = Math.round((100.0 * steps.filter(s => s.done).length) / steps.length)
|
||||
const loadingStepLabel = steps.find(s => !s.done)?.label
|
||||
|
||||
return { steps, loading, loadingPercentage, loadingStepLabel }
|
||||
}
|
||||
22
commafeed-client/src/hooks/useMousetrap.ts
Normal file
22
commafeed-client/src/hooks/useMousetrap.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import mousetrap, { ExtendedKeyboardEvent } from "mousetrap"
|
||||
import { useEffect, useRef } from "react"
|
||||
|
||||
type Callback = (e: ExtendedKeyboardEvent, combo: string) => void
|
||||
|
||||
export const useMousetrap = (key: string | string[], callback: Callback) => {
|
||||
// use a ref to avoid unbinding/rebinding every time the callback changes
|
||||
const callbackRef = useRef(callback)
|
||||
callbackRef.current = callback
|
||||
|
||||
useEffect(() => {
|
||||
mousetrap.bind(key, (event, combo) => {
|
||||
callbackRef.current(event, combo)
|
||||
|
||||
// prevent default behavior
|
||||
return false
|
||||
})
|
||||
return () => {
|
||||
mousetrap.unbind(key)
|
||||
}
|
||||
}, [key])
|
||||
}
|
||||
Reference in New Issue
Block a user