Store location last seen date to check for New label

Stores the last location's page seeing date in localStorage to hide the Location's new label in list, on top of the date limit
This commit is contained in:
2022-09-14 11:32:58 +02:00
parent 683edc05fc
commit f38a8fcdc7
4 changed files with 43 additions and 10 deletions

View File

@@ -5,9 +5,10 @@
<script lang="ts">
import { getContext } from 'svelte'
import { spring } from 'svelte/motion'
import dayjs from 'dayjs'
import dayjs, { type Dayjs } from 'dayjs'
import { lerp } from '$utils/functions'
import { PUBLIC_PREVIEW_COUNT } from '$env/static/public'
import { seenLocations } from '$utils/stores'
// Components
import Image from '$components/atoms/Image.svelte'
import Badge from '$components/atoms/Badge.svelte'
@@ -15,19 +16,22 @@
export let location: any
export let latestPhoto: any
const { settings: { limit_new }}: any = getContext('global')
const { settings }: any = getContext('global')
let locationEl: HTMLElement
let photoIndex = 0
// Location date limit
let isNew = false
let dateUpdated: dayjs.Dayjs
const dateNowOffset = dayjs().subtract(limit_new, 'day')
let dateUpdated: Dayjs
const dateNowOffset = dayjs().subtract(settings.limit_new, 'day')
$: if (latestPhoto) {
$: if (latestPhoto && $seenLocations) {
dateUpdated = dayjs(latestPhoto.date_created)
isNew = dateUpdated.isAfter(dateNowOffset)
// Detect if location has new content
const seenLocation = JSON.parse($seenLocations)?.hasOwnProperty(location.id)
isNew = dateUpdated.isAfter(dateNowOffset) && !seenLocation
}