UX: make settings available if not logged in

This commit is contained in:
Pieter Vander Vennet 2025-01-21 20:47:57 +01:00
parent 3bf099c14a
commit 87c68cedc7
4 changed files with 30 additions and 24 deletions

View file

@ -146,7 +146,7 @@ export class OsmConnection {
this.UpdateCapabilities() this.UpdateCapabilities()
this.isLoggedIn = this.userDetails.map( this.isLoggedIn = this.userDetails.map(
(user) => user !== undefined && (this.apiIsOnline.data === "unknown" || this.apiIsOnline.data === "online"), (user) => user !== undefined && this.apiIsOnline.data === "online",
[this.apiIsOnline] [this.apiIsOnline]
) )
@ -578,8 +578,10 @@ export class OsmConnection {
if (!(this.apiIsOnline.data === "unreachable" || this.apiIsOnline.data === "offline")) { if (!(this.apiIsOnline.data === "unreachable" || this.apiIsOnline.data === "offline")) {
return return
} }
if (!this.isLoggedIn.data) {
return
}
try { try {
console.log("Api is offline - trying to reconnect...")
this.AttemptLogin() this.AttemptLogin()
} catch (e) { } catch (e) {
console.log("Could not login due to", e) console.log("Could not login due to", e)

View file

@ -5,10 +5,7 @@ import { TagUtils } from "../../Logic/Tags/TagUtils"
import { And } from "../../Logic/Tags/And" import { And } from "../../Logic/Tags/And"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { Tag } from "../../Logic/Tags/Tag" import { Tag } from "../../Logic/Tags/Tag"
import { import { MappingConfigJson, QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson"
MappingConfigJson,
QuestionableTagRenderingConfigJson,
} from "./Json/QuestionableTagRenderingConfigJson"
import Validators, { ValidatorType } from "../../UI/InputElement/Validators" import Validators, { ValidatorType } from "../../UI/InputElement/Validators"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson" import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import { RegexTag } from "../../Logic/Tags/RegexTag" import { RegexTag } from "../../Logic/Tags/RegexTag"
@ -82,6 +79,7 @@ export default class TagRenderingConfig {
public readonly classes: string[] | undefined public readonly classes: string[] | undefined
public readonly onSoftDelete?: ReadonlyArray<UploadableTag> public readonly onSoftDelete?: ReadonlyArray<UploadableTag>
public readonly alwaysForceSaveButton: boolean
constructor( constructor(
config: config:
@ -144,6 +142,7 @@ export default class TagRenderingConfig {
this.question = Translations.T(json.question, translationKey + ".question") this.question = Translations.T(json.question, translationKey + ".question")
this.questionhint = Translations.T(json.questionHint, translationKey + ".questionHint") this.questionhint = Translations.T(json.questionHint, translationKey + ".questionHint")
this.questionHintIsMd = json["questionHintIsMd"] ?? false this.questionHintIsMd = json["questionHintIsMd"] ?? false
this.alwaysForceSaveButton = json["#force-save-button"] === "yes"
this.description = Translations.T(json.description, translationKey + ".description") this.description = Translations.T(json.description, translationKey + ".description")
if (json.onSoftDelete && !Array.isArray(json.onSoftDelete)) { if (json.onSoftDelete && !Array.isArray(json.onSoftDelete)) {
throw context + ".onSoftDelete Not an array: " + typeof json.onSoftDelete throw context + ".onSoftDelete Not an array: " + typeof json.onSoftDelete

View file

@ -124,12 +124,6 @@
</svelte:fragment> </svelte:fragment>
<!-- All shown components are set by 'usersettings.json', which happily uses some special visualisations created specifically for it --> <!-- All shown components are set by 'usersettings.json', which happily uses some special visualisations created specifically for it -->
<LoginToggle {state} silentFail>
<div class="flex flex-col" slot="not-logged-in">
<LanguagePicker availableLanguages={theme.language} />
<Tr cls="alert" t={Translations.t.userinfo.notLoggedIn} />
<LoginButton clss="primary" osmConnection={state.osmConnection} />
</div>
<SelectedElementView <SelectedElementView
highlightedRendering={state.guistate.highlightedUserSetting} highlightedRendering={state.guistate.highlightedUserSetting}
layer={usersettingslayer} layer={usersettingslayer}
@ -141,7 +135,6 @@
{state} {state}
tags={state.userRelatedState.preferencesAsTags} tags={state.userRelatedState.preferencesAsTags}
/> />
</LoginToggle>
</Page> </Page>
<LoginToggle {state} silentFail> <LoginToggle {state} silentFail>

View file

@ -14,7 +14,6 @@
import TagHint from "../TagHint.svelte" import TagHint from "../TagHint.svelte"
import LoginToggle from "../../Base/LoginToggle.svelte" import LoginToggle from "../../Base/LoginToggle.svelte"
import SubtleButton from "../../Base/SubtleButton.svelte" import SubtleButton from "../../Base/SubtleButton.svelte"
import Loading from "../../Base/Loading.svelte"
import TagRenderingMappingInput from "./TagRenderingMappingInput.svelte" import TagRenderingMappingInput from "./TagRenderingMappingInput.svelte"
import { Translation } from "../../i18n/Translation" import { Translation } from "../../i18n/Translation"
import Constants from "../../../Models/Constants" import Constants from "../../../Models/Constants"
@ -119,7 +118,7 @@
seenFreeforms.push(newProps[confg.freeform.key]) seenFreeforms.push(newProps[confg.freeform.key])
} }
return matches return matches
}), })
] ]
if (tgs !== undefined && confg.freeform) { if (tgs !== undefined && confg.freeform) {
@ -227,7 +226,7 @@
freeform: $freeformInput, freeform: $freeformInput,
selectedMapping, selectedMapping,
checkedMappings, checkedMappings,
currentTags: tags.data, currentTags: tags.data
}, },
" --> ", " --> ",
selectedTags selectedTags
@ -285,7 +284,7 @@
dispatch("saved", { config, applied: selectedTags }) dispatch("saved", { config, applied: selectedTags })
const change = new ChangeTagAction(tags.data.id, selectedTags, tags.data, { const change = new ChangeTagAction(tags.data.id, selectedTags, tags.data, {
theme: tags.data["_orig_theme"] ?? state.theme.id, theme: tags.data["_orig_theme"] ?? state.theme.id,
changeType: "answer", changeType: "answer"
}) })
freeformInput.set(undefined) freeformInput.set(undefined)
selectedMapping = undefined selectedMapping = undefined
@ -329,7 +328,7 @@
const tagsToSet = settableKeys.data.map((k) => new Tag(k, "")) const tagsToSet = settableKeys.data.map((k) => new Tag(k, ""))
const change = new ChangeTagAction(tags.data.id, new And(tagsToSet), tags.data, { const change = new ChangeTagAction(tags.data.id, new And(tagsToSet), tags.data, {
theme: tags.data["_orig_theme"] ?? state.theme.id, theme: tags.data["_orig_theme"] ?? state.theme.id,
changeType: "answer", changeType: "answer"
}) })
freeformInput.set(undefined) freeformInput.set(undefined)
selectedMapping = undefined selectedMapping = undefined
@ -542,12 +541,25 @@
{/if} {/if}
<!-- Save and cancel buttons, in a logintoggle --> <!-- Save and cancel buttons, in a logintoggle -->
<LoginToggle {state}> <LoginToggle {state} ignoreLoading>
<Loading slot="loading" /> <div class="flex w-full justify-end" slot="not-logged-in">
<SubtleButton slot="not-logged-in" on:click={() => state?.osmConnection?.AttemptLogin()}> {#if config.alwaysForceSaveButton}
<Login slot="image" class="h-8 w-8" /> <button
<Tr t={Translations.t.general.loginToStart} slot="message" /> on:click={() => onSave()}
</SubtleButton> class={twJoin(
selectedTags === undefined ? "disabled" : "button-shadow",
"primary"
)}
>
<Tr t={Translations.t.general.save} />
</button>
{:else}
<SubtleButton on:click={() => state?.osmConnection?.AttemptLogin()}>
<Login slot="image" class="h-8 w-8" />
<Tr t={Translations.t.general.loginToStart} slot="message" />
</SubtleButton>
{/if}
</div>
{#if $feedback !== undefined} {#if $feedback !== undefined}
<div class="alert" aria-live="assertive" role="alert"> <div class="alert" aria-live="assertive" role="alert">
<Tr t={$feedback} /> <Tr t={$feedback} />