This file contains hidden or 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
| // Функция для прокрутки страницы | |
| function scrollToBottom() { | |
| // Получаем высоту документа | |
| var documentHeight = document.documentElement.scrollHeight; | |
| // Получаем текущую позицию прокрутки | |
| var currentScroll = window.scrollY; | |
| // Устанавливаем новую позицию прокрутки | |
| var newScroll = currentScroll + 1; // Измените значение 1 на любое другое, чтобы регулировать скорость прокрутки |
This file contains hidden or 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
| export const changeCourseId = createAsyncThunk( | |
| 'auth/change-course', | |
| async (payload: PayloadType, thunkAPI) => { | |
| return thunkTryCatch(thunkAPI, async () => { | |
| await packsApi.put(payload) | |
| }) | |
| } | |
| ) |
This file contains hidden or 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
| // 🔰 Don't write dispacth in componets. Instead of useAppDispatch use useActionsHook | |
| // 🔗 https://medium.com/@d.maklygin/redux-typescript-reuse-the-type-of-an-action-creators-return-value-91663a48858f | |
| import { useMemo } from 'react' | |
| import { ActionCreatorsMapObject, bindActionCreators } from 'redux' | |
| import { useAppDispatch } from './react-redux-hooks' | |
| type IsValidArg<T> = T extends object ? (keyof T extends never ? false : true) : true |
This file contains hidden or 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
| const uploadHandler = (e: ChangeEvent<HTMLInputElement>) => { | |
| if (e.target.files && e.target.files.length) { | |
| const file = e.target.files[0] | |
| if (file.size < 4000000) { | |
| convertFileToBase64(file, (file64: string) => { | |
| dispatch(updateProfileTC({avatar: file64})) | |
| }) | |
| } else { | |
| dispatch(setAppErrorAC('Файл слишком большого размера')) | |
| } |
This file contains hidden or 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
| import { setAppErrorAC, SetAppErrorActionType } from '../../app/app-reducer'; | |
| import { Dispatch } from 'redux'; | |
| import axios, { AxiosError } from 'axios'; | |
| import { AppThunk } from '../../app/store'; | |
| import { packsAPI } from '../../api/packs-api'; | |
| export const errorUtils = (e: Error | AxiosError<{error: string}>, dispatch: Dispatch<SetAppErrorActionType>) => { | |
| const err = e as Error | AxiosError<{ error: string }> | |
| if (axios.isAxiosError(err)) { | |
| const error = err.response?.data ? err.response.data.error : err.message |
This file contains hidden or 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
| import React, { FC } from 'react'; | |
| type PropsType = { | |
| // | |
| } | |
| export const Component: FC<PropsType> = React.memo(() => { | |
| return ( | |
| <>Component</> | |
| ) |
This file contains hidden or 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
| import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' | |
| import { AppDispatch, RootState } from '../../app/store' | |
| export const useAppDispatch: () => AppDispatch = useDispatch | |
| export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector |
This file contains hidden or 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
| import { createSlice } from '@reduxjs/toolkit' | |
| export const hostAppSlice = createSlice({ | |
| name: 'host-app', | |
| initialState: { | |
| value: false, | |
| }, | |
| reducers: { | |
| changeValue: (state) => { | |
| state.value = true |
This file contains hidden or 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
| import {useState, useEffect} from 'react' | |
| import axios from 'axios' | |
| export default url => { | |
| const baseUrl = 'https://conduit.productionready.io/api' | |
| const [isLoading, setIsLoading] = useState(false) | |
| const [response, setResponse] = useState(null) | |
| const [error, setError] = useState(null) | |
| const [options, setOptions] = useState({}) |
This file contains hidden or 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
| import React, {useState, useEffect} from 'react' | |
| import {Link} from 'react-router-dom' | |
| import axios from 'axios' | |
| import useFetch from 'hooks/useFetch' | |
| const Authentication = () => { | |
| const [email, setEmail] = useState('') | |
| const [password, setPassword] = useState('') | |
| const [{isLoading, error, response}, doFetch] = useFetch('/users/login') |
NewerOlder