forked from MapComplete/MapComplete
Move MoreScreen to svelte
This commit is contained in:
parent
227551c7cb
commit
1bf1700bab
9 changed files with 419 additions and 205 deletions
83
UI/BigComponents/ThemesList.svelte
Normal file
83
UI/BigComponents/ThemesList.svelte
Normal file
|
@ -0,0 +1,83 @@
|
|||
<script lang="ts" context="module">
|
||||
export interface Theme {
|
||||
id: string
|
||||
icon: string
|
||||
title: any
|
||||
shortDescription: any
|
||||
definition?: any
|
||||
mustHaveLanguage?: boolean
|
||||
hideFromOverview?: boolean
|
||||
keywords?: any[]
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import NoThemeResultButton from "./NoThemeResultButton.svelte"
|
||||
|
||||
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
|
||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||
import type Loc from "../../Models/Loc"
|
||||
import Locale from "../i18n/Locale"
|
||||
import CustomGeneratorButton from "./CustomGeneratorButton.svelte"
|
||||
import ProfessionalServicesButton from "./ProfessionalServicesButton.svelte"
|
||||
import ThemeButton from "./ThemeButton.svelte"
|
||||
|
||||
export let search: UIEventSource<string>
|
||||
export let themes: Theme[]
|
||||
export let state: { osmConnection: OsmConnection; locationControl?: UIEventSource<Loc> }
|
||||
export let isCustom: boolean = false
|
||||
export let onMainScreen: boolean = true
|
||||
export let hideThemes: boolean = true
|
||||
|
||||
// Filter theme based on search value
|
||||
$: filteredThemes = themes.filter((theme) => {
|
||||
if ($search === undefined || $search === "") return true
|
||||
|
||||
const srch = $search.toLocaleLowerCase()
|
||||
if (theme.id.toLowerCase().indexOf(srch) >= 0) {
|
||||
return true
|
||||
}
|
||||
const entitiesToSearch = [theme.shortDescription, theme.title, ...(theme.keywords ?? [])]
|
||||
for (const entity of entitiesToSearch) {
|
||||
if (entity === undefined) {
|
||||
continue
|
||||
}
|
||||
const term = entity["*"] ?? entity[Locale.language.data]
|
||||
if (term?.toLowerCase()?.indexOf(search) >= 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
</script>
|
||||
|
||||
<section>
|
||||
<slot name="title" />
|
||||
<div class:gridview={onMainScreen}>
|
||||
{#if ($search === undefined || $search === "") && !isCustom}
|
||||
<CustomGeneratorButton userDetails={state.osmConnection.userDetails} />
|
||||
<ProfessionalServicesButton />
|
||||
{/if}
|
||||
|
||||
{#each filteredThemes as theme}
|
||||
{#if theme !== undefined && !(hideThemes && theme?.hideFromOverview)}
|
||||
<ThemeButton {theme} {isCustom} userDetails={state.osmConnection.userDetails} {state} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if filteredThemes.length == 0}
|
||||
<NoThemeResultButton {search} />
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<style lang="scss">
|
||||
section {
|
||||
@apply flex flex-col;
|
||||
|
||||
div.gridview {
|
||||
@apply md:grid md:grid-flow-row md:grid-cols-2 lg:grid-cols-3 gap-4;
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
Add table
Add a link
Reference in a new issue