Skip to content

Commit

Permalink
Filter by album correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-ismagilov committed Aug 3, 2023
1 parent c40a849 commit e1d816e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Util/PhotoLoader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useMemo, useState } from "react";
import axios from "axios";
import { album } from "lightbox2";

import { useAppContext } from "../components/AppContext";
import { TAG_ALBUM } from "../consts";

import { getEventData } from "./DataLoader";
import PhotoService from "./PhotoService";
Expand Down Expand Up @@ -72,6 +74,15 @@ const usePhotoLoader = () => {
return null;
}

function albumFromTags(tags) {
const albumTag = TAG_ALBUM.toLowerCase();
const tag = tags.split(" ").find(tag => tag.startsWith(albumTag));
if (tag === undefined) {
return null;
}
return tag.replaceAll(albumTag, "");
}

/**
* Returns a flattened array of all photos from all events.
* @returns {Array} - An array of photo objects.
Expand Down Expand Up @@ -123,14 +134,14 @@ const usePhotoLoader = () => {
}

if (response) {
const newPhotosByEvent = appendPhotos(photosByEvent, internalEvent, response.data.photos.photo.map(({ datetaken, url_m, url_o, url_l, id, width_o, width_l, height_o, height_l }) => ({
const newPhotosByEvent = appendPhotos(photosByEvent, internalEvent, response.data.photos.photo.map(({ datetaken, url_m, url_o, url_l, id, width_o, width_l, height_o, height_l, tags }) => ({
url_preview: url_m ?? url_o,
url: url_l ?? url_o,
width: width_l ?? width_o,
height: height_l ?? height_o,
id,
origin: url_o,
year: new Date(datetaken)?.getUTCFullYear(),
year: albumFromTags(tags),
})));
setTotalPages(response.data.photos.pages);
setPage(page + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/Util/PhotoService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from "axios";
import { api_key, PER_PAGE, TAG_ALBUM, TAG_EVENT, TAG_TEAM, user_id } from "../consts";

export default class PhotoService {
static extras = "tags,url_m,url_c,url_l,url_o,description,date_upload,date_taken";
static extras = "tags,machine_tags,url_m,url_c,url_l,url_o,description,date_upload,date_taken";
static parameters = `&per_page=${PER_PAGE}&extras=${PhotoService.extras}&format=json&nojsoncallback=?`;

static getAllWithEvent(year, event = "Photo%20Tour", page = 1, config = {}) {
Expand Down

0 comments on commit e1d816e

Please sign in to comment.