mirror of
https://github.com/IgnatZakalinsky/home-works.git
synced 2026-02-03 20:42:04 +00:00
add hw 14-15 for design
This commit is contained in:
84
src/s2-homeworks/hw14/HW14.tsx
Normal file
84
src/s2-homeworks/hw14/HW14.tsx
Normal 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
|
||||
Reference in New Issue
Block a user