-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathsample.tsx
More file actions
193 lines (178 loc) · 4.03 KB
/
Copy pathsample.tsx
File metadata and controls
193 lines (178 loc) · 4.03 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React, { useState, useEffect } from "react";
import styled from "styled-components";
interface Kevin {
id: number;
name: string;
wishlist: string[];
assignedKevin?: Kevin;
}
const Container = styled.div`
max-width: 800px;
margin: 0 auto;
padding: 20px;
font-family: 'Home Alone Sans', Arial, sans-serif;
`;
const Title = styled.h1`
color: #c41e3a; // Christmas red
text-align: center;
`;
const KevinCard = styled.div`
border: 2px solid #228B22; // Forest green
border-radius: 8px;
padding: 15px;
margin: 10px 0;
background: #fff;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
`;
const kevins: Kevin[] = [
{
id: 1,
name: "Kevin McCallister",
wishlist: ["BB Gun", "Pizza", "Micro Machines"],
},
{
id: 2,
name: "Kevin From Home Alone 2",
wishlist: ["Hotel Room", "Turtle Doves", "Camera"],
},
{
id: 3,
name: "Kevin From Work",
wishlist: ["Coffee Mug", "Stapler", "Post-its"],
},
{
id: 4,
name: "Evil Kevin",
wishlist: ["Paint Cans", "Hot Doorknobs", "Tar"],
},
{
id: 5,
name: "Future Kevin",
wishlist: ["Hoverboard", "Time Machine", "Robot Butler"],
},
];
const KevinSecretSanta: React.FC = () => {
const [assignedKevins, setAssignedKevins] = useState<Kevin[]>([]);
const [isShuffled, setIsShuffled] = useState(false);
const shuffleKevins = () => {
const shuffled = [...kevins];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
// Assign each Kevin to another Kevin
const assigned = shuffled.map((kevin, index) => ({
...kevin,
assignedKevin: shuffled[(index + 1) % shuffled.length],
}));
setAssignedKevins(assigned);
setIsShuffled(true);
};
return (
<Container>
<Title>🎄 Kevin's Secret Santa Exchange 🎅</Title>
<button
onClick={shuffleKevins}
style={{
padding: "10px 20px",
fontSize: "18px",
backgroundColor: !isShuffled ? "#c41e3a" : "#228B22",
color: "white",
border: "none",
borderRadius: "4px",
cursor: "pointer",
display: "block",
margin: "20px auto",
}}
>
{!isShuffled ? "Assign Secret Kevins!" : "Reassign Kevins!"}
</button>
{assignedKevins.map((kevin) => (
<KevinCard key={kevin.id}>
<h3>🎁 {kevin.name}</h3>
<p>
Will give a gift to: <strong>{kevin.assignedKevin?.name}</strong>
</p>
<p>Their wishlist:</p>
<ul>
{kevin.assignedKevin?.wishlist.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
</KevinCard>
))}
</Container>
);
};
export default KevinSecretSanta;
// Types for API endpoints
export interface SecretSantaApiResponse {
success: boolean;
assignments: {
giver: Kevin;
receiver: Kevin;
}[];
}
// API utility functions
export const fetchKevinAssignments =
async (): Promise<SecretSantaApiResponse> => {
// Simulated API call
return new Promise((resolve) => {
setTimeout(() => {
resolve({
success: true,
assignments: kevins.map((kevin, index) => ({
giver: kevin,
receiver: kevins[(index + 1) % kevins.length],
})),
});
}, 1000);
});
};
// A simple React component to display loading state
export class LoadingSpinner extends React.Component {
render() {
return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
padding: "20px",
}}
>
<div
style={{
width: "50px",
height: "50px",
border: "5px solid #f3f3f3",
borderTop: "5px solid #3498db",
borderRadius: "50%",
animation: "spin 1s linear infinite",
}}
/>
<style>
{`
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
`}
</style>
</div>
);
}
}
class MyClass {
constructor() {}
render() {
return (
<div>
<h1>My Component</h1>
</div>
);
}
}
const handleClick = () => {
console.log("Button clicked");
};