Manage displayed photos via the API
All checks were successful
continuous-integration/drone/push Build is passing
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:
@@ -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
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user