Skip to content

Commit 3dac646

Browse files
committed
Convert to variable holding arrow function
1 parent 60b0456 commit 3dac646

File tree

2 files changed

+84
-98
lines changed

2 files changed

+84
-98
lines changed

todo-frontend/ui/src/TodoList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface Todo {
2020
finished: boolean;
2121
}
2222

23-
function TodoList() {
23+
const TodoList = () => {
2424
const [todos, setTodos] = useState<Todo[]>([]);
2525
const [username, setUsername] = useState<string>('');
2626
const [csrfToken, setCsrfToken] = useState<string>('');
@@ -218,6 +218,6 @@ function TodoList() {
218218
</StyledTable>
219219
</Container>
220220
);
221-
}
221+
};
222222

223223
export default TodoList;

todo-frontend/ui/src/components.tsx

Lines changed: 82 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@ interface ContainerProps {
55
children: ReactNode;
66
}
77

8-
function Container({children}: ContainerProps) {
9-
return (
10-
<div style={{maxWidth: '800px', margin: '0 auto', fontFamily: 'Arial, sans-serif'}}>
11-
{children}
12-
</div>
13-
);
14-
}
8+
const Container = ({children}: ContainerProps) => (
9+
<div style={{maxWidth: '800px', margin: '0 auto', fontFamily: 'Arial, sans-serif'}}>
10+
{children}
11+
</div>
12+
);
1513

1614
// Header component for title
1715
interface HeaderProps {
1816
children: ReactNode;
1917
}
2018

21-
function Header({children}: HeaderProps) {
22-
return (
23-
<h1 style={{textAlign: 'center', color: '#333', marginBottom: '20px'}}>
24-
{children}
25-
</h1>
26-
);
27-
}
19+
const Header = ({children}: HeaderProps) => (
20+
<h1 style={{textAlign: 'center', color: '#333', marginBottom: '20px'}}>
21+
{children}
22+
</h1>
23+
);
2824

2925
// Styled button with hover effect
3026
interface StyledButtonProps {
@@ -34,29 +30,27 @@ interface StyledButtonProps {
3430
style?: CSSProperties;
3531
}
3632

37-
function StyledButton({children, onClick, type = 'button', style}: StyledButtonProps) {
38-
return (
39-
<button
40-
type={type}
41-
onClick={onClick}
42-
style={{
43-
padding: '10px 20px',
44-
fontSize: '16px',
45-
backgroundColor: '#28a745',
46-
color: '#fff',
47-
border: 'none',
48-
borderRadius: '4px',
49-
cursor: 'pointer',
50-
transition: 'background-color 0.3s',
51-
...style,
52-
}}
53-
onMouseEnter={(e) => (e.currentTarget.style.backgroundColor = '#218838')}
54-
onMouseLeave={(e) => (e.currentTarget.style.backgroundColor = '#28a745')}
55-
>
56-
{children}
57-
</button>
58-
);
59-
}
33+
const StyledButton = ({children, onClick, type = 'button', style}: StyledButtonProps) => (
34+
<button
35+
type={type}
36+
onClick={onClick}
37+
style={{
38+
padding: '10px 20px',
39+
fontSize: '16px',
40+
backgroundColor: '#28a745',
41+
color: '#fff',
42+
border: 'none',
43+
borderRadius: '4px',
44+
cursor: 'pointer',
45+
transition: 'background-color 0.3s',
46+
...style,
47+
}}
48+
onMouseEnter={(e) => (e.currentTarget.style.backgroundColor = '#218838')}
49+
onMouseLeave={(e) => (e.currentTarget.style.backgroundColor = '#28a745')}
50+
>
51+
{children}
52+
</button>
53+
);
6054

6155
// Small icon button for action controls (toggle and delete)
6256
interface IconButtonProps {
@@ -66,24 +60,22 @@ interface IconButtonProps {
6660
title: string;
6761
}
6862

69-
function IconButton({icon, color, onClick, title}: IconButtonProps) {
70-
return (
71-
<button
72-
onClick={onClick}
73-
title={title}
74-
style={{
75-
backgroundColor: 'transparent',
76-
border: 'none',
77-
cursor: 'pointer',
78-
fontSize: '16px',
79-
color,
80-
margin: '0 5px',
81-
}}
82-
>
83-
{icon}
84-
</button>
85-
);
86-
}
63+
const IconButton = ({icon, color, onClick, title}: IconButtonProps) => (
64+
<button
65+
onClick={onClick}
66+
title={title}
67+
style={{
68+
backgroundColor: 'transparent',
69+
border: 'none',
70+
cursor: 'pointer',
71+
fontSize: '16px',
72+
color,
73+
margin: '0 5px',
74+
}}
75+
>
76+
{icon}
77+
</button>
78+
);
8779

8880
// Input field for entering todo title
8981
interface StyledInputProps {
@@ -92,44 +84,40 @@ interface StyledInputProps {
9284
placeholder?: string;
9385
}
9486

95-
function StyledInput({value, onChange, placeholder}: StyledInputProps) {
96-
return (
97-
<input
98-
type="text"
99-
value={value}
100-
onChange={onChange}
101-
placeholder={placeholder}
102-
required={true}
103-
style={{
104-
padding: '10px',
105-
width: '70%',
106-
fontSize: '16px',
107-
border: '1px solid #ddd',
108-
borderRadius: '4px',
109-
marginRight: '10px',
110-
}}
111-
/>
112-
);
113-
}
87+
const StyledInput = ({value, onChange, placeholder}: StyledInputProps) => (
88+
<input
89+
type="text"
90+
value={value}
91+
onChange={onChange}
92+
placeholder={placeholder}
93+
required={true}
94+
style={{
95+
padding: '10px',
96+
width: '70%',
97+
fontSize: '16px',
98+
border: '1px solid #ddd',
99+
borderRadius: '4px',
100+
marginRight: '10px',
101+
}}
102+
/>
103+
);
114104

115105
// Table container with header and body styling
116106
interface StyledTableProps {
117107
children: ReactNode;
118108
}
119109

120-
function StyledTable({children}: StyledTableProps) {
121-
return (
122-
<table
123-
style={{
124-
width: '100%',
125-
borderCollapse: 'collapse',
126-
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
127-
}}
128-
>
129-
{children}
130-
</table>
131-
);
132-
}
110+
const StyledTable = ({children}: StyledTableProps) => (
111+
<table
112+
style={{
113+
width: '100%',
114+
borderCollapse: 'collapse',
115+
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
116+
}}
117+
>
118+
{children}
119+
</table>
120+
);
133121

134122
// Table cell component with optional width
135123
interface TableCellProps {
@@ -139,7 +127,7 @@ interface TableCellProps {
139127
width?: string;
140128
}
141129

142-
function TableCell({children, header = false, center = false, width}: TableCellProps) {
130+
const TableCell = ({children, header = false, center = false, width}: TableCellProps) => {
143131
const baseStyle: CSSProperties = {
144132
padding: '10px',
145133
textAlign: center ? 'center' : 'left',
@@ -156,20 +144,18 @@ function TableCell({children, header = false, center = false, width}: TableCellP
156144
) : (
157145
<td style={baseStyle}>{children}</td>
158146
);
159-
}
147+
};
160148

161149
// WelcomeMessage component to display the username
162150
interface WelcomeMessageProps {
163151
username: string;
164152
}
165153

166-
function WelcomeMessage({username}: WelcomeMessageProps) {
167-
return (
168-
<p style={{textAlign: 'center', fontSize: '18px', color: '#555'}}>
169-
Welcome, {username}!
170-
</p>
171-
);
172-
}
154+
const WelcomeMessage = ({username}: WelcomeMessageProps) => (
155+
<p style={{textAlign: 'center', fontSize: '18px', color: '#555'}}>
156+
Welcome, {username}!
157+
</p>
158+
);
173159

174160
export {
175161
Container,

0 commit comments

Comments
 (0)