Refactoring: split 'Utils' into multiple files; fix some stray uppercase-method names

This commit is contained in:
Pieter Vander Vennet 2025-08-01 04:02:09 +02:00
parent 81be4db044
commit 3ec89826e4
97 changed files with 884 additions and 921 deletions

View file

@ -3,12 +3,12 @@
*/
import { Stores, UIEventSource } from "../../../../Logic/UIEventSource"
import SingleCollectionTime from "./SingleCollectionTime.svelte"
import { Utils } from "../../../../Utils"
import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid"
import { Lists } from "../../../../Utils/Lists"
export let value: UIEventSource<string>
let initialRules: string[] = Utils.NoEmpty(value.data?.split(";")?.map(v => v.trim()))
let initialRules: string[] = Lists.noEmpty(value.data?.split(";")?.map(v => v.trim()))
let singleRules: UIEventSource<UIEventSource<string>[]> = new UIEventSource(
initialRules?.map(v => new UIEventSource(v)) ?? []
)
@ -17,7 +17,7 @@ if(singleRules.data.length === 0){
}
singleRules.bindD(stores => Stores.concat(stores)).addCallbackAndRunD(subrules => {
console.log("Setting subrules", subrules)
value.set(Utils.NoEmpty(subrules).join("; "))
value.set(Lists.noEmpty(subrules).join("; "))
})
function rm(rule: UIEventSource){

View file

@ -1,6 +1,5 @@
<script lang="ts">
import PlusCircle from "@rgossiaux/svelte-heroicons/solid/PlusCircle"
import TimeInput from "../TimeInput.svelte"
import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid"
import Checkbox from "../../../Base/Checkbox.svelte"
@ -8,7 +7,8 @@
import { Stores, UIEventSource } from "../../../../Logic/UIEventSource"
import Translations from "../../../i18n/Translations"
import { OH } from "../../../OpeningHours/OpeningHours"
import { Utils } from "../../../../Utils"
import { Lists } from "../../../../Utils/Lists"
import { Translation } from "../../../i18n/Translation"
export let value: UIEventSource<string>
@ -18,7 +18,7 @@
*/
let weekdays: Translation[] = [wt.monday, wt.tuesday, wt.wednesday, wt.thursday, wt.friday, wt.saturday, wt.sunday, Translations.t.general.opening_hours.ph]
let initialTimes= Utils.NoEmpty(value.data?.split(" ")?.[1]?.split(",")?.map(s => s.trim())??[])
let initialTimes= Lists.noEmpty(value.data?.split(" ")?.[1]?.split(",")?.map(s => s.trim()) ?? [])
let values = new UIEventSource(initialTimes.map(t => new UIEventSource(t)))
if(values.data.length === 0){
values.data.push(new UIEventSource(""))
@ -29,7 +29,7 @@
let daysOfTheWeek = [...OH.days, "PH"]
let selectedDays = daysOfTheWeek.map(() => new UIEventSource(false))
let initialDays = Utils.NoEmpty(value.data?.split(" ")?.[0]?.split(",") ?? [])
let initialDays = Lists.noEmpty(value.data?.split(" ")?.[0]?.split(",") ?? [])
for (const initialDay of initialDays) {
if (initialDay.indexOf("-") > 0) {
let [start, end] = initialDay.split("-")
@ -48,17 +48,17 @@
}
let selectedDaysBound = Stores.concat(selectedDays)
.mapD(days => Utils.NoNull(days.map((selected, i) => selected ? daysOfTheWeek[i] : undefined)))
.mapD(days => Lists.noNull(days.map((selected, i) => selected ? daysOfTheWeek[i] : undefined)))
let valuesConcat: Store<string[]> = values.bindD(values => Stores.concat(values))
.mapD(values => Utils.NoEmpty(values))
.mapD(values => Lists.noEmpty(values))
valuesConcat.mapD(times => {
console.log(times)
times = Utils.NoNull(times)
times = Lists.noNull(times)
if (!times || times?.length === 0) {
return undefined
}
times?.sort(/*concatted, new array*/)
return (Utils.NoEmpty(selectedDaysBound.data).join(",") + " " + times).trim()
return (Lists.noEmpty(selectedDaysBound.data).join(",") + " " + times).trim()
}, [selectedDaysBound]).addCallbackAndRunD(v => value.set(v))
function selectWeekdays() {

View file

@ -29,7 +29,7 @@
let element: HTMLTableElement
function range(n: number) {
return Utils.TimesT(n, (n) => n)
return Utils.timesT(n, (n) => n)
}
function clearSelection() {

View file

@ -13,6 +13,7 @@
import { Utils } from "../../../Utils"
import WikidataValidator from "../Validators/WikidataValidator"
import Searchbar from "../../Base/Searchbar.svelte"
import { Lists } from "../../../Utils/Lists"
const t = Translations.t.general.wikipedia
@ -80,7 +81,7 @@
seen.push(item)
}
}
return Utils.NoNull(seen).filter((i) => !knownIds.has(i.id))
return Lists.noNull(seen).filter((i) => !knownIds.has(i.id))
})
</script>

View file

@ -12,6 +12,7 @@
import type { Feature } from "geojson"
import { onDestroy } from "svelte"
import WikidataValidator from "../Validators/WikidataValidator"
import { Lists } from "../../../Utils/Lists"
export let args: (string | number | boolean)[] = []
export let feature: Feature
@ -43,12 +44,8 @@
})
)
let instanceOf: number[] = Utils.NoNull(
(options?.instanceOf ?? []).map((i) => Wikidata.QIdToNumber(i))
)
let notInstanceOf: number[] = Utils.NoNull(
(options?.notInstanceOf ?? []).map((i) => Wikidata.QIdToNumber(i))
)
let instanceOf: number[] = Lists.noNull((options?.instanceOf ?? []).map((i) => Wikidata.QIdToNumber(i)))
let notInstanceOf: number[] = Lists.noNull((options?.notInstanceOf ?? []).map((i) => Wikidata.QIdToNumber(i)))
let allowMultipleArg = options?.["multiple"] ?? "yes"
let allowMultiple = allowMultipleArg === "yes" || "" + allowMultipleArg === "true"