Skip to content

Commit

Permalink
Merge pull request #617 from universi-me/feat#535/cores-aleatórias-pa…
Browse files Browse the repository at this point in the history
…ra-imagem-de-perfil

FEAT #535: Cores aleatórias para imagem de perfil
  • Loading branch information
julio-ufpb authored Sep 5, 2024
2 parents cdd855b + 7c8691d commit 5a76adf
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 26 deletions.
70 changes: 67 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
"bootstrap": "^5.3.0",
"bootstrap-icons": "^1.11.3",
"compressorjs": "^1.2.1",
"core-js": "^3.38.1",
"core-js-pure": "^3.38.1",
"cropperjs": "^1.6.1",
"dompurify": "^3.0.6",
"jsdom": "^23.0.1",
"phosphor-react": "^1.4.1",
"quill-image-uploader": "^1.3.0",
"react": "^18.2.0",
"react-avatar": "^5.0.3",
"react-bootstrap": "^2.8.0",
"react-colorful": "^5.6.1",
"react-cropper": "^2.3.3",
Expand Down
1 change: 1 addition & 0 deletions src/components/ProfileImage/ProfileImage.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
background-repeat: no-repeat;
background-size: contain;
aspect-ratio: 1;
user-select: none;
}
11 changes: 6 additions & 5 deletions src/components/ProfileImage/ProfileImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import { HTMLAttributes } from "react";
import { IMG_DEFAULT_PROFILE } from "@/utils/assets";
import { makeClassName } from "@/utils/tsxUtils";
import "./ProfileImage.css"
import Avatar from 'react-avatar'

export type ProfileImageProps = HTMLAttributes<HTMLElement> & {
imageUrl: string | null | undefined;
name?: string | null | undefined;
noImageColor?: string;
};

const DEFAULT_NO_IMAGE_COLOR = "#8A8A8A";

export function ProfileImage(props: ProfileImageProps) {
const {imageUrl, noImageColor, ...genericElementProps} = props;
const {imageUrl, name, noImageColor, ...genericElementProps} = props;
const className = makeClassName("profile-image-component", genericElementProps.className);

return <img {...genericElementProps}
className={className}
src={imageUrl ?? IMG_DEFAULT_PROFILE}
/>
return <div className={className} >
<Avatar size="100%" name={name!} src={imageUrl!} round={true} textSizeRatio={3} maxInitials={2}/>
</div>;
}
2 changes: 1 addition & 1 deletion src/components/ProfileInfo/ProfileBio/ProfileBio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function ProfileBio(props: ProfileBioProps) {
</div>

<div className="intro intro-section">
<ProfileImage className="image" imageUrl={profile.imageUrl} noImageColor="#505050" />
<ProfileImage className="image" imageUrl={profile.imageUrl} name={profile.fullname} noImageColor="#505050" />
{
isOnOwnProfile
? <h2 className="card-heading name">{ profile.fullname }</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function WelcomeUser() {
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild>
<div>
<ProfileImage className="logged-user-image" imageUrl={auth.profile?.imageUrl ?? IMG_DEFAULT_PROFILE} onClick={() => {setProfileClicked(!profileClicked)}}/>
<ProfileImage className="logged-user-image" imageUrl={auth.profile?.imageUrl} name={auth.profile?.fullname} onClick={() => {setProfileClicked(!profileClicked)}}/>
</div>
</DropdownMenu.Trigger>

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Group/GroupConfig/Roles/RolesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const RolesPage : React.FC<RolesPageProps> = ({ group }) => {
return null;

return <div className="profile-item" key={profile.id}>
<ProfileImage imageUrl={profile.imageUrl} className="profile-image" />
<ProfileImage imageUrl={profile.imageUrl} name={profile.fullname} className="profile-image" />
<div className="info">
<h2 className="profile-name">{profile.fullname}</h2>
<p className="profile-bio">{profile.bio}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function SelectPeople(){
const isSelected = !!selectedProfiles.find(i => i.id === p.id);

return <div className="participant-item" key={p.id}>
<img src={p.imageUrl} alt="" className="profile-picture" />
<ProfileImage className="profile-picture" imageUrl={p.imageUrl!} name={p?.fullname} />
<div className="profile-data">
<h2 className="profile-name">{ p.fullname }</h2>
</div>
Expand Down Expand Up @@ -344,9 +344,9 @@ export function GroupContents() {
{
imageUrl
?
<ProfileImage imageUrl={imageUrl} className="content-image" onClick={() => selectContent(content)} />
<img src={imageUrl} title={content.name} className="content-image" onClick={() => selectContent(content)} />
:
<ProfileImage imageUrl={"/assets/imgs/default-content.png"} className="content-image default-image" onClick={() => selectContent(content)} />
<img src={"/assets/imgs/default-content.png"} title={content.name} className="content-image default-image" onClick={() => selectContent(content)} />
}

<div className="info">
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Group/GroupTabs/GroupFeed/GroupFeedPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Permission } from "@/types/Roles";
import { ICON_LIKE, ICON_CLAP, ICON_HEART, ICON_SUPPORT, ICON_GENIUS, ICON_HAPPY, ICON_COMMENT } from '@/utils/assets';
import TextboxFormatted from "@/components/TextboxFormatted/TextboxFormatted";
import UniversiForm, { FormInputs, RequiredValidation, TextValidation, ValidationComposite } from "@/components/UniversiForm";
import { ProfileImage } from "@/components/ProfileImage/ProfileImage";

export type GroupFeedPostProps = Readonly<{
post: GroupPost;
Expand Down Expand Up @@ -122,7 +123,7 @@ export function GroupFeedPost({ post, isComment }: GroupFeedPostProps) {

return <div className="feed-item tab-item">
<Link to={`/profile/${author.user.name}`} className="feed-user-info">
<img src={author.imageUrl} alt="" className="feed-image" />
<ProfileImage className="feed-image" imageUrl={author.imageUrl} name={author.fullname} />
<p>{author.fullname}</p>
</Link>

Expand Down
15 changes: 12 additions & 3 deletions src/pages/Group/GroupTabs/GroupPeople/GroupPeople.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,43 @@
gap: @gap;
justify-content: center;

.person-image-info {
width: 32%;
min-width: 32%;
max-width: 32%;
aspect-ratio: 1;
}

.person-item {
display: flex;
flex-direction: row;

width: calc(50% - @gap / 2);
min-width: 200px;

text-align: center;

align-items: center;
padding: 0;
padding: 0.3rem 0.3rem;
overflow: hidden;
border: none;

.person-image {
@side: 8rem !important;
@side: 100% !important;
width: @side;
height: @side;
aspect-ratio: 1;

background-color: inherit;
object-fit: cover;
border-radius: 50%;
padding: 1rem;
padding: 0.6rem 0.6rem;
}

.info {

text-align: start;
word-break: break-word;

color: @font-color-v2;
.person-name {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Group/GroupTabs/GroupPeople/GroupPeople.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ function renderPerson(person: ProfileClass) {

return (
<div className="person-item tab-item" key={person.id} id={person.id}>
<Link to={linkToProfile}>
<ProfileImage imageUrl={imageUrl} className="person-image" />
<Link to={linkToProfile} className="person-image-info">
<ProfileImage imageUrl={imageUrl} name={person.fullname} className="person-image" />
</Link>

<div className="info">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ManageProfile/ManageProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function ManageProfilePage() {
<div id="left-side">
<form id="profile-edit" className="card">
<div className="image-name-container">
<ManageProfileImage currentImage={profile.imageUrl} setImage={setImage} />
<ManageProfileImage currentImage={profile.imageUrl} setImage={setImage} name={profile.fullname} />

<fieldset id="fieldset-name">
<legend>Altere seu nome</legend>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/ManageProfile/ManageProfileImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CropperComponent from "@/components/ImageCropper/ImageCropper";
export type ManageProfileImageProps = {
currentImage: string | null;
setImage(image: File | undefined): any;
name: string | null;
};

export function ManageProfileImage(props: ManageProfileImageProps) {
Expand All @@ -20,7 +21,7 @@ export function ManageProfileImage(props: ManageProfileImageProps) {
<fieldset id="fieldset-image">
<legend className="required-input">Alterar imagem do perfil</legend>
<input id="image" name="image" accept="image/*" type="file" onChange={changeImage} />
<label htmlFor="image"><ProfileImage imageUrl={image} id="profile-image-view" /></label>
<label htmlFor="image"><ProfileImage imageUrl={image} name={props.name} id="profile-image-view" /></label>
<CropperComponent show={showCrop} src={image as string} selectImage={updateImage} willClose={() => setShowCrop(false)} options={{aspectRatio: 1,}} />
</fieldset>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { type Folder, type FolderProfile } from "@/types/Capacity";
import { ProfileClass } from "@/types/Profile";

import "./ProfileAssignedByMe.less";
import { ProfileImage } from "@/components/ProfileImage/ProfileImage";

export function ProfileAssignedByMe() {
const context = useContext(ProfileContext);
Expand Down Expand Up @@ -135,7 +136,7 @@ function WatchFolderProgress(props: Readonly<WatchFolderProgressProps>) {
const shownPercentage = isNaN(percentage) ? 0 : percentage;

return <Link to={`/content/${folder.reference}?watch=${w.profile.user.name}`} target="_blank" className="profile-watcher" key={w.id}>
<img src={w.profile.imageUrl} className="profile-image" alt="" />
<ProfileImage className="profile-image" imageUrl={w.profile.imageUrl!} name={w.profile?.fullname} />

<div className="progress-data">
<h3 className="profile-name">{w.profile.fullname}</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function ProfileLastRecommendations() {
return (
<div className="recommendation" key={recommendation.id}>
<Link to={originUrl} target='_blank'>
<ProfileImage className="image" imageUrl={recommendation.origin.imageUrl} noImageColor='#8A8A8A' />
<ProfileImage className="image" imageUrl={recommendation.origin.imageUrl} name={recommendation.origin.fullname} noImageColor='#8A8A8A' />
</Link>

<div className="box">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Settings/RolesPage/RolesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export function RolesPage() {
</div>

<div style={{width: '15%'}}>
<ProfileImage imageUrl={profile.imageUrl} className="profile-image" />
<ProfileImage imageUrl={profile.imageUrl} name={profile.fullname} className="profile-image" />
</div>

<div className="info" style={{width: '40%'}}>
Expand Down
2 changes: 1 addition & 1 deletion src/types/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ProfileClass implements Profile {
*/
get imageUrl() {
if (this.image === null)
return IMG_DEFAULT_PROFILE;
return null;

if (this.image.startsWith("/")) {
return import.meta.env.VITE_UNIVERSIME_API + this.image;
Expand Down

0 comments on commit 5a76adf

Please sign in to comment.