-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_team.html
More file actions
448 lines (368 loc) · 12.7 KB
/
Copy pathcreate_team.html
File metadata and controls
448 lines (368 loc) · 12.7 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>팀 생성 페이지</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython_stdlib.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
background-color: #f2f2f2;
}
/* HEADER */
.header {
background-color: #ffffff;
height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
box-shadow: 0 1px 4px rgba(0,0,0,0.1);
position: fixed;
top: 0;
width: 100%;
z-index: 10;
}
.menu-button {
width: 24px;
height: 18px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.menu-button div {
background-color: #333;
height: 3px;
border-radius: 2px;
}
.menu {
background-color: white;
width: 100%;
position: fixed;
top: 50px;
left: 0;
z-index: 9;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.menu.show {
max-height: 300px;
}
.menu-item {
padding: 16px;
border-bottom: 1px solid #ddd;
text-decoration: none;
color: black;
display: block;
}
.header-title {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-weight: bold;
font-size: 14px;
}
.header-title a {
text-decoration: none;
color: #000;
}
.container {
max-width: 480px;
margin: 50px auto 0 auto; /* header 높이 고려 */
padding: 20px;
background-color: white;
min-height: calc(100vh - 50px);
box-sizing: border-box;
}
h2 {
text-align: center;
margin-bottom: 30px;
}
label {
display: block;
margin-top: 16px;
font-weight: bold;
}
label {
font-weight: bold;
margin-top: 16px;
display: block;
}
input[type="text"], input[type="url"] {
width: 100%;
padding: 10px;
margin-top: 6px;
margin-bottom: 10px;
border-radius: 6px;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 10px 16px;
border: none;
border-radius: 6px;
background-color: #007bff;
color: white;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.img-preview {
margin-top: 10px;
text-align: center;
}
.img-preview img {
max-width: 100%;
max-height: 200px;
border-radius: 10px;
}
.tag-section {
margin-top: 20px;
}
.tag-list {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 10px;
}
.tag-item {
background-color: #ddd;
padding: 6px 10px;
border-radius: 20px;
display: flex;
align-items: center;
}
.tag-item span {
margin-right: 6px;
}
.tag-item button {
background: #dc3545;
border: none;
border-radius: 50%;
width: 20px;
height: 20px;
color: white;
font-weight: bold;
padding: 0;
line-height: 20px;
cursor: pointer;
}
.tag-section div {
display: flex;
gap: 8px;
align-items: center; /* ✅ 버튼과 input 수직 가운데 정렬 */
}
/* + 버튼 스타일 수정 */
#add-tag {
background-color: #007bff;
color: white;
border: none;
padding: 0 12px; /* 좌우 패딩만 적용 */
height: 37.5px; /* ✅ input 높이에 맞춤 */
font-size: 20px;
line-height: 1;
border-radius: 6px;
cursor: pointer;
}
.btn {
width: 100%;
max-width: 480px;
margin: 10px auto;
padding: 12px 20px;
border: none;
border-radius: 8px;
color: white;
font-size: 16px;
text-align: center;
display: block;
cursor: pointer;
transition: background-color 0.2s ease;
}
.btn-blue {
background-color: #007bff;
}
.btn-blue:hover {
background-color: #0056b3;
}
.btn-green {
background-color: #28a745;
}
.btn-green:hover {
background-color: #1e7e34;
}
</style>
</head>
<body onload="brython()">
<!-- HEADER -->
<div class="header">
<div class="menu-button" id="hamburger">
<div></div>
<div></div>
<div></div>
</div>
<div class="header-title">
<a href="index.html">성격기반 랜덤여행</a>
</div>
</div>
<!-- DROPDOWN MENU -->
<div class="menu" id="menu">
<!-- 여기에 Brython이 동적으로 삽입할 내용이 들어감 -->
</div>
<!-- FORM -->
<div class="container">
<h2>새로운 팀 만들기</h2>
<label for="team-name">팀 이름</label>
<input type="text" id="team-name" placeholder="예: 자유로운 여행가들">
<label for="image-url">여행지 예시 이미지 URL</label>
<input type="text" id="image-url" placeholder="https://example.com/image.jpg">
<div class="img-preview" id="image-preview"></div>
<div class="tag-section">
<label for="tag-input">선호 팀원 태그</label>
<div style="display: flex; gap: 8px;">
<input type="text" id="tag-input" placeholder="예: 차분한, 활동적" style="flex: 1;">
<button type="button" id="add-tag">+</button>
</div>
<div class="tag-list" id="tag-list"></div>
</div>
<button class="btn btn-green" id="create-team-btn">팀 만들기</button>
</div>
<script type="text/python">
import json
from browser import document, html, alert, window
def setup_menu():
menu = document["menu"]
menu.clear()
user_info_str = window.sessionStorage.getItem("userInfo")
if user_info_str is None:
# 로그인 안 된 경우
menu <= html.A("회원가입", href="signup.html", Class="menu-item")
menu <= html.A("로그인", href="login.html", Class="menu-item")
else:
try:
user_info = json.loads(user_info_str)
name = user_info.get("name", "회원")
# 인사말 (텍스트만, 클릭 안 됨)
greet = html.SPAN(f"{name}님 반가워요", Class="menu-item")
greet.style.cursor = "default"
greet.style.marginRight = "10px"
menu <= greet
# 로그아웃 버튼
logout = html.A("로그아웃", href="#", Class="menu-item")
logout.bind("click", on_logout)
menu <= logout
except:
# 파싱 실패 시 강제 로그아웃
on_logout(None)
def on_logout(ev):
window.sessionStorage.removeItem("userInfo")
window.location.href = "index.html" # 메인 페이지로 이동
setup_menu()
def toggle_menu(event):
menu = document["menu"]
menu.classList.toggle("show")
document["hamburger"].bind("click", toggle_menu)
team_data = { #쿠키 데이터 딕셔너리
"teamName" : None,
"imgSrc" : None,
"tag" : [ ],
"userInfo" : { }
}
tag_data = [] #모든 태그
create_button = document["create-team-btn"]
team_name = document["team-name"]
image_url = document["image-url"]
def update_image_preview(ev):
url = document["image-url"].value.strip()
preview = document["image-preview"]
preview.clear()
if url:
preview <= html.IMG(src=url)
def add_tag(ev):
tag_input = document["tag-input"]
tag = tag_input.value.strip()
if tag: #태그 요소 만들기
tag_list = document["tag-list"]
tag_item = html.DIV(Class="tag-item")
tag_item <= html.SPAN(tag)
remove_btn = html.BUTTON("-")
tag_data.append(tag)
def remove_tag(e):
tag_data.remove(tag)
tag_item.remove()
remove_btn.bind("click", remove_tag)
tag_item <= remove_btn
tag_list <= tag_item
tag_input.value = ""
document["image-url"].bind("input", update_image_preview)
document["add-tag"].bind("click", add_tag)
def create_button_click(event):
all_ok = True
if team_name_check(team_name.value) == False:
all_ok = False
if url_check(image_url.value) == False:
all_ok = False
if tag_check(tag_data) == False:
all_ok = False
if all_ok == False: #정보가 제대로 적혀있지 않음
alert_meassage() #경고 메세지
return 0
team_data["teamName"] = team_name.value
team_data["imgSrc"] = image_url.value
team_data["tag"] = tag_data
team_data["userInfo"] = get_userInfo() #userinfo 넣기 (미구현)
save_cookie(team_data) #쿠키 처리 (미구현)
pass
create_button.bind("click", create_button_click)
def team_name_check(tn): #팀 이름 검사
if len(tn) == 0: #뭐라도 적어야함
return False
return True
def url_check(ur):
ur = ur.strip().lower()
if len(ur) <= 5:
return False
return ur
def tag_check(tg): #태그 체크
if len(tg) == 0: #태그가 하나는 있어야함
return False
return True
def get_userInfo(): #session Stroage 데이터 받아오기 (미구현)
if "userInfo" in window.sessionStorage:
return json.loads(window.sessionStorage["userInfo"])
return {}
def save_cookie(new_team):
cookies = window.document.cookie.split("; ")
team_list = []
for cookie in cookies:
if cookie.startswith("team-list="):
value = cookie[len("team-list="):]
try:
decoded = window.decodeURIComponent(value)
parsed = json.loads(decoded)
# 기존 쿠키가 dict 하나면 리스트로 바꿔줌
if isinstance(parsed, dict):
team_list = [parsed]
elif isinstance(parsed, list):
team_list = parsed
except:
team_list = []
team_list.append(new_team)
json_str = json.dumps(team_list)
encoded = window.encodeURIComponent(json_str)
window.document.cookie = f"team-list={encoded}; path=/;"
window.console.log("✅ 팀 저장 완료:", team_list)
alert("팀이 정상적으로 생성 되었습니다.\n메인페이지로 이동합니다.")
window.location.href = "index.html"
def alert_meassage():
alert("정보를 제대로 적어주세요")
</script>
</body>
</html>