Skip to content

Commit 0c78095

Browse files
committed
chore: image widget styles
1 parent 96c7476 commit 0c78095

File tree

5 files changed

+46
-28
lines changed

5 files changed

+46
-28
lines changed
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { AuthContext } from '../AuthContext';
33

44
interface ProtectedRouteProps {
55
children: React.ReactNode;
66
}
77

88
export const ProtectedRoute: React.FC<ProtectedRouteProps> = (props) => {
9-
const { isAuthenticated, isLoading, logIn } = React.useContext(AuthContext);
9+
const { isAuthenticated, isLoading, logIn, logOut, isLoggedOut } = React.useContext(AuthContext);
10+
11+
useEffect(() => {
12+
if(isLoading) {
13+
return
14+
}
15+
16+
if(!isAuthenticated || isLoggedOut) {
17+
logOut().then(logIn)
18+
}
19+
20+
}, [isAuthenticated, isLoading, logIn, logOut, isLoggedOut])
1021

1122
if (isLoading) {
1223
return <div>Loading User....</div>;
1324
}
1425

15-
if (!isAuthenticated && !isLoading) {
16-
logIn();
17-
return null;
18-
}
19-
2026
return <>{props.children}</>;
2127
};

packages/frontend/config/webpack/webpack.config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ interface Configuration extends WebpackConfiguration {
1515

1616
const createConfig = ({
1717
dirname,
18-
isProduction
19-
}: {dirname: string, isProduction: boolean}): Configuration => {
18+
isProduction,
19+
analyse
20+
}: {dirname: string, isProduction: boolean, analyse?: boolean}): Configuration => {
2021
const env = createWebpackEnv({
21-
ANALYSE: false,
22+
ANALYSE: analyse || false,
2223
NODE_ENV: isProduction ? "production" : "development"
2324
})
25+
2426
const paths = createWebpackPaths(dirname)
2527
const plugins = createWebpackPlugins(env, paths)
2628

2729
const config: Configuration = {
28-
mode: isProduction ? 'production' : 'development',
30+
mode: isProduction ? 'production' : 'development',
2931
entry: './src/index.tsx',
3032
output: {
3133
path: path.resolve(dirname, 'dist'),
@@ -44,17 +46,23 @@ const createConfig = ({
4446
{
4547
test: /\.scss$/,
4648
use: [
47-
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
48-
'css-loader',
49+
MiniCssExtractPlugin.loader,
50+
{
51+
loader: 'css-loader',
52+
options: { importLoaders: 1 }, // make imports go through postcss
53+
},
4954
'postcss-loader',
5055
'sass-loader',
5156
],
5257
},
5358
{
5459
test: /\.css$/,
5560
use: [
56-
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
57-
'css-loader',
61+
MiniCssExtractPlugin.loader,
62+
{
63+
loader: 'css-loader',
64+
options: { importLoaders: 1 }, // make imports go through postcss
65+
},
5866
'postcss-loader',
5967
],
6068
},
@@ -89,14 +97,12 @@ const createConfig = ({
8997
},
9098
}
9199

92-
if (isProduction) {
93-
config.plugins?.push(
100+
config.plugins?.push(
94101
new MiniCssExtractPlugin({
95102
filename: '[name].[contenthash].css',
96103

97104
})
98105
);
99-
}
100106

101107
return config
102108
};

packages/frontend/ui/src/components/ImageUploader/Row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function ItemRow({ item, onCancel }: { item: UploadItem; onCancel: () =>
3131
const humanEta = item.etaSec ? `${item.etaSec}s` : "";
3232

3333
return (
34-
<Card className="my-3">
34+
<Card className="mb-2">
3535
<Flex align="center" gap="3">
3636
<img
3737
src={item.previewUrl}

packages/frontend/ui/src/components/ImageUploader/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export function MaistroImageUploader({
5050
state: "QUEUED",
5151
progress: 0,
5252
});
53-
54-
setItems((prev) => [...next, ...prev]);
5553
}
54+
55+
setItems((prev) => [...next, ...prev]);
5656
}
5757

5858
const handleUpload = async (id: string) => {
@@ -116,8 +116,9 @@ export function MaistroImageUploader({
116116
xhr.onload = async () => {
117117
if (xhr.status >= 200 && xhr.status < 300) {
118118
// S3 usually returns 204 for successful POST
119-
setItems((cur) => updateItem(cur, id, { state: "PROCESSING", progress: 100, xhr: undefined, s3Key }));
120-
// 3) Manually trigger resize in your API
119+
setItems((item) => updateItem(item, id, { state: "DONE", progress: 100, xhr: undefined, s3Key }));
120+
121+
// 3) Manually trigger resize
121122
const reponse = await resizeImage({
122123
url: `${apiBaseUrl}/resize`,
123124
key: `${ownerType === "user" ? "users" : "businesses"}/${ownerId}/${response.ImageId}/original.bin`,
@@ -157,7 +158,9 @@ export function MaistroImageUploader({
157158
});
158159
};
159160

160-
const clearDone = () => setItems((cur) => cur.filter((x) => x.state !== "DONE" && x.state !== "CANCELED"));
161+
const clearDone = () => {
162+
setItems([]);
163+
}
161164

162165
const totalPct = React.useMemo(() => {
163166
if (items.length === 0) {
@@ -173,7 +176,6 @@ export function MaistroImageUploader({
173176
return Math.round(sum / active.length);
174177
}, [items]);
175178

176-
// TODO fix flow, resizing works but UI doesn't reflect it
177179
return (
178180
<Theme appearance="light" accentColor="crimson" grayColor="sand" radius="large" scaling="100%">
179181
<Card
@@ -193,7 +195,7 @@ export function MaistroImageUploader({
193195
<Button variant="solid" onClick={() => inputRef.current?.click()} style={{ background: "#FF3366" }}>
194196
Seleccionar archivos
195197
</Button>
196-
<Button variant="soft" onClick={startAll}>Subir & procesar</Button>
198+
<Button variant="soft" onClick={startAll}>Subir</Button>
197199
<Button variant="ghost" onClick={clearDone}>Limpiar</Button>
198200
</Flex>
199201
</Flex>
@@ -224,8 +226,8 @@ export function MaistroImageUploader({
224226
</Box>
225227

226228
<Flex className="py-6" direction="column">
227-
{items.map((it) => (
228-
<ItemRow key={it.id} item={it} onCancel={() => cancelItem(it.id)} />
229+
{items.map((item, index) => (
230+
<ItemRow key={`${item.id}-${index}`} item={item} onCancel={() => cancelItem(item.id)} />
229231
))}
230232
{items.length === 0 && (
231233
<Text className="py-3" color="gray">No hay archivos aún. Usa “Seleccionar archivos” o arrastra aquí.</Text>

packages/frontend/ui/src/styles/global.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@import '@radix-ui/themes/styles.css';
22

3+
@tailwind base;
4+
@tailwind components;
5+
@tailwind utilities;
6+
37

48
:root {
59
--maistro-black: #000000;

0 commit comments

Comments
 (0)