Skip to content

Commit 88d66e0

Browse files
committed
chore: routine improvements
1 parent e2e22b1 commit 88d66e0

19 files changed

Lines changed: 415 additions & 412 deletions

File tree

apps/main/next.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const NextConfigs = {
2626
{
2727
protocol: "https",
2828
hostname: "luneresearch.com",
29+
pathname: "/lune-logo.svg",
30+
search: "",
31+
},
32+
{
33+
protocol: "https",
34+
hostname: "retroguard.ai",
35+
pathname: "/logo.svg",
36+
search: "",
2937
},
3038
{
3139
protocol: "https",
83 Bytes
Binary file not shown.

apps/main/src/components/Footer/index.tsx

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { OffsetTransition } from "../Motion"
21
import { Icon } from "@twilight-toolkit/ui"
3-
import { useTheme } from "next-themes"
42
import { useRouter } from "next/router"
3+
import { useTheme } from "next-themes"
54
import { useEffect, useRef, useState } from "react"
65
import smoothScroll from "smoothscroll-polyfill"
76
import { useDispatch, useSelector } from "~/hooks"
87
import { deactivateKbar } from "~/store/kbar/actions"
98
import { selectKbar } from "~/store/kbar/selectors"
9+
import { OffsetTransition } from "../Motion"
1010

1111
const themes = ["system", "dark", "light"]
1212
const icons = [
@@ -23,67 +23,72 @@ export default function Footer() {
2323
const { pathname } = useRouter()
2424
const [mounted, setMounted] = useState(false)
2525
const backToTopRef = useRef<HTMLButtonElement>(null)
26+
const previousPathnameRef = useRef(pathname)
2627

2728
useEffect(() => {
2829
smoothScroll.polyfill()
2930
setMounted(true)
3031
}, [])
3132

3233
useEffect(() => {
33-
// Cursor glowing effect
34-
if (mounted && resolvedTheme === "dark") {
35-
const glowingArea = document.querySelector(".glowing-area")
36-
const glowingDivs = document.querySelectorAll(".glowing-div")
34+
if (!mounted || resolvedTheme !== "dark") return
35+
36+
const glowingArea = document.querySelector<HTMLElement>(".glowing-area")
37+
const glowingDivs = document.querySelectorAll<HTMLElement>(".glowing-div")
3738

38-
if (glowingArea) {
39-
const handler = (ev: any) => {
40-
glowingDivs.forEach((featureEl: any) => {
41-
const rect = featureEl.getBoundingClientRect()
42-
featureEl.style.setProperty("--x", ev.clientX - rect.left)
43-
featureEl.style.setProperty("--y", ev.clientY - rect.top)
44-
})
45-
}
46-
glowingArea.addEventListener("pointermove", handler)
39+
if (!glowingArea) return
4740

48-
return () => {
49-
glowingArea.removeEventListener("pointermove", handler)
50-
}
51-
}
41+
const handler = (ev: PointerEvent) => {
42+
glowingDivs.forEach((featureEl) => {
43+
const rect = featureEl.getBoundingClientRect()
44+
featureEl.style.setProperty("--x", `${ev.clientX - rect.left}`)
45+
featureEl.style.setProperty("--y", `${ev.clientY - rect.top}`)
46+
})
5247
}
53-
// Hide kbar on route change
54-
visible && dispatch(deactivateKbar())
55-
}, [resolvedTheme, mounted, pathname])
48+
glowingArea.addEventListener("pointermove", handler)
49+
50+
return () => {
51+
glowingArea.removeEventListener("pointermove", handler)
52+
}
53+
}, [mounted, pathname, resolvedTheme])
54+
55+
useEffect(() => {
56+
if (previousPathnameRef.current === pathname) return
57+
58+
previousPathnameRef.current = pathname
59+
if (visible) dispatch(deactivateKbar())
60+
}, [dispatch, pathname, visible])
5661

5762
if (!mounted) return null
5863

5964
return (
60-
<footer className="mt-20 border-b border-t border-gray-200 bg-white py-4 text-center dark:border-gray-700 dark:bg-gray-800">
65+
<footer className="mt-20 border-gray-200 border-t border-b bg-white py-4 text-center dark:border-gray-700 dark:bg-gray-800">
6166
<div className="fixed bottom-8 left-8 text-gray-500 dark:text-gray-300">
6267
<button
6368
aria-label="change theme"
6469
onClick={() => {
6570
setTheme(targetThemes[themes.indexOf(theme)])
6671
}}
67-
className="effect-pressing p-3! shadow-xs focus:outline-hidden flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white text-xl tracking-wider hover:shadow-inner dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700">
72+
className="effect-pressing flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white p-3! text-xl tracking-wider shadow-xs hover:shadow-inner focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700">
6873
<span className="h-7 w-7">{icons[themes.indexOf(theme)]}</span>
6974
</button>
7075
</div>
71-
<div className="fixed bottom-8 right-8 text-gray-500 dark:text-gray-300">
76+
<div className="fixed right-8 bottom-8 text-gray-500 dark:text-gray-300">
7277
<OffsetTransition componentRef={backToTopRef}>
7378
<button
7479
ref={backToTopRef}
7580
aria-label="change theme"
7681
onClick={() => {
7782
window.scrollTo({ top: 0, behavior: "smooth" })
7883
}}
79-
className="effect-pressing shadow-xs focus:outline-hidden flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white p-3 text-xl tracking-wider opacity-0 hover:shadow-inner dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700">
84+
className="effect-pressing flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white p-3 text-xl tracking-wider opacity-0 shadow-xs hover:shadow-inner focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700">
8085
<span className="h-7 w-7">
8186
<Icon name="arrowUp" />
8287
</span>
8388
</button>
8489
</OffsetTransition>
8590
</div>
86-
<p className="text-4 tracking-wide text-gray-500 dark:text-gray-400">
91+
<p className="text-4 text-gray-500 tracking-wide dark:text-gray-400">
8792
<a
8893
href="https://creativecommons.org/licenses/by-nc-sa/4.0/"
8994
target="_blank"

apps/main/src/components/Helpers/hotKey.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import type { KbarListItem } from "../Kbar"
21
import { useHotkeys } from "react-hotkeys-hook"
32

4-
/**
5-
* Helper component to use react-hotkeys-hook to register hotkeys
6-
* for Kbar list items
7-
*
8-
* @param {{ item: KbarListItem }} { item }
9-
* @return {*}
10-
*/
11-
const HotkeyHelper = ({ item }: { item: KbarListItem }) => {
3+
const HotkeyHelper = ({
4+
onTrigger,
5+
shortcut,
6+
}: {
7+
onTrigger: () => void
8+
shortcut: string[]
9+
}) => {
10+
const hotkey = `shift+${shortcut.join("+")}`
11+
1212
useHotkeys(
13-
`shift+${item.shortcut.join("+")}`,
13+
hotkey,
1414
(e) => {
15-
// Only trigger if shift key is actually pressed
1615
if (e.shiftKey) {
1716
e.preventDefault()
18-
item.action()
17+
onTrigger()
1918
}
2019
},
2120
{
2221
enableOnFormTags: ["INPUT"],
2322
useKey: true,
24-
}
23+
},
24+
[onTrigger]
2525
)
26-
// render nothing
2726
return null
2827
}
2928

apps/main/src/components/Kbar/component.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import type { KbarProps } from "."
2-
import { KbarContextProvider } from "./context"
3-
import KbarPanel from "./panel"
41
import { useEffect, useState } from "react"
52
import { useHotkeys } from "react-hotkeys-hook"
63
import {
74
useBodyPointerEvents,
85
useBodyScroll,
9-
useDebounce,
106
useDispatch,
117
useSelector,
128
} from "~/hooks"
139
import useAnalytics from "~/hooks/analytics"
1410
import { activateKbar, deactivateKbar, updateKbar } from "~/store/kbar/actions"
1511
import { searchLocation } from "~/store/kbar/sagas/updateKbarToSearch"
1612
import { selectKbar } from "~/store/kbar/selectors"
13+
import type { KbarProps } from "."
14+
import { KbarContextProvider } from "./context"
15+
import KbarPanel from "./panel"
1716

1817
const Kbar = (props: KbarProps) => {
1918
const dispatch = useDispatch()
@@ -67,18 +66,19 @@ const Kbar = (props: KbarProps) => {
6766
setBodyPointerEvents(true)
6867
setBodyScroll(true)
6968
}
70-
}, [visible])
69+
}, [visible, setBodyPointerEvents, setBodyScroll])
7170

72-
// Input effects
73-
useDebounce(
74-
() => {
75-
if (location === searchLocation && kbarInputValueChangeHandler) {
76-
kbarInputValueChangeHandler(kbarInputValue)
77-
}
78-
},
79-
300,
80-
[location, kbarInputValueChangeHandler, kbarInputValue]
81-
)
71+
useEffect(() => {
72+
if (location !== searchLocation || !kbarInputValueChangeHandler) return
73+
74+
const timeout = window.setTimeout(() => {
75+
kbarInputValueChangeHandler(kbarInputValue)
76+
}, 300)
77+
78+
return () => {
79+
window.clearTimeout(timeout)
80+
}
81+
}, [location, kbarInputValueChangeHandler, kbarInputValue])
8282

8383
return (
8484
visible && (
@@ -91,7 +91,7 @@ const Kbar = (props: KbarProps) => {
9191
}}>
9292
<div
9393
data-cy="kbar-bg"
94-
className={`bg-gray-50/90 pointer-events-auto absolute z-40 h-screen w-full dark:bg-black/70 ${
94+
className={`pointer-events-auto absolute z-40 h-screen w-full bg-gray-50/90 dark:bg-black/70 ${
9595
animation === "out" ? "animate-kbar-bg-out" : "animate-kbar-bg"
9696
}`}
9797
onClick={() => dispatch(deactivateKbar())}

0 commit comments

Comments
 (0)