Skip to content

Commit 3e4fed3

Browse files
committed
resolve the cropIssues
1 parent 604cf94 commit 3e4fed3

File tree

8 files changed

+66
-88
lines changed

8 files changed

+66
-88
lines changed

apps/app/components/AppMenu/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ import {
1616
UsergroupAddOutlined,
1717
} from "@ant-design/icons";
1818
import { useAuth } from "@coderdojobraga/ui";
19-
import { EUser, IUser,API_URL } from "bokkenjs";
19+
import { API_URL, EUser, IUser } from "bokkenjs";
2020

2121
import styles from "./style.module.css";
2222

23-
24-
2523
const { SubMenu, Item } = Menu;
2624
const { Text, Title } = Typography;
2725

@@ -64,7 +62,11 @@ function AppMenu({ hidePrimaryMenu, collapsed }: any) {
6462
setSecondarySelectedKeys([key]);
6563
};
6664
let avatarSrc;
67-
if (!avatarPreview && typeof user?.photo === 'string' && user?.photo.startsWith('/uploads/')) {
65+
if (
66+
!avatarPreview &&
67+
typeof user?.photo === "string" &&
68+
user?.photo.startsWith("/uploads/")
69+
) {
6870
const previewUrl = `${API_URL}${user.photo}`;
6971
avatarSrc = previewUrl;
7072
} else {

apps/app/components/Profile/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as api from "bokkenjs";
2020
import * as socials from "~/lib/social";
2121
import { notifyError, notifyInfo } from "~/components/Notification";
2222
import styles from "./style.module.css";
23-
import { EUser, API_URL } from "bokkenjs";
23+
import { API_URL, EUser } from "bokkenjs";
2424

2525
import { BsFileEarmarkPersonFill } from "react-icons/bs";
2626

@@ -29,8 +29,6 @@ import { getIcon } from "~/lib/utils";
2929
const { TabPane } = Tabs;
3030
const { Title } = Typography;
3131

32-
33-
3432
interface Props {
3533
id: string;
3634
role: EUser;
@@ -102,7 +100,11 @@ function Profile({ id, role }: Props) {
102100
}, [info]);
103101

104102
let avatarSrc;
105-
if (!avatarPreview && typeof info?.photo === 'string' && info?.photo.startsWith('/uploads/')) {
103+
if (
104+
!avatarPreview &&
105+
typeof info?.photo === "string" &&
106+
info?.photo.startsWith("/uploads/")
107+
) {
106108
const previewUrl = `${API_URL}${info.photo}`;
107109
avatarSrc = previewUrl;
108110
} else {

apps/app/components/Register/index.tsx

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@ import {
2222
} from "@ant-design/icons";
2323
import { useAuth } from "@coderdojobraga/ui";
2424
import * as api from "bokkenjs";
25-
import {getBase64,getAvatarSrc} from "~/lib/images";
25+
import { getAvatarSrc, getBase64 } from "~/lib/images";
2626
import Emoji from "~/components/Emoji";
2727

2828
import styles from "./style.module.css";
2929
import { useState } from "react";
30-
import { EUser, API_URL } from "bokkenjs";
30+
import { API_URL, EUser } from "bokkenjs";
3131
import { notifyError, notifyInfo } from "~/components/Notification";
3232

3333
import { getIcon } from "~/lib/utils";
3434

3535
const [avatarPreview, setAvatarPreview] = useState<null | string>();
3636

37-
38-
39-
40-
4137
const { Option } = Select;
4238

4339
const CountrySelect = () => (
@@ -48,15 +44,13 @@ const CountrySelect = () => (
4844
</Select>
4945
);
5046

51-
52-
5347
function Register({ cities }: any) {
5448
const router = useRouter();
5549
const { Title } = Typography;
5650
const { user } = useAuth();
5751
const [isLoading, setLoading] = useState(false);
5852
const [errors, setErrors] = useState();
59-
const [avatar, setAvatar] = useState< void | File|string>();
53+
const [avatar, setAvatar] = useState<void | File | string>();
6054
const [socials] = useState([
6155
"Scratch",
6256
"Codewars",
@@ -67,7 +61,6 @@ function Register({ cities }: any) {
6761
"Slack",
6862
]);
6963

70-
7164
const onFinish = (values: any) => {
7265
console.log(avatar);
7366
values["user[photo]"] = avatar;
@@ -89,11 +82,12 @@ function Register({ cities }: any) {
8982
.finally(() => setLoading(false));
9083
};
9184

92-
93-
94-
9585
let avatarSrc;
96-
if (!avatarPreview && typeof user?.photo === 'string' && user?.photo.startsWith('/uploads/')) {
86+
if (
87+
!avatarPreview &&
88+
typeof user?.photo === "string" &&
89+
user?.photo.startsWith("/uploads/")
90+
) {
9791
const previewUrl = `${API_URL}${user.photo}`;
9892
avatarSrc = previewUrl;
9993
} else {
@@ -227,22 +221,22 @@ function Register({ cities }: any) {
227221
label="Foto de perfil"
228222
valuePropName="avatar"
229223
>
230-
<ImgCrop>
231-
<Upload
232-
accept="image/*"
233-
maxCount={1}
234-
beforeUpload={(file:File) => {
235-
setAvatar(file);
236-
getBase64(file, (result: string) => {
237-
setAvatarPreview(result);
238-
});
239-
return false;
240-
}}
241-
onRemove={() => setAvatar(user?.photo )}
242-
>
243-
<Button icon={<UploadOutlined />}>Upload</Button>
244-
</Upload>
245-
</ImgCrop>
224+
<ImgCrop>
225+
<Upload
226+
accept="image/*"
227+
maxCount={1}
228+
beforeUpload={(file: File) => {
229+
setAvatar(file);
230+
getBase64(file, (result: string) => {
231+
setAvatarPreview(result);
232+
});
233+
return false;
234+
}}
235+
onRemove={() => setAvatar(user?.photo)}
236+
>
237+
<Button icon={<UploadOutlined />}>Upload</Button>
238+
</Upload>
239+
</ImgCrop>
246240
</Form.Item>
247241
{user?.role == EUser.Mentor && (
248242
<Form.Item name="user[socials]" label="Redes Sociais">

apps/app/lib/images.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
export function getBase64(img:File, callback:Function) {
1+
export function getBase64(img: File, callback: Function) {
22
const reader = new FileReader();
33
reader.addEventListener("load", () => callback(reader.result));
44
reader.readAsDataURL(img);
55
}
66

7-
87
export function getAvatarSrc(
9-
avatarPreview: null | string | undefined ,
8+
avatarPreview: null | string | undefined,
109
userPhoto: string | undefined,
11-
API_URL: string | undefined,
10+
API_URL: string | undefined
1211
): string | undefined {
13-
if (typeof avatarPreview === 'undefined' && typeof userPhoto === 'string' && userPhoto.startsWith('/uploads/')) {
12+
if (
13+
typeof avatarPreview === "undefined" &&
14+
typeof userPhoto === "string" &&
15+
userPhoto.startsWith("/uploads/")
16+
) {
1417
const previewUrl = `${API_URL}${userPhoto}`;
15-
console.log('previewUrl', previewUrl);
18+
console.log("previewUrl", previewUrl);
1619
return previewUrl;
1720
} else {
1821
return userPhoto;
1922
}
2023
}
21-

apps/app/pages/admin/lectures/index.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,7 @@ function Lectures() {
240240
onOk={handleOk}
241241
onCancel={handleOk}
242242
>
243-
244-
245-
246-
{/* const PresenceList: React.FC<PresenceListProps> = ({ attendees }) => {
243+
{/* const PresenceList: React.FC<PresenceListProps> = ({ attendees }) => {
247244
const [presence, setPresence] = useState<boolean[]>(Array(attendees.length).fill(false));
248245
249246
const handlePresenceChange = (index: number) => {
@@ -271,24 +268,6 @@ function Lectures() {
271268
export default PresenceList;
272269
*/}
273270

274-
275-
276-
277-
278-
279-
280-
281-
282-
283-
284-
285-
286-
287-
288-
289-
290-
291-
292271
<Descriptions size="small" column={1} layout="horizontal">
293272
<Descriptions.Item
294273
labelStyle={labelStyle}

apps/app/pages/lectures/[role]/[id].tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function Lectures() {
9797
{moment(new Date(lecture.event.start_time)).format(
9898
"DD/MM/YYYY"
9999
)}
100-
</Text>1
100+
</Text>
101+
1
101102
</Col>
102103
</Row>
103104
<Row align="middle" gutter={[16, 16]}>

apps/app/pages/settings.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
PlusOutlined,
2323
UploadOutlined,
2424
} from "@ant-design/icons";
25-
import { getBase64, getAvatarSrc } from "~/lib/images";
25+
import { getAvatarSrc, getBase64 } from "~/lib/images";
2626
import { useAuth } from "@coderdojobraga/ui";
2727
import { notifyError, notifyInfo } from "~/components/Notification";
2828
import { getIcon } from "~/lib/utils";
@@ -67,9 +67,11 @@ function Settings() {
6767
const [formPersonal] = Form.useForm();
6868
const [formPassword] = Form.useForm();
6969
const [avatar, setAvatar] = useState<null | File | string>();
70-
const [avatarPreview, setAvatarPreview] = useState<null | string | undefined>();
70+
const [avatarPreview, setAvatarPreview] = useState<
71+
null | string | undefined
72+
>();
7173

72-
const [userSkills, setUserSkills] = useState<any[]>([]);
74+
const [userSkills, setUserSkills] = useState<any[]>([]);
7375
const [skills, setSkills] = useState<any[]>([]);
7476
const [selectedSkills, setSelectedSkills] = useState<any[]>([]);
7577
const [mentorSocials, setMentorSocials] = useState([]);
@@ -82,20 +84,20 @@ function Settings() {
8284
"Discord",
8385
"Slack",
8486
]);
85-
8687

8788
// const avatarSrc = getAvatarSrc(avatarPreview, user?.photo, API_URL);
8889
// if (avatarSrc !== avatarPreview) {
8990
// setAvatarPreview(avatarSrc);
9091
// }
9192

92-
if (!avatarPreview && typeof avatar === "string" && avatar.startsWith("/uploads/")) {
93-
console.log("avatar", API_URL+avatar);
93+
if (
94+
!avatarPreview &&
95+
typeof avatar === "string" &&
96+
avatar.startsWith("/uploads/")
97+
) {
98+
console.log("avatar", API_URL + avatar);
9499
setAvatarPreview(API_URL + avatar);
95100
}
96-
97-
98-
99101

100102
const onSubmit = (values: any) => {
101103
if (avatar) {
@@ -200,8 +202,6 @@ function Settings() {
200202
}
201203
};
202204

203-
204-
205205
const changeSkills = () => {
206206
const deleted = userSkills
207207
.map((skill: any) => skill.id)
@@ -241,9 +241,9 @@ function Settings() {
241241
useEffect(() => {
242242
if (user?.photo) {
243243
setAvatar(user?.photo);
244-
};
245-
getUserSkills();
246-
getAllSkills();
244+
}
245+
getUserSkills();
246+
getAllSkills();
247247
}, [user, getUserSkills]);
248248

249249
const breakpoints = {
@@ -288,19 +288,19 @@ function Settings() {
288288
<Space>
289289
<Avatar size={100} src={avatarPreview} />
290290
<Form.Item name="user[photo]">
291-
<ImgCrop>
291+
<ImgCrop>
292292
<Upload
293293
accept="image/*"
294294
maxCount={1}
295-
beforeUpload={(file:File) => {
295+
beforeUpload={(file: File) => {
296296
setAvatar(file);
297297
getBase64(file, (result: string) => {
298298
setAvatarPreview(result);
299299
});
300300
return false;
301301
}}
302-
onRemove={() => setAvatar(user?.photo )}
303-
>
302+
onRemove={() => setAvatar(user?.photo)}
303+
>
304304
<Button icon={<UploadOutlined />}>Upload</Button>
305305
</Upload>
306306
</ImgCrop>

packages/bokkenjs/lib/auth/auth.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,3 @@ export async function registerUser(values: any) {
132132

133133
return response.data;
134134
}
135-
136-

0 commit comments

Comments
 (0)