Manage displayed photos via the API
All checks were successful
continuous-integration/drone/push Build is passing

Define limits (for homepage carousel and photos per page on a place) in the site settings via a slider
This commit is contained in:
2020-03-16 13:11:58 +01:00
parent 9965c9dec3
commit 8c8ee101f2
3 changed files with 13 additions and 6 deletions

View File

@@ -11,6 +11,8 @@
description description
explore_globe explore_globe
explore_list explore_list
homepage_photos_limit
photos_per_page
instagram instagram
seo_name seo_name
seo_title_default seo_title_default

View File

@@ -1,15 +1,21 @@
<script context="module"> <script context="module">
import { apiEndpoints } from '../utils/store' import { site, apiEndpoints } from '../utils/store'
// Preload data // Variables
let limit
// Preload data (photos to display)
export async function preload (page, session) { export async function preload (page, session) {
// Load random photos // Fields
const fields = [ const fields = [
'id', 'name', 'image.private_hash', 'id', 'name', 'image.private_hash',
'location.id', 'location.name', 'location.slug', 'location.country.name' 'location.id', 'location.name', 'location.slug', 'location.country.name'
] ]
// Random sort
const sort = '?' const sort = '?'
const limit = 5 // Get the limit from API
site.subscribe(store => limit = store.homepage_photos_limit)
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`) const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`)
const photos = await req.json() const photos = await req.json()
if (req.ok) { if (req.ok) {
@@ -22,7 +28,6 @@
<script> <script>
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { import {
site,
currentLocation, currentLocation,
currentPhotos, currentPhotos,
pageReady, pageReady,

View File

@@ -72,7 +72,7 @@
/* /*
** Pagination ** Pagination
*/ */
let photosPerPage = 2 // 12 let photosPerPage = $site.photos_per_page
let currentIndex = photosPerPage let currentIndex = photosPerPage
// Hide photos by default // Hide photos by default