Skip to content

Commit 1f15d7e

Browse files
adaptive main page
1 parent eb5bf3b commit 1f15d7e

File tree

14 files changed

+276
-48
lines changed

14 files changed

+276
-48
lines changed

client/public/audio/end.mp3

37.3 KB
Binary file not shown.

client/public/img/screen_1.png

219 KB
Loading

client/public/img/screen_2.png

90.5 KB
Loading

client/public/img/screen_3.png

15.5 KB
Loading

client/src/components/Nav.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import logo from '/img/favicon_2.ico'
44
import { NavLink } from 'react-router-dom';
55

66
import { Links } from "@enums/Links.enum"
7+
import { useWindow } from '../hooks/useWindow.hook';
78

89
const NavComponent: FC = () => {
10+
11+
const window_size = useWindow();
12+
913
return (
1014
<nav>
1115
<NavLink id='logo' to={Links.MAIN_PAGE}><img src={logo} alt="logo" /></NavLink>
1216
<div id="a">
1317
<NavLink to={Links.MAIN_PAGE}>Главная</NavLink>
14-
<NavLink to={Links.REDACT}>Конструктор бюллетеней</NavLink>
18+
<NavLink to={Links.REDACT}>{window_size.width > 436 ? 'Конструктор бюллетеней' : 'Конструктор'}</NavLink>
1519
</div>
1620
</nav>
1721
)

client/src/hooks/useWindow.hook.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import { useState, useEffect } from "react";
3+
4+
interface WindowSize {
5+
width: number,
6+
height: number
7+
}
8+
9+
export const useWindow = () => {
10+
const [windowSize, setWindowSize] = useState<WindowSize>({
11+
width: window.innerWidth,
12+
height: window.innerHeight,
13+
});
14+
useEffect(()=> {
15+
const handleResize = () => {
16+
setWindowSize(prevSize => ({
17+
...prevSize,
18+
width: window.innerWidth,
19+
height: window.innerHeight,
20+
}));
21+
};
22+
23+
window.addEventListener('resize', handleResize);
24+
25+
return () => {
26+
window.removeEventListener('resize', handleResize);
27+
};
28+
}, []);
29+
return windowSize;
30+
}

client/src/pages/Main.page.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { FC } from 'react';
22
import '../sass/main_page.scss'
33
import "../sass/button.scss"
4-
4+
import { useNavigate } from 'react-router-dom';
5+
import { Links } from '@enums/Links.enum';
56

67
import BlockComponent from '@components/Block';
78

89
const MainPage:FC = () => {
910

11+
const navigate = useNavigate();
12+
1013
return (
1114
<>
1215
<main>
@@ -15,11 +18,8 @@ const MainPage:FC = () => {
1518
Конструктор бюллетеней - ваш верный помощник в создании бюллетеней для голосования на общих собраниях. <br />
1619
P.S. Ни в коем случае не пользуйтесь им, если Вы не цените свое время!
1720
</BlockComponent>
18-
<button id='main_button' type='button'>Смотреть ниже</button>
21+
<button onClick={() => navigate(Links.REDACT)} id='main_button' type='button'>Сгенерировать</button>
1922
</main>
20-
<div id="info">
21-
22-
</div>
2323
</>
2424
)
2525
}

client/src/pages/Result.page.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ const ResultPage: FC = () => {
5353
}, [general_info, various_data]);
5454

5555
const mutation = useMutation({
56+
onSuccess: () => {
57+
const end: HTMLAudioElement = new Audio();
58+
const end_src = `${import.meta.env.BASE_URL}audio/end.mp3`;
59+
end.src = end_src;
60+
end.volume = 0.3
61+
62+
if(!mutation.isPending && !mutation.isError) {
63+
end.play();
64+
}
65+
},
5666
mutationKey: ['docx'],
5767
mutationFn: async (data: FullInfo): Promise<Blob | undefined> => {
5868
const res = await fetch('/api/redact', {
@@ -136,6 +146,7 @@ const ResultPage: FC = () => {
136146
<button id='download' disabled={mutation.isError || mutation.isPending} onClick={handleDownload}>{mutation.isPending ? 'Генерация...' : 'Скачать'}</button>
137147
<p className='validate_error'>{mutation.error && mutation.error.message}</p>
138148
</div>
149+
139150
{!mutation.isError && <span>Ваши бюллетени успешно сгенерировались. В случае каких-либо неисправностей прошу Вас написать нам
140151
сюда: <code>ivan.minevskiy@yandex.ru</code> .
141152
</span>}

client/src/pages/Various.page.tsx

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,55 @@ const Various_page: FC = () => {
1919
const general_info = useSelector((state: RootState) => state.general_info.general_info)
2020
const isValid = useSelector((state: RootState) => state.various_info.isValid)
2121

22-
const [forms, setForms] = useState<FormProps[]>([])
22+
const [forms, setForms] = useState<FormProps[]>([]);
23+
const [yesLimit, setYesLimit] = useState<boolean>(true);
2324

2425
interface FormProps {
2526
id: number,
2627
}
2728

28-
const deleteForm = useCallback((id: number) => {
29-
setForms(prevForms => prevForms.filter((form) => form.id !== id));
30-
}, []);
31-
32-
useEffect(() => {
33-
const defaultForms = () => {
34-
const newForms: FormProps[] = [];
35-
for (let i = 1; i < 6; i++) {
36-
newForms.push({id: i});
37-
}
38-
setForms(newForms);
39-
}
40-
defaultForms()
41-
}, [])
42-
43-
useEffect(() => {
44-
// Проверяем, все ли формы валидны, когда меняется isValid
45-
if (isValid.length > 0) {
46-
const allFormsValid = isValid.every(item => item === true);
47-
setIsValidForms(allFormsValid);
48-
} else {
49-
setIsValidForms(false); // Если isValid пуст, считаем, что формы не валидны
50-
}
51-
}, [isValid]);
52-
53-
54-
const addForm = () => {
55-
const newId = forms.length + 1; // Генерируем уникальный id для новой формы
56-
setForms(prevForms => [...prevForms, {id: newId}]);
29+
const deleteForm = useCallback((id: number) => {
30+
setForms(prevForms => prevForms.filter((form) => form.id !== id));
31+
}, []);
32+
33+
useEffect(() => {
34+
const change_limit = general_info.number_questions * forms.length;
35+
36+
if(change_limit > 300) {
37+
setYesLimit(false)
38+
} else {
39+
setYesLimit(true)
40+
}
41+
}, [forms.length])
42+
43+
useEffect(() => {
44+
const defaultForms = () => {
45+
const newForms: FormProps[] = [];
46+
for (let i = 1; i < 6; i++) {
47+
newForms.push({ id: i });
5748
}
49+
setForms(newForms);
50+
}
51+
defaultForms()
52+
}, [])
53+
54+
useEffect(() => {
55+
// Проверяем, все ли формы валидны, когда меняется isValid
56+
if (isValid.length > 0) {
57+
const allFormsValid = isValid.every(item => item === true);
58+
setIsValidForms(allFormsValid);
59+
} else {
60+
setIsValidForms(false); // Если isValid пуст, считаем, что формы не валидны
61+
}
62+
}, [isValid]);
63+
64+
65+
const addForm = () => {
66+
const newId = forms.length + 1; // Генерируем уникальный id для новой формы
67+
setForms(prevForms => [...prevForms, { id: newId }]);
68+
}
69+
5870

59-
6071

6172

6273
return (
@@ -65,16 +76,16 @@ const Various_page: FC = () => {
6576

6677
{
6778
forms.map((form, index) =>
68-
<Form key={form.id} id={form.id} num={index + 1} onDelete={deleteForm}/>
69-
)
79+
<Form key={form.id} id={form.id} num={index + 1} onDelete={deleteForm} />
80+
)
7081
}
7182
<div className="center">
72-
<button className='send_various' onClick={() => navigate(Links.REDACT)}>Назад</button>
73-
<button onClick={addForm} className='send_various'>+ участник</button>
74-
<button className='send_various next' type="button" onClick={(e) => {
75-
e.preventDefault();
76-
dispatch(setIsClick());
77-
}}>Далее</button>
83+
<button className='send_various' onClick={() => navigate(Links.REDACT)}>Назад</button>
84+
<button disabled={!yesLimit} onClick={addForm} className='send_various'>+ участник</button>
85+
<button className='send_various next' type="button" onClick={(e) => {
86+
e.preventDefault();
87+
dispatch(setIsClick());
88+
}}>Далее</button>
7889
</div>
7990
</>
8091
)

client/src/sass/block.scss

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,54 @@ span {
2020
font-family: Arial, sans-serif;
2121
}
2222

23+
@media screen and (max-width: 1700px) {
24+
#block {
25+
width: 1000px !important;
26+
}
27+
}
28+
@media screen and (max-width: 1300px) {
29+
#block {
30+
width: 800px !important;
31+
}
32+
}
33+
@media screen and (max-width: 900px) {
34+
#block {
35+
width: 700px !important;
36+
span {
37+
font-size: 20px;
38+
}
39+
}
40+
}
41+
@media screen and (max-width: 750px) {
42+
#block {
43+
width: 500px !important;
44+
margin-bottom: 0;
45+
}
46+
}
47+
@media screen and (max-width: 530px) {
48+
#block {
49+
width: 400px !important;
50+
margin-bottom: 10px !important;
51+
}
52+
}
53+
@media screen and (max-width: 430px) {
54+
#block {
55+
width: 300px !important;
56+
}
57+
}
58+
@media screen and (max-width: 310px) {
59+
#block {
60+
width: 200px !important;
61+
span {
62+
font-size: 15px !important;
63+
}
64+
}
65+
}
66+
@media screen and (max-width: 250px) {
67+
#block {
68+
width: 100px !important;
69+
span {
70+
font-size: 10px !important;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)