mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 20:09:25 +00:00
fix: user pictures ordering
This commit is contained in:
@ -9,28 +9,35 @@ interface PagePictureConfig {
|
||||
userId: number;
|
||||
}
|
||||
|
||||
interface Album {
|
||||
id: number;
|
||||
name: string;
|
||||
pictures: PictureSchema[];
|
||||
}
|
||||
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("user_pictures", (config: PagePictureConfig) => ({
|
||||
loading: true,
|
||||
pictures: [] as PictureSchema[],
|
||||
albums: {} as Record<string, PictureSchema[]>,
|
||||
albums: [] as Album[],
|
||||
|
||||
async init() {
|
||||
this.pictures = await paginated(picturesFetchPictures, {
|
||||
const pictures = await paginated(picturesFetchPictures, {
|
||||
// biome-ignore lint/style/useNamingConvention: from python api
|
||||
query: { users_identified: [config.userId] },
|
||||
} as PicturesFetchPicturesData);
|
||||
|
||||
this.albums = this.pictures.reduce(
|
||||
(acc: Record<number, PictureSchema[]>, picture: PictureSchema) => {
|
||||
if (!acc[picture.album.id]) {
|
||||
acc[picture.album.id] = [];
|
||||
}
|
||||
acc[picture.album.id].push(picture);
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
const groupedAlbums = Object.groupBy(pictures, (i: PictureSchema) => i.album.id);
|
||||
this.albums = Object.values(groupedAlbums).map((pictures: PictureSchema[]) => {
|
||||
return {
|
||||
id: pictures[0].album.id,
|
||||
name: pictures[0].album.name,
|
||||
pictures: pictures,
|
||||
};
|
||||
});
|
||||
this.albums.sort((a: Album, b: Album) => b.id - a.id);
|
||||
const hash = document.location.hash.replace("#", "");
|
||||
if (hash.startsWith("album-")) {
|
||||
this.$nextTick(() => document.getElementById(hash)?.scrollIntoView()).then();
|
||||
}
|
||||
this.loading = false;
|
||||
},
|
||||
}));
|
||||
|
@ -50,7 +50,7 @@
|
||||
#}
|
||||
{% macro download_button(name) %}
|
||||
<div x-data="pictures_download">
|
||||
<div x-show="pictures.length > 0" x-cloak>
|
||||
<div x-show="albums.length > 0" x-cloak>
|
||||
<button
|
||||
:disabled="isDownloading"
|
||||
class="btn btn-blue {% if name == "" %}btn-no-text{% endif %}"
|
||||
|
@ -20,17 +20,17 @@
|
||||
{{ download_button(_("Download all my pictures")) }}
|
||||
{% endif %}
|
||||
|
||||
<template x-for="[album_id, pictures] in Object.entries(albums)" x-cloak>
|
||||
<template x-for="album in albums" x-cloak>
|
||||
<section>
|
||||
<br />
|
||||
<div class="row">
|
||||
<h4 x-text="pictures[0].album.name" :id="`album-${album_id}`"></h4>
|
||||
<h4 x-text="album.name" :id="`album-${album.id}`"></h4>
|
||||
{% if user.id == object.id %}
|
||||
{{ download_button("") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="photos">
|
||||
<template x-for="picture in pictures">
|
||||
<template x-for="picture in album.pictures">
|
||||
<a :href="picture.sas_url">
|
||||
<div
|
||||
class="photo"
|
||||
|
Reference in New Issue
Block a user