-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path+page.svelte
162 lines (145 loc) · 3.47 KB
/
+page.svelte
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
<script>
// Our cards array. We'll need to fill this with cards from our Kintone database...
let cards = [];
// Default color of red, and the text on each card.
let color = 'Red';
let title = '';
// A function to GET cards from our backend.
const getCards = async () => {
const cardsRequest = await fetch('/kintone', {
method: 'GET',
credentials: 'same-origin',
headers: {
'content-type': 'application/json'
}
});
const cardsInfo = await cardsRequest.json();
// Resetting our array in case the GET button is pressed multiple times.
cards.length = 0;
cardsInfo.forEach((card) => {
// TODO We need to add our cards to our card array here!
});
console.log(cards);
};
// Our POST request to our backend.
const addCard = async (addCardTitle, addCardColor) => {
try {
const cardsRequest = await fetch('/kintone', {
method: 'POST',
credentials: 'same-origin',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
title: addCardTitle,
color: addCardColor
})
});
const cardResponse = await cardsRequest.json();
// Reset the title value of our add card.
title = '';
// Re-GET the cards after we posted a new one!
getCards();
} catch (error) {
console.log(error);
}
};
</script>
<div class="main">
<div class="grid-container">
<div class="left">
<button on:click={getCards}> Get Cards </button>
<div class="card-row">
{#each cards as card, i}
<!-- TODO: Here, we'll need to loop through our cards Array, and display each card, with its title and color. -->
{/each}
</div>
</div>
<div class="right">
<button on:click={addCard(title, color)}> Add Card </button>
<div class:blue-card={color === 'Blue'} class:red-card={color === 'Red'}>
<input type="text" bind:value={title} placeholder="My Card Title" />
<label>
<input type="radio" bind:group={color} value="Red" name="addCard" />
Red
</label>
<label>
<input type="radio" bind:group={color} value="Blue" name="addCard" />
Blue
</label>
</div>
</div>
</div>
</div>
<style>
.main {
color: aliceblue;
}
.main p {
font-size: large;
}
.main label {
font-size: large;
}
.blue-card {
background-color: #2196f3;
/* Add shadows to create the "card" effect */
box-shadow: 0px 12px 16px 0px rgba(0, 0, 0, 0.3);
transition: 0.3s;
padding: 20px;
margin: 10px;
display: flex;
flex-direction: column;
align-items: baseline;
}
.red-card {
background-color: tomato;
/* Add shadows to create the "card" effect */
box-shadow: 0px 12px 16px 0px rgba(0, 0, 0, 0.3);
transition: 0.3s;
padding: 20px;
margin: 10px;
display: flex;
flex-direction: column;
align-items: baseline;
}
.red-card:hover {
box-shadow: 0px 16px 24px 0px rgba(0, 0, 0, 0.5);
}
.blue-card:hover {
box-shadow: 0px 16px 24px 0px rgba(0, 0, 0, 0.5);
}
.left {
grid-area: left;
display: flex;
flex-direction: column;
align-items: center;
}
.card-row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.right {
grid-area: right;
display: flex;
flex-direction: column;
align-items: center;
}
.grid-container {
display: grid;
grid-template-areas:
'header header header header'
'left left right right'
'footer footer footer footer';
gap: 10px;
background-color: #1e2931;
padding: 10px;
}
.grid-container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 10px 0;
font-size: 35px;
}
</style>