Skip to content

Commit

Permalink
resolve the cropIssues
Browse files Browse the repository at this point in the history
  • Loading branch information
Afonso-santos committed Jun 19, 2023
1 parent 604cf94 commit 3e4fed3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 88 deletions.
10 changes: 6 additions & 4 deletions apps/app/components/AppMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import {
UsergroupAddOutlined,
} from "@ant-design/icons";
import { useAuth } from "@coderdojobraga/ui";
import { EUser, IUser,API_URL } from "bokkenjs";
import { API_URL, EUser, IUser } from "bokkenjs";

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



const { SubMenu, Item } = Menu;
const { Text, Title } = Typography;

Expand Down Expand Up @@ -64,7 +62,11 @@ function AppMenu({ hidePrimaryMenu, collapsed }: any) {
setSecondarySelectedKeys([key]);
};
let avatarSrc;
if (!avatarPreview && typeof user?.photo === 'string' && user?.photo.startsWith('/uploads/')) {
if (
!avatarPreview &&
typeof user?.photo === "string" &&
user?.photo.startsWith("/uploads/")
) {
const previewUrl = `${API_URL}${user.photo}`;
avatarSrc = previewUrl;
} else {
Expand Down
10 changes: 6 additions & 4 deletions apps/app/components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as api from "bokkenjs";
import * as socials from "~/lib/social";
import { notifyError, notifyInfo } from "~/components/Notification";
import styles from "./style.module.css";
import { EUser, API_URL } from "bokkenjs";
import { API_URL, EUser } from "bokkenjs";

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

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



interface Props {
id: string;
role: EUser;
Expand Down Expand Up @@ -102,7 +100,11 @@ function Profile({ id, role }: Props) {
}, [info]);

let avatarSrc;
if (!avatarPreview && typeof info?.photo === 'string' && info?.photo.startsWith('/uploads/')) {
if (
!avatarPreview &&
typeof info?.photo === "string" &&
info?.photo.startsWith("/uploads/")
) {
const previewUrl = `${API_URL}${info.photo}`;
avatarSrc = previewUrl;
} else {
Expand Down
54 changes: 24 additions & 30 deletions apps/app/components/Register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,18 @@ import {
} from "@ant-design/icons";
import { useAuth } from "@coderdojobraga/ui";
import * as api from "bokkenjs";
import {getBase64,getAvatarSrc} from "~/lib/images";
import { getAvatarSrc, getBase64 } from "~/lib/images";
import Emoji from "~/components/Emoji";

import styles from "./style.module.css";
import { useState } from "react";
import { EUser, API_URL } from "bokkenjs";
import { API_URL, EUser } from "bokkenjs";
import { notifyError, notifyInfo } from "~/components/Notification";

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

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





const { Option } = Select;

const CountrySelect = () => (
Expand All @@ -48,15 +44,13 @@ const CountrySelect = () => (
</Select>
);



function Register({ cities }: any) {
const router = useRouter();
const { Title } = Typography;
const { user } = useAuth();
const [isLoading, setLoading] = useState(false);
const [errors, setErrors] = useState();
const [avatar, setAvatar] = useState< void | File|string>();
const [avatar, setAvatar] = useState<void | File | string>();
const [socials] = useState([
"Scratch",
"Codewars",
Expand All @@ -67,7 +61,6 @@ function Register({ cities }: any) {
"Slack",
]);


const onFinish = (values: any) => {
console.log(avatar);
values["user[photo]"] = avatar;
Expand All @@ -89,11 +82,12 @@ function Register({ cities }: any) {
.finally(() => setLoading(false));
};




let avatarSrc;
if (!avatarPreview && typeof user?.photo === 'string' && user?.photo.startsWith('/uploads/')) {
if (
!avatarPreview &&
typeof user?.photo === "string" &&
user?.photo.startsWith("/uploads/")
) {
const previewUrl = `${API_URL}${user.photo}`;
avatarSrc = previewUrl;
} else {
Expand Down Expand Up @@ -227,22 +221,22 @@ function Register({ cities }: any) {
label="Foto de perfil"
valuePropName="avatar"
>
<ImgCrop>
<Upload
accept="image/*"
maxCount={1}
beforeUpload={(file:File) => {
setAvatar(file);
getBase64(file, (result: string) => {
setAvatarPreview(result);
});
return false;
}}
onRemove={() => setAvatar(user?.photo )}
>
<Button icon={<UploadOutlined />}>Upload</Button>
</Upload>
</ImgCrop>
<ImgCrop>
<Upload
accept="image/*"
maxCount={1}
beforeUpload={(file: File) => {
setAvatar(file);
getBase64(file, (result: string) => {
setAvatarPreview(result);
});
return false;
}}
onRemove={() => setAvatar(user?.photo)}
>
<Button icon={<UploadOutlined />}>Upload</Button>
</Upload>
</ImgCrop>
</Form.Item>
{user?.role == EUser.Mentor && (
<Form.Item name="user[socials]" label="Redes Sociais">
Expand Down
16 changes: 9 additions & 7 deletions apps/app/lib/images.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
export function getBase64(img:File, callback:Function) {
export function getBase64(img: File, callback: Function) {
const reader = new FileReader();
reader.addEventListener("load", () => callback(reader.result));
reader.readAsDataURL(img);
}


export function getAvatarSrc(
avatarPreview: null | string | undefined ,
avatarPreview: null | string | undefined,
userPhoto: string | undefined,
API_URL: string | undefined,
API_URL: string | undefined
): string | undefined {
if (typeof avatarPreview === 'undefined' && typeof userPhoto === 'string' && userPhoto.startsWith('/uploads/')) {
if (
typeof avatarPreview === "undefined" &&
typeof userPhoto === "string" &&
userPhoto.startsWith("/uploads/")
) {
const previewUrl = `${API_URL}${userPhoto}`;
console.log('previewUrl', previewUrl);
console.log("previewUrl", previewUrl);
return previewUrl;
} else {
return userPhoto;
}
}

23 changes: 1 addition & 22 deletions apps/app/pages/admin/lectures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@ function Lectures() {
onOk={handleOk}
onCancel={handleOk}
>



{/* const PresenceList: React.FC<PresenceListProps> = ({ attendees }) => {
{/* const PresenceList: React.FC<PresenceListProps> = ({ attendees }) => {
const [presence, setPresence] = useState<boolean[]>(Array(attendees.length).fill(false));
const handlePresenceChange = (index: number) => {
Expand Down Expand Up @@ -271,24 +268,6 @@ function Lectures() {
export default PresenceList;
*/}



















<Descriptions size="small" column={1} layout="horizontal">
<Descriptions.Item
labelStyle={labelStyle}
Expand Down
3 changes: 2 additions & 1 deletion apps/app/pages/lectures/[role]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function Lectures() {
{moment(new Date(lecture.event.start_time)).format(
"DD/MM/YYYY"
)}
</Text>1
</Text>
1
</Col>
</Row>
<Row align="middle" gutter={[16, 16]}>
Expand Down
36 changes: 18 additions & 18 deletions apps/app/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
PlusOutlined,
UploadOutlined,
} from "@ant-design/icons";
import { getBase64, getAvatarSrc } from "~/lib/images";
import { getAvatarSrc, getBase64 } from "~/lib/images";
import { useAuth } from "@coderdojobraga/ui";
import { notifyError, notifyInfo } from "~/components/Notification";
import { getIcon } from "~/lib/utils";
Expand Down Expand Up @@ -67,9 +67,11 @@ function Settings() {
const [formPersonal] = Form.useForm();
const [formPassword] = Form.useForm();
const [avatar, setAvatar] = useState<null | File | string>();
const [avatarPreview, setAvatarPreview] = useState<null | string | undefined>();
const [avatarPreview, setAvatarPreview] = useState<
null | string | undefined
>();

const [userSkills, setUserSkills] = useState<any[]>([]);
const [userSkills, setUserSkills] = useState<any[]>([]);
const [skills, setSkills] = useState<any[]>([]);
const [selectedSkills, setSelectedSkills] = useState<any[]>([]);
const [mentorSocials, setMentorSocials] = useState([]);
Expand All @@ -82,20 +84,20 @@ function Settings() {
"Discord",
"Slack",
]);


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

if (!avatarPreview && typeof avatar === "string" && avatar.startsWith("/uploads/")) {
console.log("avatar", API_URL+avatar);
if (
!avatarPreview &&
typeof avatar === "string" &&
avatar.startsWith("/uploads/")
) {
console.log("avatar", API_URL + avatar);
setAvatarPreview(API_URL + avatar);
}




const onSubmit = (values: any) => {
if (avatar) {
Expand Down Expand Up @@ -200,8 +202,6 @@ function Settings() {
}
};



const changeSkills = () => {
const deleted = userSkills
.map((skill: any) => skill.id)
Expand Down Expand Up @@ -241,9 +241,9 @@ function Settings() {
useEffect(() => {
if (user?.photo) {
setAvatar(user?.photo);
};
getUserSkills();
getAllSkills();
}
getUserSkills();
getAllSkills();
}, [user, getUserSkills]);

const breakpoints = {
Expand Down Expand Up @@ -288,19 +288,19 @@ function Settings() {
<Space>
<Avatar size={100} src={avatarPreview} />
<Form.Item name="user[photo]">
<ImgCrop>
<ImgCrop>
<Upload
accept="image/*"
maxCount={1}
beforeUpload={(file:File) => {
beforeUpload={(file: File) => {
setAvatar(file);
getBase64(file, (result: string) => {
setAvatarPreview(result);
});
return false;
}}
onRemove={() => setAvatar(user?.photo )}
>
onRemove={() => setAvatar(user?.photo)}
>
<Button icon={<UploadOutlined />}>Upload</Button>
</Upload>
</ImgCrop>
Expand Down
2 changes: 0 additions & 2 deletions packages/bokkenjs/lib/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,3 @@ export async function registerUser(values: any) {

return response.data;
}


0 comments on commit 3e4fed3

Please sign in to comment.