feat: remember last selected team id (#2210)

Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Anwarul Islam
2022-04-02 15:47:37 +06:00
committed by GitHub
parent 183d5f3545
commit 8cafef48fb
4 changed files with 98 additions and 4 deletions

View File

@@ -70,6 +70,7 @@ import { onLoggedIn } from "~/helpers/fb/auth"
import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
import TeamListAdapter from "~/helpers/teams/TeamListAdapter"
import { useReadonlyStream } from "~/helpers/utils/composables"
import { useLocalState } from "~/newstore/localstate"
type TeamData = GetMyTeamsQuery["myTeams"][number]
@@ -94,7 +95,19 @@ const emit = defineEmits<{
const currentUser = useReadonlyStream(currentUserInfo$, null)
const adapter = new TeamListAdapter(true)
const myTeams = useReadonlyStream(adapter.teamList$, [])
const myTeams = useReadonlyStream(adapter.teamList$, null)
const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID")
let teamListFetched = false
watch(myTeams, (teams) => {
if (teams && !teamListFetched) {
teamListFetched = true
if (REMEMBERED_TEAM_ID.value && currentUser) {
const team = teams.find((t) => t.id === REMEMBERED_TEAM_ID.value)
if (team) updateSelectedTeam(team)
}
}
})
onLoggedIn(() => {
adapter.initialize()
@@ -112,6 +125,7 @@ const updateCollectionsType = (tabID: string) => {
const options = ref<any | null>(null)
const updateSelectedTeam = (team: TeamData | undefined) => {
REMEMBERED_TEAM_ID.value = team?.id
emit("update-selected-team", team)
}