Redefine if location is has new photos and compare to last seen date

This commit is contained in:
2022-10-10 17:26:22 +02:00
parent a19339b49d
commit ee095a2cc8
3 changed files with 30 additions and 21 deletions

View File

@@ -5,7 +5,7 @@
<script lang="ts">
import { getContext } from 'svelte'
import { spring } from 'svelte/motion'
import dayjs, { type Dayjs } from 'dayjs'
import dayjs from 'dayjs'
import { lerp } from '$utils/functions'
import { PUBLIC_PREVIEW_COUNT } from '$env/static/public'
import { seenLocations } from '$utils/stores'
@@ -23,15 +23,24 @@
// Location date limit
let isNew = false
let dateUpdated: Dayjs
const dateNowOffset = dayjs().subtract(settings.limit_new, 'day')
const parsedSeenLocations = JSON.parse($seenLocations)
$: if (latestPhoto && $seenLocations) {
dateUpdated = dayjs(latestPhoto.date_created)
$: if (latestPhoto) {
const dateUpdated = dayjs(latestPhoto.date_created)
// Detect if location has new content
const seenLocation = JSON.parse($seenLocations)?.hasOwnProperty(location.id)
isNew = dateUpdated.isAfter(dateNowOffset) && !seenLocation
const seenLocationDate = dayjs(parsedSeenLocations[location.id])
const isLocationSeen = parsedSeenLocations?.hasOwnProperty(location.id)
// Define if location is has new photos
if (seenLocationDate && isLocationSeen) {
// A more recent photo has been added (if has been seen and has a seen date)
isNew = dateUpdated.isAfter(dateNowOffset) && dateUpdated.isAfter(seenLocationDate)
} else {
// The photo is after the offset
isNew = dateUpdated.isAfter(dateNowOffset)
}
}