Skip to content

Commit b17ad68

Browse files
committed
feat: upload details, style tweaks
1 parent e2e57de commit b17ad68

File tree

4 files changed

+73
-30
lines changed

4 files changed

+73
-30
lines changed

src/layouts/default.astro

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,22 @@ const nav = [
172172
</style>
173173

174174
<style is:global>
175+
* {
176+
box-sizing: border-box;
177+
}
178+
175179
.upload {
176180
background: color-mix(in oklab, var(--orange-600), var(--bg) 95%);
177181
border: 1px solid color-mix(in oklab, var(--orange-600), var(--bg) 40%);
178182
border-radius: 0.5rem;
179-
margin-block-end: 3rem;
183+
margin-block-end: 1rem;
180184
padding: 1.5rem;
181185
text-align: center;
182-
width: 100cqi;
186+
inline-size: 100cqi;
187+
188+
div + & {
189+
margin-block-start: 1rem;
190+
}
183191
}
184192

185193
.gallery {
@@ -199,7 +207,7 @@ const nav = [
199207
flex-direction: column;
200208
inline-size: max-content;
201209
justify-content: center;
202-
max-inline-size: 200px;
210+
max-inline-size: calc(200px + 3rem + 2px);
203211
padding: 1.5rem;
204212
text-align: center;
205213

@@ -214,18 +222,50 @@ const nav = [
214222
}
215223

216224
& img {
217-
height: auto;
218-
width: 200px;
225+
block-size: auto;
226+
inline-size: 200px;
219227
margin-inline: auto;
220228
}
221229

222230
&.double img {
223231
inline-size: 300px;
224232
}
233+
}
234+
235+
:is(.error, .success) {
236+
background: color-mix(in oklch, var(--color), var(--bg) 80%);
237+
border: 1px solid var(--color);
238+
border-radius: 0.5rem;
239+
inline-size: 100cqi;
240+
padding: 1.5rem;
241+
text-align: center;
242+
243+
& :is(h3, p, pre) {
244+
margin: 0;
245+
}
225246

226-
& pre {
247+
& h3 {
248+
inline-size: 100%;
249+
margin-block: 0;
250+
text-align: left;
251+
}
252+
253+
pre {
227254
font-size: 0.875rem;
255+
inline-size: 100%;
256+
margin: 0 auto;
257+
overflow-x: scroll;
258+
padding: 0.5rem 1.5rem;
228259
text-align: left;
260+
white-space: pre-wrap;
229261
}
230262
}
263+
264+
.error {
265+
--color: red;
266+
}
267+
268+
.success {
269+
--color: green;
270+
}
231271
</style>

src/pages/01-basic.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cloudinary.config({
99
api_secret: import.meta.env.CLOUDINARY_API_SECRET,
1010
});
1111
12-
const banner = cloudinary.url('cloudinary-images/tagging-test.jpg');
12+
const banner = cloudinary.url('cloudinary-images/jason.jpg');
1313
---
1414

1515
<Layout>

src/pages/04-user-uploads.astro

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const uploadStream = async (buffer: Uint8Array) => {
3434
let uploadedFile: any | undefined;
3535
let banner;
3636
let thumb;
37+
let public_id;
3738
let alt;
3839
3940
if (Astro.request.method === 'POST') {
@@ -48,7 +49,7 @@ if (Astro.request.method === 'POST') {
4849
}
4950
5051
if (uploadedFile && uploadedFile.public_id) {
51-
const public_id = uploadedFile.public_id;
52+
public_id = uploadedFile.public_id;
5253
alt = uploadedFile.info?.detection?.captioning?.data?.caption ?? '';
5354
5455
const base_transformation: TransformationOptions = {
@@ -72,6 +73,15 @@ if (uploadedFile && uploadedFile.public_id) {
7273
<Layout>
7374
<h1>04. User Uploads</h1>
7475

76+
{
77+
uploadedFile ? (
78+
<div class="success">
79+
<h3>Upload Details</h3>
80+
<pre>{JSON.stringify({ public_id, alt }, null, 2)}</pre>
81+
</div>
82+
) : null
83+
}
84+
7585
<form method="post" enctype="multipart/form-data" class="upload">
7686
<label for="file">Upload your photo:</label>
7787
<input type="file" name="file" id="file" accept="image/*" required />
@@ -109,6 +119,8 @@ if (uploadedFile && uploadedFile.public_id) {
109119
.uploads {
110120
display: flex;
111121
gap: 3rem;
122+
inline-size: 100cqi;
123+
justify-content: space-between;
112124
}
113125

114126
.image {

src/pages/05-moderation.astro

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const uploadStream = async (buffer: Uint8Array) => {
3737
3838
let uploadedFile: any | undefined;
3939
let moderationStatus;
40+
let public_id;
4041
let alt;
4142
4243
if (Astro.request.method === 'POST') {
@@ -51,6 +52,7 @@ if (Astro.request.method === 'POST') {
5152
}
5253
5354
if (uploadedFile && uploadedFile.public_id) {
55+
public_id = uploadedFile.public_id;
5456
alt = uploadedFile.info?.detection?.captioning?.data?.caption ?? '';
5557
5658
moderationStatus = uploadedFile.moderation.at(0).status;
@@ -87,6 +89,15 @@ const gallery = uploads.map((upload) => {
8789
) : null
8890
}
8991

92+
{
93+
uploadedFile ? (
94+
<div class="success">
95+
<h3>Upload Details</h3>
96+
<pre>{JSON.stringify({ public_id, alt }, null, 2)}</pre>
97+
</div>
98+
) : null
99+
}
100+
90101
<form method="post" enctype="multipart/form-data" class="upload">
91102
<label for="file">Upload your photo:</label>
92103
<input type="file" name="file" id="file" required />
@@ -108,41 +119,21 @@ const gallery = uploads.map((upload) => {
108119
))
109120
}
110121
</div>
111-
112-
{
113-
uploadedFile ? (
114-
<pre style="max-width: 100vw">
115-
{JSON.stringify(uploadedFile, null, 2)}
116-
</pre>
117-
) : null
118-
}
119122
</Layout>
120123

121124
<style>
122-
.error {
123-
background: color-mix(in oklch, red, var(--bg) 92%);
124-
border: 1px solid red;
125-
border-radius: 0.25rem;
126-
padding: 1.5rem;
127-
text-align: center;
128-
width: 100cqi;
129-
130-
& p {
131-
margin: 0;
132-
}
133-
}
134-
135125
.uploads {
136126
display: flex;
137127
flex-wrap: wrap;
138128
gap: 3rem;
129+
inline-size: 100cqi;
139130
justify-content: center;
140131
}
141132

142133
.image {
143134
border: 1px solid color-mix(in oklch, var(--orange-600), transparent 60%);
144135
border-radius: 0.5rem;
145-
max-inline-size: 150px;
136+
max-inline-size: calc(150px + 3rem + 2px);
146137
padding: 1.5rem;
147138
}
148139
</style>

0 commit comments

Comments
 (0)