Added a Loading component and added a border to the current image

This commit is contained in:
Lucas Oliveira 2024-06-07 15:41:47 -03:00
commit a2485d1797
3 changed files with 56 additions and 36 deletions

View file

@ -366,7 +366,7 @@ export async function uploadFile(
} }
export async function getProfilePictures(): Promise<ProfilePicturesTypeAPI> { export async function getProfilePictures(): Promise<ProfilePicturesTypeAPI> {
return await api.get(`${BASE_URL_API}files/list/profile_pictures`); return api.get(`${BASE_URL_API}files/list/profile_pictures`);
} }
export async function postCustomComponent( export async function postCustomComponent(

View file

@ -1,3 +1,4 @@
import { reject } from "lodash";
import { PROFILE_PICTURES_GET_ERROR_ALERT } from "../../../../../../../../../constants/alerts_constants"; import { PROFILE_PICTURES_GET_ERROR_ALERT } from "../../../../../../../../../constants/alerts_constants";
import { getProfilePictures } from "../../../../../../../../../controllers/API"; import { getProfilePictures } from "../../../../../../../../../controllers/API";
@ -11,6 +12,7 @@ const useGetProfilePictures = (setErrorData) => {
title: PROFILE_PICTURES_GET_ERROR_ALERT, title: PROFILE_PICTURES_GET_ERROR_ALERT,
list: [(error as any)?.response?.data?.detail], list: [(error as any)?.response?.data?.detail],
}); });
throw error;
} }
}; };

View file

@ -7,15 +7,20 @@ import {
BACKEND_URL, BACKEND_URL,
BASE_URL_API, BASE_URL_API,
} from "../../../../../../../../constants/constants"; } from "../../../../../../../../constants/constants";
import HorizontalScrollFadeComponent from "../../../../../../../../components/horizontalScrollFadeComponent";
import LoadingComponent from "../../../../../../../../components/loadingComponent";
import Loading from "../../../../../../../../components/ui/loading";
export default function ProfilePictureChooserComponent({ value, onChange }) { export default function ProfilePictureChooserComponent({ value, onChange }) {
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);
const getProfilePictures = useGetProfilePictures({ setErrorData }); const getProfilePictures = useGetProfilePictures({ setErrorData });
const [profilePictures, setProfilePictures] = useState<string[][]>([]); const [profilePictures, setProfilePictures] = useState<string[][]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => { useEffect(() => {
getProfilePictures().then((data) => { getProfilePictures()
.then((data) => {
if (data) { if (data) {
data.forEach((profile_picture) => { data.forEach((profile_picture) => {
const [folder, path] = profile_picture.split("/"); const [folder, path] = profile_picture.split("/");
@ -27,19 +32,26 @@ export default function ProfilePictureChooserComponent({ value, onChange }) {
} }
return prev; return prev;
}); });
setLoading(false);
}); });
} }
})
.catch(() => {
setLoading(false);
}); });
}); });
return ( return (
<div className="flex flex-wrap items-center justify-start gap-2"> <div className="flex flex-col justify-center gap-2">
{profilePictures.map((folder, idx) => ( {loading ? (
<Loading />
) : (
profilePictures.map((folder, idx) => (
<Label> <Label>
<div className="edit-flow-arrangement"> <div className="edit-flow-arrangement">
<span className="font-medium">{folder}</span> <span className="font-medium">{folder}</span>
</div> </div>
<div className="flex flex-wrap items-center justify-start gap-2"> <HorizontalScrollFadeComponent>
{folder.map((path, idx) => ( {folder.map((path, idx) => (
<img <img
key={idx} key={idx}
@ -47,13 +59,19 @@ export default function ProfilePictureChooserComponent({ value, onChange }) {
0, 0,
BACKEND_URL.length - 1, BACKEND_URL.length - 1,
)}${BASE_URL_API}files/images/${folder + "/" + path}`} )}${BASE_URL_API}files/images/${folder + "/" + path}`}
className="h-12 w-12 rounded-full" className={
"h-12 w-12 rounded-full" +
(value === folder + "/" + path
? " border-2 border-white"
: "")
}
onClick={() => onChange(folder + "/" + path)} onClick={() => onChange(folder + "/" + path)}
/> />
))} ))}
</div> </HorizontalScrollFadeComponent>
</Label> </Label>
))} ))
)}
</div> </div>
); );
} }