Redefine if location is has new photos and compare to last seen date
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user