mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-12 15:25:59 +00:00
fix(app): show past items (#433)
Co-authored-by: mahula <lenzmath@posteo.de> Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
This commit is contained in:
parent
1aa9132246
commit
2eec9f959f
@ -1,12 +1,10 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/* eslint-disable import/no-relative-parent-imports */
|
/* eslint-disable import/no-relative-parent-imports */
|
||||||
/* eslint-disable array-callback-return */
|
|
||||||
/* eslint-disable new-cap */
|
/* eslint-disable new-cap */
|
||||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
UtopiaMap,
|
UtopiaMap,
|
||||||
@ -36,34 +34,37 @@ function MapContainer({ layers, map }: { layers: LayerProps[]; map: any }) {
|
|||||||
const [apis, setApis] = useState<layerApi[]>([])
|
const [apis, setApis] = useState<layerApi[]>([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// get timestamp for the end of the current day
|
// get timestamp for the start of the current day
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
||||||
const etartOfDayISO = startOfDay.toISOString()
|
const startOfDayISO = startOfDay.toISOString()
|
||||||
|
|
||||||
layers.map((layer: LayerProps) => {
|
const newApis = layers.map((layer: LayerProps) => {
|
||||||
apis &&
|
// Only apply date filter if showPastItems is not explicitly set to true
|
||||||
setApis((current) => [
|
const dateFilter = layer.showPastItems
|
||||||
...current,
|
? undefined
|
||||||
{
|
: {
|
||||||
id: layer.id,
|
_or: [
|
||||||
api: new itemsApi<Place>('items', layer.id, undefined, {
|
{
|
||||||
_or: [
|
end: {
|
||||||
{
|
_gt: startOfDayISO,
|
||||||
end: {
|
|
||||||
_gt: etartOfDayISO,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
end: {
|
{
|
||||||
_null: true,
|
end: {
|
||||||
},
|
_null: true,
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
}),
|
],
|
||||||
},
|
}
|
||||||
])
|
|
||||||
|
return {
|
||||||
|
id: layer.id,
|
||||||
|
api: new itemsApi<Place>('items', layer.id, undefined, dateFilter),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setApis(newApis)
|
||||||
}, [layers])
|
}, [layers])
|
||||||
|
|
||||||
useEffect(() => {}, [apis])
|
useEffect(() => {}, [apis])
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"collection": "layers",
|
||||||
|
"field": "showPastItems",
|
||||||
|
"type": "boolean",
|
||||||
|
"meta": {
|
||||||
|
"collection": "layers",
|
||||||
|
"conditions": null,
|
||||||
|
"display": null,
|
||||||
|
"display_options": null,
|
||||||
|
"field": "showPastItems",
|
||||||
|
"group": null,
|
||||||
|
"hidden": false,
|
||||||
|
"interface": "boolean",
|
||||||
|
"note": null,
|
||||||
|
"options": null,
|
||||||
|
"readonly": false,
|
||||||
|
"required": false,
|
||||||
|
"sort": 19,
|
||||||
|
"special": [
|
||||||
|
"cast-boolean"
|
||||||
|
],
|
||||||
|
"translations": null,
|
||||||
|
"validation": null,
|
||||||
|
"validation_message": null,
|
||||||
|
"width": "full"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"name": "showPastItems",
|
||||||
|
"table": "layers",
|
||||||
|
"data_type": "boolean",
|
||||||
|
"default_value": false,
|
||||||
|
"max_length": null,
|
||||||
|
"numeric_precision": null,
|
||||||
|
"numeric_scale": null,
|
||||||
|
"is_nullable": true,
|
||||||
|
"is_unique": false,
|
||||||
|
"is_indexed": false,
|
||||||
|
"is_primary_key": false,
|
||||||
|
"is_generated": false,
|
||||||
|
"generation_expression": null,
|
||||||
|
"has_auto_increment": false,
|
||||||
|
"foreign_key_table": null,
|
||||||
|
"foreign_key_column": null
|
||||||
|
}
|
||||||
|
}
|
||||||
1
lib/src/types/LayerProps.d.ts
vendored
1
lib/src/types/LayerProps.d.ts
vendored
@ -26,4 +26,5 @@ export interface LayerProps {
|
|||||||
listed?: boolean
|
listed?: boolean
|
||||||
item_presets?: Record<string, unknown>
|
item_presets?: Record<string, unknown>
|
||||||
item_default_name?: string
|
item_default_name?: string
|
||||||
|
showPastItems?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user