Skip to content

Commit

Permalink
Issue mozilla-mobile#10611 - Add a new SelectOrAddUseCase for reopeni…
Browse files Browse the repository at this point in the history
…ng existing tab with matching HistoryMetadataKey
  • Loading branch information
gabrielluong committed Jul 15, 2021
1 parent cd897a8 commit d80c99d
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import mozilla.components.browser.state.state.recover.toTabSessionStates
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
import mozilla.components.concept.storage.HistoryMetadataKey
import mozilla.components.feature.session.SessionUseCases.LoadUrlUseCase

/**
Expand Down Expand Up @@ -122,6 +123,22 @@ class TabsUseCases(
this.invoke(url, selectTab = true, startLoading = true, parentId = null, flags = flags)
}

operator fun invoke(
url: String,
selectTab: Boolean,
startLoading: Boolean,
historyMetadata: HistoryMetadataKey,
): String {
val tab = store.state.tabs.find { it.historyMetadata == historyMetadata }

return if (tab != null) {
store.dispatch(TabListAction.SelectTabAction(tab.id))
tab.id
} else {
this.invoke(url, selectTab = selectTab, startLoading = startLoading)
}
}

/**
* Adds a new tab and loads the provided URL.
*
Expand Down

0 comments on commit d80c99d

Please sign in to comment.