Skip to content

Commit

Permalink
Adds prettie & pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Asman Umbetov committed Nov 25, 2023
1 parent 452ba3b commit 3d126cb
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 47 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name: Deploy to Render
name: Deploy to Render

on:
push:
branches: [ master ]
on: [push]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to production
uses: johnbeynon/render-deploy-action@v0.0.8
uses: fastndead/render-deploy-action@0.0.8-pre
with:
service-id: ${{ secrets.SERVICE_ID }}
api-key: ${{ secrets.RENDER_API_KEY }}


wait-for-success: true
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn format
yarn lint

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
12 changes: 12 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
printWidth: 100,
semi: false,
trailingComma: "es5",
useTabs: false,
tabWidth: 2,
singleQuote: true,
quoteProps: "consistent",
jsxSingleQuote: true,
arrowParens: "always",
endOfLine: "lf",
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"dev:server": "npx tsc --watch & nodemon -q build/server/index.js && fg",
"test": "react-scripts test",
"lint": "eslint src/**/*.{ts,tsx} --fix",
"eject": "react-scripts eject"
"format": "prettier --write src/**/*.{ts,tsx}",
"eject": "react-scripts eject",
"prepare": "husky install"
},
"dependencies": {
"@react-spring/web": "^9.7.1",
Expand Down Expand Up @@ -45,9 +47,11 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"nodemon": "^2.0.20",
"prettier": "^3.1.0",
"stylelint": "^15.2.0",
"stylelint-config-standard": "^30.0.1",
"tailwindcss": "^3.2.7"
"tailwindcss": "^3.2.7",
"husky": "^8.0.0"
},
"eslintConfig": {
"extends": [
Expand Down
85 changes: 52 additions & 33 deletions src/contexts/NotificationContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,66 @@ export type Notification = {
timer?: ReturnType<typeof setTimeout>
}

export default function NotificationContextProvider({ children }: {children: ReactNode}) {
const [notifications, setNotifications] = useState<Map<string, Omit<Notification,'text'>>>(new Map())

const handleDismissFactory = useCallback((key: string) => () => {
setNotifications((prev) => {
prev.delete(key)
return new Map(prev)
})
}, [setNotifications])
export default function NotificationContextProvider({ children }: { children: ReactNode }) {
const [notifications, setNotifications] = useState<Map<string, Omit<Notification, 'text'>>>(
new Map()
)

const addNotification = useCallback((notification: Notification) => {
const timer = setTimeout(() => {handleDismissFactory(notification.text)()}, 2000)
const handleDismissFactory = useCallback(
(key: string) => () => {
setNotifications((prev) => {
prev.delete(key)
return new Map(prev)
})
},
[setNotifications]
)

setNotifications((prev) => new Map([...prev, [notification.text, { type: notification.type, timer }]]))
}, [setNotifications, handleDismissFactory])
const addNotification = useCallback(
(notification: Notification) => {
const timer = setTimeout(() => {
handleDismissFactory(notification.text)()
}, 2000)

setNotifications(
(prev) => new Map([...prev, [notification.text, { type: notification.type, timer }]])
)
},
[setNotifications, handleDismissFactory]
)

const formattedNotificatoins = useMemo(() => Array.from(notifications).map(item => ({ text: item[0], ...item[1] })), [notifications])
const formattedNotificatoins = useMemo(
() => Array.from(notifications).map((item) => ({ text: item[0], ...item[1] })),
[notifications]
)

const [transitions, api] = useTransition(formattedNotificatoins, () => {
return {
key: (item: Notification) => item.text,
from: { opacity: 0, y: -30 },
enter: { opacity: 1, y: 0 },
leave: { opacity: 0, y: -30 },
config: { tension: 310, friction: 20, mass: 2 },
}
config: { tension: 310, friction: 20, mass: 2 },
}
})

const handleMouseEnter = useCallback((key: string) => {
clearTimeout(notifications.get(key)?.timer)
}, [notifications])

const handleMouseLeave = useCallback((key: string) => {
const timer = setTimeout(() => {handleDismissFactory(key)()}, 2000)
const notification = notifications.get(key) || {} as Notification
notifications.set(key, { ...notification, timer } )
const handleMouseEnter = useCallback(
(key: string) => {
clearTimeout(notifications.get(key)?.timer)
},
[notifications]
)

}, [handleDismissFactory, notifications])
const handleMouseLeave = useCallback(
(key: string) => {
const timer = setTimeout(() => {
handleDismissFactory(key)()
}, 2000)
const notification = notifications.get(key) || ({} as Notification)
notifications.set(key, { ...notification, timer })
},
[handleDismissFactory, notifications]
)

useEffect(() => {
api.start()
Expand All @@ -54,7 +76,7 @@ export default function NotificationContextProvider({ children }: {children: Rea
return (
<NotificatoinsContext.Provider
value={{
addNotification
addNotification,
}}
>
{children}
Expand All @@ -63,7 +85,7 @@ export default function NotificationContextProvider({ children }: {children: Rea
>
{transitions((notifStyles, notif, state) => {
return (
<Notification
<Notification
onDismiss={handleDismissFactory(notif.text)}
key={state.key}
text={notif.text}
Expand All @@ -79,7 +101,6 @@ export default function NotificationContextProvider({ children }: {children: Rea
)
}


type NotificationProps = Notification & {
style: CSSProperties
onDismiss(): void
Expand All @@ -91,18 +112,16 @@ function Notification({ text, style, onDismiss, onMouseLeave, onMouseEnter }: No
const [isHovered, setIsHovered] = useState<boolean>(false)

const [spring] = useSpring(() => {
return isHovered
? { scale: 1.1 }
: { scale: 1 }
return isHovered ? { scale: 1.1 } : { scale: 1 }
}, [isHovered])

const handleMouseEnter = useCallback(() => {
onMouseEnter && onMouseEnter()
onMouseEnter && onMouseEnter()
setIsHovered(true)
}, [onMouseEnter, setIsHovered])

const handleMouseLeave = useCallback(() => {
onMouseLeave && onMouseLeave()
onMouseLeave && onMouseLeave()
setIsHovered(false)
}, [onMouseLeave, setIsHovered])

Expand Down
6 changes: 5 additions & 1 deletion src/contexts/NotificationsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ type NotificationContextValue = {
addNotification(notif: Notification): void
}

export const NotificatoinsContext = createContext<NotificationContextValue>({ addNotification: () => {/* */} })
export const NotificatoinsContext = createContext<NotificationContextValue>({
addNotification: () => {
/* */
},
})
3 changes: 1 addition & 2 deletions src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export function useLocalStorage<T>(key: string, initialValue: T) {

const setValue = (value: T | ((val: T) => T)) => {
try {
const valueToStore =
value instanceof Function ? value(storedValue) : value
const valueToStore = value instanceof Function ? value(storedValue) : value
setStoredValue(valueToStore)
if (typeof window !== 'undefined') {
window.localStorage.setItem(key, JSON.stringify(valueToStore))
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NotificatoinsContext } from 'contexts/NotificationsContext'
import { useContext } from 'react'

export function useNotifications(){
export function useNotifications() {
const { addNotification } = useContext(NotificatoinsContext)
return { addNotification }
}
2 changes: 1 addition & 1 deletion src/sockets/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import io from 'socket.io-client'
import { apiBaseUrl } from 'constants/constants'

export const socket = io(`${apiBaseUrl}/`, {
withCredentials: true,
withCredentials: true,
})
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5210,6 +5210,11 @@ human-signals@^2.1.0:
resolved "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

husky@^8.0.0:
version "8.0.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184"
integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==

[email protected]:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz"
Expand Down Expand Up @@ -7700,6 +7705,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==

prettier@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.0.tgz#c6d16474a5f764ea1a4a373c593b779697744d5e"
integrity sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==

pretty-bytes@^5.3.0, pretty-bytes@^5.4.1:
version "5.6.0"
resolved "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz"
Expand Down

0 comments on commit 3d126cb

Please sign in to comment.