mirror of
https://github.com/mue/mue.git
synced 2026-07-09 13:35:35 +02:00
refactor(modules): second part of moving files around, changing layout etc
This commit is contained in:
35
src/utils/background/getOfflineImage.js
Normal file
35
src/utils/background/getOfflineImage.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import offlineImages from 'utils/data/offline_images.json';
|
||||
|
||||
/**
|
||||
* It gets a random photographer from the offlineImages.json file, then gets a random image from that
|
||||
* photographer, and returns an object with the image's URL, type, and photoInfo.
|
||||
* </code>
|
||||
* @param type - 'background' or 'thumbnail'
|
||||
* @returns An object with the following properties:
|
||||
* url: A string that is the path to the image.
|
||||
* type: A string that is the type of image.
|
||||
* photoInfo: An object with the following properties:
|
||||
* offline: A boolean that is true.
|
||||
* credit: A string that is the name of the photographer.
|
||||
*/
|
||||
export function offlineBackground(type) {
|
||||
const photographers = Object.keys(offlineImages);
|
||||
const photographer = photographers[Math.floor(Math.random() * photographers.length)];
|
||||
|
||||
const randomImage =
|
||||
offlineImages[photographer].photo[
|
||||
Math.floor(Math.random() * offlineImages[photographer].photo.length)
|
||||
];
|
||||
|
||||
const object = {
|
||||
url: `./offline-images/${randomImage}.webp`,
|
||||
type,
|
||||
photoInfo: {
|
||||
offline: true,
|
||||
credit: photographer,
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem('currentBackground', JSON.stringify(object));
|
||||
return object;
|
||||
}
|
||||
Reference in New Issue
Block a user