Skip to content

Commit

Permalink
fix(@desktop/onboarding): fetching waku data ui improvements
Browse files Browse the repository at this point in the history
- icon added to the ui items we're syncing
- in case data are fetched during 30 seconds timeframe the app is staying in success state
  • Loading branch information
saledjenic committed Jan 10, 2023
1 parent 0cc6477 commit d7e4ee2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/app/modules/startup/models/fetching_data_item.nim
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
type
Item* = ref object
entity: string
icon: string
trackOfLoadedMessages: seq[bool]
totalMessages: int

proc newItem*(entity: string, totalMessages: int = 0): Item =
proc newItem*(entity: string, icon: string, totalMessages: int = 0): Item =
result = Item()
result.entity = entity
result.icon = icon
result.trackOfLoadedMessages = @[]
result.totalMessages = totalMessages

proc entity*(self: Item): string =
return self.entity

proc icon*(self: Item): string =
return self.icon

proc loadedMessages*(self: Item): int =
if self.trackOfLoadedMessages.len == 0:
return 0
Expand Down
10 changes: 7 additions & 3 deletions src/app/modules/startup/models/fetching_data_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fetching_data_item
type
ModelRole {.pure.} = enum
Entity = UserRole + 1
Icon
LoadedMessages
TotalMessages

Expand Down Expand Up @@ -39,6 +40,7 @@ QtObject:
method roleNames(self: Model): Table[int, string] =
{
ModelRole.Entity.int:"entity",
ModelRole.Icon.int:"icon",
ModelRole.LoadedMessages.int:"loadedMessages",
ModelRole.TotalMessages.int:"totalMessages"
}.toTable
Expand All @@ -56,6 +58,8 @@ QtObject:
case enumRole:
of ModelRole.Entity:
result = newQVariant(item.entity())
of ModelRole.Icon:
result = newQVariant(item.icon())
of ModelRole.LoadedMessages:
result = newQVariant(item.loadedMessages())
of ModelRole.TotalMessages:
Expand All @@ -67,10 +71,10 @@ QtObject:
return i
return -1

proc init*(self: Model, entities: seq[string]) =
proc init*(self: Model, entities: seq[tuple[entity: string, icon: string]]) =
self.beginResetModel()
for s in entities:
self.items.add(newItem(s))
for e in entities:
self.items.add(newItem(e.entity, e.icon))
self.endResetModel()
self.countChanged()

Expand Down
23 changes: 16 additions & 7 deletions src/app/modules/startup/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ logScope:
topics = "startup-module"

const FetchingFromWakuProfile = "profile"
const FetchingFromWakuProfileIcon = "profile"
const FetchingFromWakuContacts = "contacts"
const FetchingFromWakuContactsIcon = "contact-book"
const FetchingFromWakuCommunities = "communities"
const FetchingFromWakuCommunitiesIcon = "communities"
const FetchingFromWakuSettings = "settings"
const FetchingFromWakuSettingsIcon = "settings"

type
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
Expand Down Expand Up @@ -319,8 +323,12 @@ method onFetchingFromWakuMessageReceived*[T](self: Module[T], section: string, t

proc prepareAndInitFetchingData[T](self: Module[T]) =
# fetching data from waku starts when messenger starts
const listOfEntitiesWeExpectToBeSynced = @[FetchingFromWakuProfile, FetchingFromWakuContacts, FetchingFromWakuCommunities,
FetchingFromWakuSettings]
const listOfEntitiesWeExpectToBeSynced = @[
(FetchingFromWakuProfile, FetchingFromWakuProfileIcon),
(FetchingFromWakuContacts, FetchingFromWakuContactsIcon),
(FetchingFromWakuCommunities, FetchingFromWakuCommunitiesIcon),
(FetchingFromWakuSettings, FetchingFromWakuSettingsIcon)
]
self.view.createAndInitFetchingDataModel(listOfEntitiesWeExpectToBeSynced)

proc delayStartingApp[T](self: Module[T]) =
Expand All @@ -331,11 +339,12 @@ proc delayStartingApp[T](self: Module[T]) =
self.controller.connectToTimeoutEventAndStratTimer(timeoutInMilliseconds = 30000) # delay for 30 seconds

method startAppAfterDelay*[T](self: Module[T]) =
let currStateObj = self.view.currentStartupStateObj()
if currStateObj.isNil:
error "cannot determine current startup state"
quit() # quit the app
self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil))
if not self.view.fetchingDataModel().allMessagesLoaded():
let currStateObj = self.view.currentStartupStateObj()
if currStateObj.isNil:
error "cannot determine current startup state"
quit() # quit the app
self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil))
self.moveToStartupState()

proc logoutAndDisplayError[T](self: Module[T], error: string) =
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/startup/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ QtObject:
read = getFetchingDataModel
notify = fetchingDataModelChanged

proc createAndInitFetchingDataModel*(self: View, sections: seq[string]) =
proc createAndInitFetchingDataModel*(self: View, sections: seq[tuple[entity: string, icon: string]]) =
if self.fetchingDataModel.isNil:
self.fetchingDataModel = fetch_model.newModel()
if self.fetchingDataModelVariant.isNil:
Expand Down

0 comments on commit d7e4ee2

Please sign in to comment.