MapComplete/src/UI/SpecialVisualisations/SettingsVisualisations.ts

190 lines
8.2 KiB
TypeScript
Raw Normal View History

import { SpecialVisualizationState, SpecialVisualizationSvelte } from "../SpecialVisualization"
import SvelteUIElement from "../Base/SvelteUIElement"
import DisabledQuestions from "../Popup/DisabledQuestions.svelte"
import Constants from "../../Models/Constants"
import LogoutButton from "../Base/LogoutButton.svelte"
import LoginButton from "../Base/LoginButton.svelte"
import ThemeViewState from "../../Models/ThemeViewState"
import OrientationDebugPanel from "../Debug/OrientationDebugPanel.svelte"
import AllTagsPanel from "../Popup/AllTagsPanel/AllTagsPanel.svelte"
2025-04-06 00:30:59 +02:00
import { UIEventSource } from "../../Logic/UIEventSource"
import ClearCaches from "../Popup/ClearCaches.svelte"
import Locale from "../i18n/Locale"
import LanguageUtils from "../../Utils/LanguageUtils"
import LanguagePicker from "../InputElement/LanguagePicker.svelte"
import PendingChangesIndicator from "../BigComponents/PendingChangesIndicator.svelte"
2025-04-06 00:30:59 +02:00
import { Utils } from "../../Utils"
import { Feature } from "geojson"
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
import QrCode from "../Popup/QrCode.svelte"
export class SettingsVisualisations {
public static initList(): SpecialVisualizationSvelte[] {
return [
{
funcName: "language_picker",
args: [],
group: "settings",
docs: "A component to set the language of the user interface",
constr(state: SpecialVisualizationState): SvelteUIElement {
const availableLanguages = Locale.showLinkToWeblate.map((showTranslations) =>
2025-03-06 16:21:55 +01:00
showTranslations
? LanguageUtils.usedLanguagesSorted
: state?.theme?.language ?? LanguageUtils.usedLanguagesSorted
2025-02-10 02:04:58 +01:00
)
return new SvelteUIElement(LanguagePicker, {
assignTo: state.userRelatedState.language,
availableLanguages,
preferredLanguages: state.osmConnection.userDetails.map(
(ud) => ud?.languages ?? []
2025-02-10 02:04:58 +01:00
),
})
2025-02-10 02:04:58 +01:00
},
},
{
funcName: "disabled_questions",
group: "settings",
docs: "Shows which questions are disabled for every layer. Used in 'settings'",
needsUrls: [],
args: [],
constr(state) {
return new SvelteUIElement(DisabledQuestions, { state })
2025-02-10 02:04:58 +01:00
},
},
{
funcName: "gyroscope_all_tags",
group: "settings",
docs: "Shows the current tags of the GPS-representing object, used for debugging",
args: [],
constr(): SvelteUIElement {
return new SvelteUIElement(OrientationDebugPanel, {})
2025-02-10 02:04:58 +01:00
},
},
{
funcName: "gps_all_tags",
group: "settings",
docs: "Shows the current tags of the GPS-representing object, used for debugging",
args: [],
2025-02-10 02:04:58 +01:00
constr(state: SpecialVisualizationState): SvelteUIElement {
const tags = (<ThemeViewState>(
state
)).geolocation.currentUserLocation.features.map(
(features) => features[0]?.properties
)
return new SvelteUIElement(AllTagsPanel, {
state,
2025-02-10 02:04:58 +01:00
tags,
})
2025-02-10 02:04:58 +01:00
},
},
2025-02-03 22:03:14 +01:00
{
funcName: "storage_all_tags",
group: "settings",
docs: "Shows the current state of storage",
args: [],
2025-04-15 18:18:44 +02:00
constr: function (state: SpecialVisualizationState): SvelteUIElement {
2025-02-03 22:03:14 +01:00
const data = {}
for (const key in localStorage) {
data[key] = localStorage[key]
}
2025-04-06 00:30:59 +02:00
const tags = new UIEventSource(data)
2025-04-15 18:18:44 +02:00
navigator.storage.estimate().then((estimate) => {
2025-04-06 00:30:59 +02:00
data["__usage:current:bytes"] = estimate.usage
data["__usage:current:human"] = Utils.toHumanByteSize(estimate.usage)
data["__usage:quota:bytes"] = estimate.quota
data["__usage:quota:human"] = Utils.toHumanByteSize(estimate.quota)
tags.ping()
})
2025-02-03 22:03:14 +01:00
return new SvelteUIElement(AllTagsPanel, { state, tags })
2025-04-15 18:18:44 +02:00
},
2025-02-03 22:03:14 +01:00
},
{
funcName: "clear_caches",
docs: "A button which clears the locally downloaded data and the service worker. Login status etc will be kept",
args: [
{
name: "text",
required: true,
2025-02-10 02:04:58 +01:00
doc: "The text to show on the button",
},
],
group: "settings",
constr(
_: SpecialVisualizationState,
__: UIEventSource<Record<string, string>>,
2025-02-03 22:03:14 +01:00
argument: string[]
): SvelteUIElement {
return new SvelteUIElement(ClearCaches, {
2025-02-10 02:04:58 +01:00
msg: argument[0] ?? "Clear local caches",
})
2025-02-10 02:04:58 +01:00
},
},
{
funcName: "login_button",
2025-03-17 02:54:12 +01:00
args: [
{
name: "force",
doc: "Always show this button, even if logged in",
},
{
name: "message",
doc: "Message to display on the button",
},
],
docs: "Show a login button",
needsUrls: [],
group: "settings",
constr(state: SpecialVisualizationState, _, args): SvelteUIElement {
const force = args[0].toLowerCase()
let msg = args[1]
if (msg === "") {
msg = undefined
}
return new SvelteUIElement(LoginButton, {
osmConnection: state.osmConnection,
msg,
2025-03-17 02:54:12 +01:00
forceShow: force === "yes" || force === "true",
})
2025-02-10 02:04:58 +01:00
},
},
{
funcName: "qr_login",
args: [],
docs: "A QR-code which shares the current URL and adds the login token. Anyone with this login token will have the same permissions as you currently have. Logging out from this session will also log them out",
group: "settings",
constr(state: SpecialVisualizationState, tags: UIEventSource<Record<string, string>>, argument: string[], feature: Feature, layer: LayerConfig): SvelteUIElement {
const shared_oauth_cookie = state.osmConnection.getToken()
return new SvelteUIElement(QrCode, {
state,
tags,
feature,
extraUrlParams: { shared_oauth_cookie }
})
}
},
{
funcName: "logout",
args: [],
needsUrls: [Constants.osmAuthConfig.url],
docs: "Shows a button where the user can log out",
group: "settings",
constr(state: SpecialVisualizationState): SvelteUIElement {
return new SvelteUIElement(LogoutButton, { osmConnection: state.osmConnection })
2025-02-10 02:04:58 +01:00
},
},
{
funcName: "pending_changes",
docs: "A module showing the pending changes, with the option to clear the pending changes",
group: "settings",
args: [],
constr(state: SpecialVisualizationState): SvelteUIElement {
return new SvelteUIElement(PendingChangesIndicator, { state, compact: false })
2025-02-10 02:04:58 +01:00
},
},
]
}
}