fix: teams list not properly showing
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<div class="mt-1 text-secondaryLight">
|
<div class="mt-1 text-secondaryLight">
|
||||||
<SmartAnchor
|
<SmartAnchor
|
||||||
:label="$t('team.join_beta')"
|
:label="`${$t('team.join_beta')}`"
|
||||||
to="https://hoppscotch.io/beta"
|
to="https://hoppscotch.io/beta"
|
||||||
blank
|
blank
|
||||||
class="link"
|
class="link"
|
||||||
@@ -13,21 +13,27 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="space-y-4 mt-4">
|
<div class="space-y-4 mt-4">
|
||||||
<ButtonSecondary
|
<ButtonSecondary
|
||||||
:label="$t('team.create_new')"
|
:label="`${$t('team.create_new')}`"
|
||||||
outline
|
outline
|
||||||
@click.native="displayModalAdd(true)"
|
@click.native="displayModalAdd(true)"
|
||||||
/>
|
/>
|
||||||
<p v-if="$apollo.queries.myTeams.loading">
|
<p v-if="!myTeamsLoading">
|
||||||
{{ $t("state.loading") }}
|
{{ $t("state.loading") }}
|
||||||
</p>
|
</p>
|
||||||
<div v-if="myTeams.length === 0" class="flex items-center">
|
<div
|
||||||
|
v-if="!myTeamsLoading && myTeams.myTeams.length === 0"
|
||||||
|
class="flex items-center"
|
||||||
|
>
|
||||||
<i class="mr-4 material-icons">help_outline</i>
|
<i class="mr-4 material-icons">help_outline</i>
|
||||||
{{ $t("empty.teams") }}
|
{{ $t("empty.teams") }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="grid gap-4 sm:grid-cols-2 md:grid-cols-3">
|
<div
|
||||||
|
v-else-if="!myTeamsLoading && !isApolloError(myTeams)"
|
||||||
|
class="grid gap-4 sm:grid-cols-2 md:grid-cols-3"
|
||||||
|
>
|
||||||
<TeamsTeam
|
<TeamsTeam
|
||||||
v-for="(team, index) in myTeams"
|
v-for="(team, index) in myTeams.myTeams"
|
||||||
:key="`team-${index}`"
|
:key="`team-${String(index)}`"
|
||||||
:team-i-d="team.id"
|
:team-i-d="team.id"
|
||||||
:team="team"
|
:team="team"
|
||||||
@edit-team="editTeam(team, team.id)"
|
@edit-team="editTeam(team, team.id)"
|
||||||
@@ -35,94 +41,68 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
|
<TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
|
||||||
|
<!-- ¯\_(ツ)_/¯ -->
|
||||||
<TeamsEdit
|
<TeamsEdit
|
||||||
:team="myTeams[0]"
|
v-if="!myTeamsLoading && myTeams.myTeams.length > 0"
|
||||||
|
:team="myTeams.myTeams[0]"
|
||||||
:show="showModalEdit"
|
:show="showModalEdit"
|
||||||
:editing-team="editingTeam"
|
:editing-team="editingTeam"
|
||||||
:editingteam-i-d="editingteamID"
|
:editingteam-i-d="editingTeamID"
|
||||||
@hide-modal="displayModalEdit(false)"
|
@hide-modal="displayModalEdit(false)"
|
||||||
/>
|
/>
|
||||||
</AppSection>
|
</AppSection>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
import { defineComponent } from "@nuxtjs/composition-api"
|
import { gql } from "@apollo/client/core"
|
||||||
import gql from "graphql-tag"
|
import { ref } from "@nuxtjs/composition-api"
|
||||||
import { currentUser$ } from "~/helpers/fb/auth"
|
import { useGQLQuery, isApolloError } from "~/helpers/apollo"
|
||||||
import { useReadonlyStream } from "~/helpers/utils/composables"
|
|
||||||
|
|
||||||
export default defineComponent({
|
const showModalAdd = ref(false)
|
||||||
setup() {
|
const showModalEdit = ref(false)
|
||||||
return {
|
const editingTeam = ref<any>({}) // TODO: Check this out
|
||||||
currentUser: useReadonlyStream(currentUser$, null),
|
const editingTeamID = ref<any>("")
|
||||||
}
|
|
||||||
},
|
const { loading: myTeamsLoading, data: myTeams } = useGQLQuery({
|
||||||
data() {
|
query: gql`
|
||||||
return {
|
query GetMyTeams {
|
||||||
showModalAdd: false,
|
myTeams {
|
||||||
showModalEdit: false,
|
id
|
||||||
editingTeam: {},
|
name
|
||||||
editingteamID: "",
|
myRole
|
||||||
me: {},
|
ownersCount
|
||||||
myTeams: [],
|
members {
|
||||||
}
|
user {
|
||||||
},
|
photoURL
|
||||||
apollo: {
|
displayName
|
||||||
me: {
|
email
|
||||||
query: gql`
|
|
||||||
query GetMe {
|
|
||||||
me {
|
|
||||||
uid
|
uid
|
||||||
eaInvited
|
|
||||||
}
|
}
|
||||||
|
role
|
||||||
}
|
}
|
||||||
`,
|
}
|
||||||
pollInterval: 100000,
|
}
|
||||||
},
|
`,
|
||||||
myTeams: {
|
pollInterval: 10000,
|
||||||
query: gql`
|
|
||||||
query GetMyTeams {
|
|
||||||
myTeams {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
myRole
|
|
||||||
ownersCount
|
|
||||||
members {
|
|
||||||
user {
|
|
||||||
photoURL
|
|
||||||
displayName
|
|
||||||
email
|
|
||||||
uid
|
|
||||||
}
|
|
||||||
role
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
pollInterval: 10000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
beforeDestroy() {
|
|
||||||
document.removeEventListener("keydown", this._keyListener)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
displayModalAdd(shouldDisplay) {
|
|
||||||
this.showModalAdd = shouldDisplay
|
|
||||||
},
|
|
||||||
displayModalEdit(shouldDisplay) {
|
|
||||||
this.showModalEdit = shouldDisplay
|
|
||||||
|
|
||||||
if (!shouldDisplay) this.resetSelectedData()
|
|
||||||
},
|
|
||||||
editTeam(team, teamID) {
|
|
||||||
this.editingTeam = team
|
|
||||||
this.editingteamID = teamID
|
|
||||||
this.displayModalEdit(true)
|
|
||||||
},
|
|
||||||
resetSelectedData() {
|
|
||||||
this.$data.editingTeam = undefined
|
|
||||||
this.$data.editingteamID = undefined
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const displayModalAdd = (shouldDisplay: boolean) => {
|
||||||
|
showModalAdd.value = shouldDisplay
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayModalEdit = (shouldDisplay: boolean) => {
|
||||||
|
showModalEdit.value = shouldDisplay
|
||||||
|
|
||||||
|
if (!shouldDisplay) resetSelectedData()
|
||||||
|
}
|
||||||
|
const editTeam = (team: any, teamID: any) => {
|
||||||
|
editingTeam.value = team
|
||||||
|
editingTeamID.value = teamID
|
||||||
|
displayModalEdit(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetSelectedData = () => {
|
||||||
|
editingTeam.value = undefined
|
||||||
|
editingTeamID.value = undefined
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ import {
|
|||||||
ApolloClient,
|
ApolloClient,
|
||||||
HttpLink,
|
HttpLink,
|
||||||
InMemoryCache,
|
InMemoryCache,
|
||||||
|
QueryOptions,
|
||||||
|
OperationVariables,
|
||||||
split,
|
split,
|
||||||
|
ApolloError,
|
||||||
|
isApolloError as _isApolloError
|
||||||
} from "@apollo/client/core"
|
} from "@apollo/client/core"
|
||||||
import { WebSocketLink } from "@apollo/client/link/ws"
|
import { WebSocketLink } from "@apollo/client/link/ws"
|
||||||
import { setContext } from "@apollo/client/link/context"
|
import { setContext } from "@apollo/client/link/context"
|
||||||
import { getMainDefinition } from "@apollo/client/utilities"
|
import { getMainDefinition } from "@apollo/client/utilities"
|
||||||
|
import { ref, onMounted, onBeforeUnmount, Ref } from "@nuxtjs/composition-api"
|
||||||
import { authIdToken$ } from "./fb/auth"
|
import { authIdToken$ } from "./fb/auth"
|
||||||
|
|
||||||
let authToken: String | null = null
|
let authToken: String | null = null
|
||||||
@@ -84,3 +89,39 @@ export const apolloClient = new ApolloClient({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export function isApolloError(x: any): x is ApolloError {
|
||||||
|
return _isApolloError(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useGQLQuery<T = any, TVariables = OperationVariables>(
|
||||||
|
options: QueryOptions<TVariables, T>
|
||||||
|
): { loading: Ref<boolean>; data: Ref<T | ApolloError | undefined> } {
|
||||||
|
const loading = ref(true)
|
||||||
|
const data = ref<T | ApolloError | undefined>()
|
||||||
|
|
||||||
|
let subscription: ZenObservable.Subscription | null = null
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
subscription = apolloClient.watchQuery(options).subscribe((result) => {
|
||||||
|
if (result.error) {
|
||||||
|
data.value = result.error
|
||||||
|
} else {
|
||||||
|
data.value = result.data
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (subscription) {
|
||||||
|
subscription.unsubscribe()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
loading,
|
||||||
|
data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user