-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { StateSchema } from '@/app/providers/StoreProvider'; | ||
|
||
type Selector<T> = (state: StateSchema) => T; | ||
type Result<T> = [() => T, Selector<T>] | ||
|
||
export function buildSelector<T>(selector: Selector<T>): Result<T> { | ||
const useSelectorHook = () => { | ||
return useSelector(selector); | ||
}; | ||
|
||
return [useSelectorHook, selector]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { bindActionCreators, createSlice } from '@reduxjs/toolkit'; | ||
import { SliceCaseReducers, CreateSliceOptions } from '@reduxjs/toolkit/dist'; | ||
import { useDispatch } from 'react-redux'; | ||
import { useMemo } from 'react'; | ||
|
||
export function buildSlice< | ||
State, | ||
CaseReducers extends SliceCaseReducers<State>, | ||
Name extends string = string | ||
>(options: CreateSliceOptions<State, CaseReducers, Name>) { | ||
const slice = createSlice(options); | ||
|
||
const useActions = (): typeof slice.actions => { | ||
const dispatch = useDispatch(); | ||
|
||
// @ts-ignore | ||
return useMemo(() => bindActionCreators(slice.actions, dispatch), [dispatch]); | ||
}; | ||
|
||
return { | ||
...slice, | ||
useActions, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { buildSelector } from './buildSelector'; | ||
export { buildSlice } from './buildSlice'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,54 @@ | ||
import { classNames, Mods } from '@/shared/lib/classNames/classNames'; | ||
import { CSSProperties, useMemo } from 'react'; | ||
import cls from './Avatar.module.scss'; | ||
import { CSSProperties, useMemo } from "react"; | ||
import { classNames, Mods } from "@/shared/lib/classNames/classNames"; | ||
import cls from "./Avatar.module.scss"; | ||
import { AppImage } from "../AppImage"; | ||
import UserIcon from "../../assets/icons/user-filled.svg"; | ||
import { Icon } from "../Icon"; | ||
import { Skeleton } from "../Skeleton"; | ||
|
||
interface AvatarProps { | ||
className?: string; | ||
src?: string; | ||
size?: number; | ||
alt?: string; | ||
className?: string; | ||
src?: string; | ||
size?: number; | ||
alt?: string; | ||
fallbackInverted?: boolean; | ||
} | ||
|
||
export const Avatar = ({ | ||
className, src, size, alt, | ||
className, | ||
src, | ||
size = 100, | ||
alt, | ||
fallbackInverted, | ||
}: AvatarProps) => { | ||
const mods: Mods = {}; | ||
const mods: Mods = {}; | ||
|
||
const styles = useMemo<CSSProperties>(() => ({ | ||
width: size || 100, | ||
height: size || 100, | ||
}), [size]); | ||
const styles = useMemo<CSSProperties>( | ||
() => ({ | ||
width: size, | ||
height: size, | ||
}), | ||
[size] | ||
); | ||
|
||
return ( | ||
<img | ||
src={src} | ||
alt={alt} | ||
style={styles} | ||
className={classNames(cls.Avatar, mods, [className])} | ||
/> | ||
); | ||
const fallback = <Skeleton width={size} height={size} border="50%" />; | ||
const errorFallback = ( | ||
<Icon | ||
inverted={fallbackInverted} | ||
width={size} | ||
height={size} | ||
Svg={UserIcon} | ||
/> | ||
); | ||
|
||
return ( | ||
<AppImage | ||
fallback={fallback} | ||
errorFallback={errorFallback} | ||
src={src} | ||
alt={alt} | ||
style={styles} | ||
className={classNames(cls.Avatar, mods, [className])} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
.Icon { | ||
fill: var(--primary-color); | ||
color: var(--primary-color); | ||
} | ||
|
||
.inverted { | ||
fill: var(--inverted-primary-color); | ||
color: var(--inverted-primary-color); | ||
} |