Files
home-works/src/s2-homeworks/hw10/HW10.tsx
2022-09-26 09:09:47 +03:00

56 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react'
import {useDispatch, useSelector} from 'react-redux'
import {AppStoreType} from './bll/store'
import {loadingAC} from './bll/loadingReducer'
import SuperButton from '../hw04/common/c2-SuperButton/SuperButton'
import s2 from '../../s1-main/App.module.css'
import {Loader} from './Loader'
/*
* 1 - в файле loadingReducer.ts дописать типы и логику
* 2 - получить isLoading из редакса
* 3 - дописать функцию setLoading
* 4 - сделать стили в соответствии с дизайном
* */
const HW10 = () => {
// useSelector, useDispatch // пишет студент
const isLoading = useSelector<AppStoreType, boolean>(
(state: any) => state.loading.isLoading
)
const dispatch = useDispatch()
const setLoading = () => { // пишет студент // показать крутилку на 1,5 секунд
// dispatch
dispatch(loadingAC(true))
// setTimeout
setTimeout(() => {
dispatch(loadingAC(false))
}, 1500)
}
return (
<div id={'hw10'}>
<div className={s2.hwTitle}>Homework #10</div>
<div className={s2.hw}>
{isLoading ? (
<div id={'hw10-loading'}>
<Loader/>
</div>
) : (
<SuperButton
id={'hw10-button-start-loading'}
onClick={setLoading}
>
Set loading...
</SuperButton>
)}
</div>
</div>
)
}
export default HW10