Festalist.svelte
3.74 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
<script>
import { fly } from 'svelte/transition'
import SideBar from './SideBar.svelte';
let icon_show = true;
let sidebar_show = false;
function showBar() {
sidebar_show = true;
}
function hide() {
if (window.scrollY < 400) {
icon_show = true;
} else {
icon_show = false;
sidebar_show = false;
}
}
import { District, City, Changed } from '../Stores/DistrictStore';
import { AllFestas } from "../Stores/AllFestas";
import { DisplayedFestas } from "../Stores/DisplayedFestas";
let festaChecked = [];
$: festaList = $AllFestas.filter( v => {
if(v.addr1) {
let district = v.addr1.split(" ")[0];
let city = v.addr1.split(" ")[1];
return ($District === "" || district === $District) &&
($City === "" || city === $City);
} else {
return false;
}
});
$: festaParsed = festaList.map( (v, i) => {
return { "id" : i, "title" : v.title, "addr1" : v.addr1, "contentid" : v.contentid, "checked" : false }
});
$: if ($Changed) {
let len = festaList.length >= 9 ? 9 : festaList.length;
festaChecked = [];
for(let i = 0; i < len; i++)
check(i);
}
$: DisplayedFestas.set(festaChecked);
function check(idx) {
if (!festaParsed[idx].checked) {
if(festaChecked.length <= 8) {
festaParsed[idx].checked = true;
festaChecked = festaChecked.concat(festaList[idx]);
} else {
alert("9개 이상 선택하실 수 없습니다.");
}
} else {
festaParsed[idx].checked = false;
festaChecked = festaChecked.filter( v => {
return v.contentid !== festaParsed[idx].contentid;
});
}
}
</script>
<style>
.sidebtn {
border-radius: 5px;
border: 0px;
width: 70px;
height: 70px;
position: fixed;
left: -20px;
top: 200px;
padding-right: 10px;
text-align: right;
background-color: #e65100;
color: #ffffff;
box-shadow: 0 10px 20px rgb(0 0 0 / 15%);
}
.sidebtn:focus {
background-color: #f57c00;
}
.sidebtn:hover {
background-color: #ef6c00;
}
.festa {
border: 1px solid #aaa;
border-radius: 2px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
padding: 2px;
margin-bottom: 5px;
}
.festa:hover {
background-color: #fff3e0;
}
.festa:focus {
background-color: #ffe0b2;
}
.selected {
background-color: #ffe0b2;
border: 1px solid #aaa;
border-radius: 2px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
padding: 2px;
margin-bottom: 5px;
}
.title {
font-weight: bold;
border-bottom: 2px solid #ff3e00;
}
.addr {
display: flex;
align-items: center;
}
.addr img {
width: 20px;
height: 20px;
}
</style>
<svelte:window on:scroll={hide}></svelte:window>
{#if (icon_show)}
<button class="sidebtn"
transition:fly="{{ x : -50, duration : 400}}"
on:click={showBar}>
행사<br>목록
</button>
{/if}
<SideBar bind:show={sidebar_show}>
{#if festaParsed.length > 0}
{#each festaParsed as festa}
<div class="{festa.checked ? "selected" : "festa"}"
on:click={() => {check(festa.id)}}>
<div class="title">{festa.title}</div>
<div class="addr"><img alt="pin" src="/public/map-pin.png"><div>{festa.addr1}</div></div>
</div>
{/each}
{:else}
개최되는 축제가 없습니다.
{/if}
</SideBar>