refactor: better team selector drop down

This commit is contained in:
liyasthomas
2022-02-25 08:06:33 +05:30
parent 0c96993cc0
commit 137de5dcc7

View File

@@ -12,33 +12,48 @@
:label="`${$t('collection.team_collections')}`" :label="`${$t('collection.team_collections')}`"
> >
<SmartIntersection @intersecting="onTeamSelectIntersect"> <SmartIntersection @intersecting="onTeamSelectIntersect">
<div class="select-wrapper"> <tippy
<select ref="options"
id="team" interactive
type="text" trigger="click"
autocomplete="off" theme="popover"
autofocus arrow
class="flex w-full px-4 py-2 font-semibold bg-transparent border-t appearance-none cursor-pointer border-dividerLight hover:bg-primaryDark" placement="bottom"
@change="updateSelectedTeam(myTeams[$event.target.value])" >
> <template #trigger>
<option <span
:key="undefined" v-tippy="{ theme: 'tooltip' }"
:value="undefined" :title="`${$t('collection.select_team')}`"
hidden class="bg-transparent border-t border-dividerLight select-wrapper"
disabled
selected
> >
{{ $t("collection.select_team") }} <ButtonSecondary
</option> v-if="collectionsType.selectedTeam"
<option :label="collectionsType.selectedTeam.name"
v-for="(team, index) in myTeams" class="flex-1 pr-8 rounded-none"
:key="`team-${String(index)}`" />
:value="String(index)" <ButtonSecondary
> v-else
{{ team.name }} :label="`${$t('collection.select_team')}`"
</option> class="flex-1 pr-8 rounded-none"
</select> />
</div> </span>
</template>
<SmartItem
v-for="(team, index) in myTeams"
:key="`team-${index}`"
:label="team.name"
:info-icon="
team.id === collectionsType.selectedTeam?.id ? 'done' : ''
"
:active-info-icon="team.id === collectionsType.selectedTeam?.id"
@click.native="
() => {
updateSelectedTeam(team)
options.tippy().hide()
}
"
/>
</tippy>
</SmartIntersection> </SmartIntersection>
</SmartTab> </SmartTab>
</SmartTabs> </SmartTabs>
@@ -46,7 +61,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { GetMyTeamsQuery } from "~/helpers/backend/graphql" import { ref } from "@nuxtjs/composition-api"
import { GetMyTeamsQuery, Team } from "~/helpers/backend/graphql"
import { onLoggedIn } from "~/helpers/fb/auth" import { onLoggedIn } from "~/helpers/fb/auth"
import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo" import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
import TeamListAdapter from "~/helpers/teams/TeamListAdapter" import TeamListAdapter from "~/helpers/teams/TeamListAdapter"
@@ -57,6 +73,10 @@ type TeamData = GetMyTeamsQuery["myTeams"][number]
defineProps<{ defineProps<{
doc: boolean doc: boolean
show: boolean show: boolean
collectionsType: {
type: "my-collections" | "team-collections"
selectedTeam: Team | undefined
}
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
@@ -82,6 +102,8 @@ const updateCollectionsType = (tabID: string) => {
emit("update-collection-type", tabID) emit("update-collection-type", tabID)
} }
const options = ref<any | null>(null)
const updateSelectedTeam = (team: TeamData | undefined) => { const updateSelectedTeam = (team: TeamData | undefined) => {
emit("update-selected-team", team) emit("update-selected-team", team)
} }