forked from MapComplete/MapComplete
Scroll focused setting into view
This commit is contained in:
parent
978603b2f0
commit
8603c409fc
3 changed files with 47 additions and 18 deletions
|
@ -87,6 +87,9 @@ class SingleUserSettingsPanel extends EditableTagRendering {
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserInformationMainPanel extends VariableUiElement {
|
class UserInformationMainPanel extends VariableUiElement {
|
||||||
|
private readonly settings: UIEventSource<Record<string, BaseUIElement>>
|
||||||
|
private readonly userInfoFocusedQuestion?: UIEventSource<string>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
osmConnection: OsmConnection,
|
osmConnection: OsmConnection,
|
||||||
locationControl: UIEventSource<Loc>,
|
locationControl: UIEventSource<Loc>,
|
||||||
|
@ -97,6 +100,7 @@ class UserInformationMainPanel extends VariableUiElement {
|
||||||
const t = Translations.t.userinfo
|
const t = Translations.t.userinfo
|
||||||
const imgSize = "h-6 w-6"
|
const imgSize = "h-6 w-6"
|
||||||
const ud = osmConnection.userDetails
|
const ud = osmConnection.userDetails
|
||||||
|
const settings = new UIEventSource<Record<string, BaseUIElement>>({})
|
||||||
|
|
||||||
const amendedPrefs = new UIEventSource<any>({})
|
const amendedPrefs = new UIEventSource<any>({})
|
||||||
osmConnection.preferencesHandler.preferences.addCallback((newPrefs) => {
|
osmConnection.preferencesHandler.preferences.addCallback((newPrefs) => {
|
||||||
|
@ -173,15 +177,18 @@ class UserInformationMainPanel extends VariableUiElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
const usersettingsConfig = new LayerConfig(usersettings, "userinformationpanel")
|
const usersettingsConfig = new LayerConfig(usersettings, "userinformationpanel")
|
||||||
|
const settingElements = []
|
||||||
const questions = usersettingsConfig.tagRenderings.map((c) =>
|
for (const c of usersettingsConfig.tagRenderings) {
|
||||||
new SingleUserSettingsPanel(
|
const settingsPanel = new SingleUserSettingsPanel(
|
||||||
c,
|
c,
|
||||||
osmConnection,
|
osmConnection,
|
||||||
amendedPrefs,
|
amendedPrefs,
|
||||||
userInfoFocusedQuestion
|
userInfoFocusedQuestion
|
||||||
).SetClass("block my-4")
|
).SetClass("block my-4")
|
||||||
)
|
settings.data[c.id] = settingsPanel
|
||||||
|
settingElements.push(settingsPanel)
|
||||||
|
}
|
||||||
|
settings.ping()
|
||||||
|
|
||||||
return new Combine([
|
return new Combine([
|
||||||
new Combine([img, description]).SetClass("flex border border-black rounded-md"),
|
new Combine([img, description]).SetClass("flex border border-black rounded-md"),
|
||||||
|
@ -189,7 +196,7 @@ class UserInformationMainPanel extends VariableUiElement {
|
||||||
layout.language,
|
layout.language,
|
||||||
Translations.t.general.pickLanguage.Clone()
|
Translations.t.general.pickLanguage.Clone()
|
||||||
),
|
),
|
||||||
...questions,
|
...settingElements,
|
||||||
new SubtleButton(
|
new SubtleButton(
|
||||||
Svg.envelope_svg(),
|
Svg.envelope_svg(),
|
||||||
new Combine([
|
new Combine([
|
||||||
|
@ -216,10 +223,26 @@ class UserInformationMainPanel extends VariableUiElement {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
this.SetClass("flex flex-col")
|
this.SetClass("flex flex-col")
|
||||||
|
this.settings = settings
|
||||||
|
this.userInfoFocusedQuestion = userInfoFocusedQuestion
|
||||||
|
const self = this
|
||||||
|
userInfoFocusedQuestion.addCallbackD((_) => {
|
||||||
|
self.focusOnSelectedQuestion()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public focusOnSelectedQuestion() {
|
||||||
|
const focusedId = this.userInfoFocusedQuestion.data
|
||||||
|
console.log("Focusing on", focusedId, this.settings.data[focusedId])
|
||||||
|
if (focusedId === undefined) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.settings.data[focusedId]?.ScrollIntoView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class UserInformationPanel extends ScrollableFullScreen {
|
export default class UserInformationPanel extends ScrollableFullScreen {
|
||||||
|
private readonly userPanel: UserInformationMainPanel
|
||||||
constructor(
|
constructor(
|
||||||
state: {
|
state: {
|
||||||
readonly layoutToUse: LayoutConfig
|
readonly layoutToUse: LayoutConfig
|
||||||
|
@ -233,6 +256,13 @@ export default class UserInformationPanel extends ScrollableFullScreen {
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const isOpened = options?.isOpened ?? new UIEventSource<boolean>(false)
|
const isOpened = options?.isOpened ?? new UIEventSource<boolean>(false)
|
||||||
|
const userPanel = new UserInformationMainPanel(
|
||||||
|
state.osmConnection,
|
||||||
|
state.locationControl,
|
||||||
|
state.layoutToUse,
|
||||||
|
isOpened,
|
||||||
|
options?.userInfoFocusedQuestion
|
||||||
|
)
|
||||||
super(
|
super(
|
||||||
() => {
|
() => {
|
||||||
return new VariableUiElement(
|
return new VariableUiElement(
|
||||||
|
@ -244,20 +274,15 @@ export default class UserInformationPanel extends ScrollableFullScreen {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
() =>
|
() => new LoginToggle(userPanel, Translations.t.general.getStartedLogin, state),
|
||||||
new LoginToggle(
|
|
||||||
new UserInformationMainPanel(
|
|
||||||
state.osmConnection,
|
|
||||||
state.locationControl,
|
|
||||||
state.layoutToUse,
|
|
||||||
isOpened,
|
|
||||||
options?.userInfoFocusedQuestion
|
|
||||||
),
|
|
||||||
Translations.t.general.getStartedLogin,
|
|
||||||
state
|
|
||||||
),
|
|
||||||
"userinfo",
|
"userinfo",
|
||||||
isOpened
|
isOpened
|
||||||
)
|
)
|
||||||
|
this.userPanel = userPanel
|
||||||
|
}
|
||||||
|
|
||||||
|
Activate() {
|
||||||
|
super.Activate()
|
||||||
|
this.userPanel.focusOnSelectedQuestion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ export class ImageUploadFlow extends Toggle {
|
||||||
})
|
})
|
||||||
.SetClass("underline"),
|
.SetClass("underline"),
|
||||||
]).SetStyle("font-size:small;"),
|
]).SetStyle("font-size:small;"),
|
||||||
]).SetClass("flex flex-col image-upload-flow mt-4 mb-8 text-center")
|
]).SetClass("flex flex-col image-upload-flow mt-4 mb-8 text-center leading-none")
|
||||||
|
|
||||||
super(
|
super(
|
||||||
new LoginToggle(
|
new LoginToggle(
|
||||||
|
|
|
@ -1687,6 +1687,10 @@ video {
|
||||||
font-variant-numeric: var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction);
|
font-variant-numeric: var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.leading-none {
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.tracking-tight {
|
.tracking-tight {
|
||||||
letter-spacing: -0.025em;
|
letter-spacing: -0.025em;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue