1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-2734 Global search | Save last search phrase (#1518)

This commit is contained in:
Konstantin Ivanov 2024-08-29 13:19:31 +02:00 committed by GitHub
parent 6bb9ef1716
commit fdbdc20f21
Signed by: github
GPG key ID: B5690EEEBB952194
35 changed files with 403 additions and 76 deletions

View file

@ -312,6 +312,54 @@ class DefaultUserSettingsCache(
}
}
override suspend fun setLastSearchQuery(query: String, space: SpaceId) {
context.spacePrefsStore.updateData { existingPreferences ->
val givenSpacePreference = existingPreferences
.preferences
.getOrDefault(
key = space.id,
defaultValue = SpacePreference()
)
val updated = givenSpacePreference.copy(
lastSearchQuery = query
)
val result = buildMap {
putAll(existingPreferences.preferences)
put(key = space.id, updated)
}
SpacePreferences(preferences = result)
}
}
override suspend fun getLastSearchQuery(space: SpaceId): String {
return context.spacePrefsStore
.data
.map { preferences ->
preferences
.preferences[space.id]
?.lastSearchQuery.orEmpty()
}
.first()
}
override suspend fun clearLastSearchQuery(space: SpaceId) {
context.spacePrefsStore.updateData { existingPreferences ->
val givenSpacePreference = existingPreferences
.preferences
.getOrDefault(key = space.id, defaultValue = SpacePreference())
val updated = givenSpacePreference.copy(
lastSearchQuery = null
)
val result = buildMap {
putAll(existingPreferences.preferences)
put(key = space.id, updated)
}
SpacePreferences(
preferences = result
)
}
}
companion object {
const val CURRENT_SPACE_KEY = "prefs.user_settings.current_space"
const val DEFAULT_OBJECT_TYPE_ID_KEY = "prefs.user_settings.default_object_type.id"

View file

@ -12,4 +12,5 @@ message SpacePreference {
optional string defaultObjectTypeKey = 1;
repeated string pinnedObjectTypeIds = 2;
optional string lastOpenedObject = 3;
optional string lastSearchQuery = 4;
}