-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
113 lines (100 loc) · 3.15 KB
/
Copy pathApp.js
File metadata and controls
113 lines (100 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React, { useEffect, useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import "./App.scss";
//Redux actions
import { applyTheme } from "./redux/theme/themeActions";
import { applyFullscreen } from "./redux/fullscreen/fullscreenActions";
import { setColumnCount } from "./redux/column/columnCount/columnCountActions";
//Components
import { Scrollbar } from "./components/Scrollbar/Scrollbar";
import { AddBtn } from "./components/AddBtn/AddBtn";
import { Header } from "./components/Header/Header";
import { BaseColumn } from "./components/Columns/BaseColumn";
import { Column } from "./components/Columns/Column";
//Mobile adaptation
import { isMobileOnly, isBrowser, isTablet } from "react-device-detect";
//Animations
import { animated, useSpring, config } from "react-spring";
import { useHeight } from "./hooks/useHeight";
function App() {
const dispatch = useDispatch();
//Theme
const darkTheme = useSelector((state) => state.theme.darkTheme);
const changeTheme = (theme) => {
dispatch(applyTheme(theme));
};
//Screen mode
const fullscreen = useSelector((state) => state.fullscreen.fullscreen);
const changeMode = (fullscreen) => {
dispatch(applyFullscreen(fullscreen));
};
//TODO: remove me
let testArr = [
{ value: "EUR", name: "Euro", icon: "€" },
{ value: "RUB", name: "Russian Ruble", icon: "₽" },
{ value: "USD", name: "US Dollar", icon: "$" },
];
//Normal columns options
const [columns, setColumns] = useState([Math.random()]);
//Column remove
const [canRemove, setCanRemove] = useState(false);
useEffect(() => {
dispatch(setColumnCount(columns.length));
}, [columns.length]);
const addColumn = () => {
setColumns([...columns, Math.random()]);
};
const removeColumn = (id) => {
setColumns(columns.filter((item) => item !== id));
};
useEffect(() => {
console.log(columns);
}, [columns]);
useEffect(() => {
if (isMobileOnly) {
changeMode(true);
}
}, []);
//Column mode
const twoColumn = useSelector((state) => state.twoColumn.twoColumn);
//ANim
const [heightRef, height] = useHeight();
return (
<Scrollbar>
<div
className={`App ${darkTheme ? "dark" : "light"} ${
fullscreen ? "fullscreen" : ""
}`}
>
<section
className={`surface ${fullscreen ? "fullscreen" : ""} ${
isMobileOnly ? "mobile" : ""
}`}
>
<Header fullscreen={fullscreen} />
<main
className={`content ${isMobileOnly ? "mobile" : ""} ${
twoColumn ? "two-column" : ""
}`}
ref={heightRef}
>
<BaseColumn fullscreen={fullscreen} />
{columns.map((item) => {
return (
<Column
key={item}
fullscreen={fullscreen}
remove={() => removeColumn(item)}
/>
);
})}
{(isBrowser || isTablet) && (
<AddBtn onClick={addColumn} ariaLabel="Add column" />
)}
</main>
</section>
</div>
</Scrollbar>
);
}
export default App;