add hw 14-15 for design

This commit is contained in:
neko
2022-11-08 14:01:28 +03:00
parent b25f4b4f5b
commit 7a91352d47
7 changed files with 362 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
import React, {useEffect, useState} from 'react'
import s2 from '../../s1-main/App.module.css'
import s from './HW14.module.css'
import axios from 'axios'
import SuperDebouncedInput from './common/c8-SuperDebouncedInput/SuperDebouncedInput'
import {useSearchParams} from 'react-router-dom'
/*
* 1 - дописать функцию onChangeTextCallback в SuperPagination
* 2 - дописать функцию sendQuery в HW14
* 3 - дописать функцию onChangeText в HW14
* 4 - сделать стили в соответствии с дизайном
* 5 - добавить HW14 в HW5/pages/JuniorPlus
* */
const getTechs = (find: string) => {
return axios
.get<{techs: string[]}>(
'https://incubator-personal-page-back.herokuapp.com/api/3.0/homework/test2',
{params: {find}}
)
.catch((e) => {
alert(e.response?.data?.errorText || e.message)
})
}
const HW14 = () => {
const [find, setFind] = useState('')
const [searchParams, setSearchParams] = useSearchParams()
const [techs, setTechs] = useState<string[]>([])
const sendQuery = (value: string) => {
getTechs(value)
.then((res) => {
// делает студент
if (res) setTechs(res.data.techs)
//
})
}
const onChangeText = (value: string) => {
setFind(value)
// делает студент
const findQuery: {find?: string} = value ? {find: value} : {} // если нет - то не записывать в урл
const {find, ...lastQueries} = Object.fromEntries(searchParams)
setSearchParams({...lastQueries, ...findQuery})
//
}
useEffect(() => {
const params = Object.fromEntries(searchParams)
sendQuery(params.find || '')
setFind(params.find || '')
}, [])
const mappedTechs = techs.map(t => (
<div key={t} id={'hw14-tech-' + t} className={s.tech}>
{t}
</div>
))
return (
<div id={'hw14'}>
<div className={s2.hwTitle}>Homework #14</div>
<div className={s2.hw}>
<SuperDebouncedInput
id={'hw14-super-debounced-input'}
value={find}
onChangeText={onChangeText}
onDebouncedChange={sendQuery}
/>
{mappedTechs}
</div>
</div>
)
}
export default HW14