feature(usersettings): Add option to show all questions at once

This commit is contained in:
Pieter Vander Vennet 2023-03-08 01:36:27 +01:00
parent 7bd3fcd490
commit 60f3499eb0
10 changed files with 72 additions and 26 deletions

View file

@ -161,9 +161,12 @@ export class OsmConnection {
public GetPreference(
key: string,
defaultValue: string = undefined,
prefix: string = "mapcomplete-"
options?: {
documentation?: string
prefix?: string
}
): UIEventSource<string> {
return this.preferencesHandler.GetPreference(key, defaultValue, prefix)
return this.preferencesHandler.GetPreference(key, defaultValue, options)
}
public GetLongPreference(key: string, prefix: string = "mapcomplete-"): UIEventSource<string> {

View file

@ -33,8 +33,9 @@ export class OsmPreferences {
this.longPreferences[prefix + key] = source
const allStartWith = prefix + key + "-combined"
const subOptions = { prefix: "" }
// Gives the number of combined preferences
const length = this.GetPreference(allStartWith + "-length", "", "")
const length = this.GetPreference(allStartWith + "-length", "", subOptions)
if ((allStartWith + "-length").length > 255) {
throw (
@ -56,9 +57,9 @@ export class OsmPreferences {
let count = parseInt(length.data)
for (let i = 0; i < count; i++) {
// Delete all the preferences
self.GetPreference(allStartWith + "-" + i, "", "").setData("")
self.GetPreference(allStartWith + "-" + i, "", subOptions).setData("")
}
self.GetPreference(allStartWith + "-length", "", "").setData("")
self.GetPreference(allStartWith + "-length", "", subOptions).setData("")
return
}
@ -70,7 +71,9 @@ export class OsmPreferences {
if (i > 100) {
throw "This long preference is getting very long... "
}
self.GetPreference(allStartWith + "-" + i, "", "").setData(str.substr(0, 255))
self.GetPreference(allStartWith + "-" + i, "", subOptions).setData(
str.substr(0, 255)
)
str = str.substr(255)
i++
}
@ -116,8 +119,12 @@ export class OsmPreferences {
public GetPreference(
key: string,
defaultValue: string = undefined,
prefix: string = "mapcomplete-"
options?: {
documentation?: string
prefix?: string
}
): UIEventSource<string> {
const prefix: string = options?.prefix ?? "mapcomplete-"
if (key.startsWith(prefix) && prefix !== "") {
console.trace(
"A preference was requested which has a duplicate prefix in its key. This is probably a bug"
@ -173,7 +180,7 @@ export class OsmPreferences {
const matches = prefixes.some((prefix) => key.startsWith(prefix))
if (matches) {
console.log("Clearing ", key)
self.GetPreference(key, "", "").setData("")
self.GetPreference(key, "", { prefix: "" }).setData("")
}
}
isRunning = false

View file

@ -34,10 +34,10 @@ export default class UserRelatedState extends ElementsState {
*/
public maprouletteConnection: Maproulette
public readonly isTranslator: Store<boolean>
public readonly installedUserThemes: Store<string[]>
public readonly showAllQuestionsAtOnce: UIEventSource<boolean>
constructor(layoutToUse: LayoutConfig, options?: { attemptLogin: true | boolean }) {
super(layoutToUse)
@ -73,7 +73,12 @@ export default class UserRelatedState extends ElementsState {
}
this.changes = new Changes(this, layoutToUse?.isLeftRightSensitive() ?? false)
this.showAllQuestionsAtOnce = UIEventSource.asBoolean(
this.osmConnection.GetPreference("show-all-questions", "false", {
documentation:
"Either 'true' or 'false'. If set, all questions will be shown all at once",
})
)
new ChangeToElementsActor(this.changes, this.allElements)
new PendingChangesUploader(this.changes, this.selectedElement)

View file

@ -754,4 +754,12 @@ export class UIEventSource<T> extends Store<T> {
}
return this
}
static asBoolean(stringUIEventSource: UIEventSource<string>) {
return stringUIEventSource.sync(
(str) => str === "true",
[],
(b) => "" + b
)
}
}

View file

@ -40,10 +40,8 @@ export class QueryParameters {
deflt: boolean,
documentation?: string
): UIEventSource<boolean> {
return QueryParameters.GetQueryParameter(key, "" + deflt, documentation).sync(
(str) => str === "true",
[],
(b) => "" + b
return UIEventSource.asBoolean(
QueryParameters.GetQueryParameter(key, "" + deflt, documentation)
)
}