fixes and refactor

This commit is contained in:
Liyas Thomas
2021-05-14 05:50:17 +00:00
committed by GitHub
parent 2b8cda40a2
commit 8f09c82763
13 changed files with 107 additions and 87 deletions

View File

@@ -5,7 +5,7 @@
<SmartTab <SmartTab
:id="'team-collections'" :id="'team-collections'"
:label="'Team Collections'" :label="'Team Collections'"
v-if="currentUser && currentUser.eaInvited" v-if="currentUser && currentUser.eaInvited && !doc"
> >
<ul> <ul>
<li> <li>
@@ -40,6 +40,7 @@ import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
export default { export default {
props: { props: {
doc: Boolean,
show: Boolean, show: Boolean,
}, },
subscriptions() { subscriptions() {

View File

@@ -13,6 +13,7 @@
<CollectionsChooseType <CollectionsChooseType
:collectionsType="collectionsType" :collectionsType="collectionsType"
:show="showTeamCollections" :show="showTeamCollections"
:doc="doc"
@update-collection-type="updateCollectionType" @update-collection-type="updateCollectionType"
@update-selected-team="updateSelectedTeam" @update-selected-team="updateSelectedTeam"
/> />
@@ -108,7 +109,8 @@
@edit-folder="editFolder($event)" @edit-folder="editFolder($event)"
@edit-request="editRequest($event)" @edit-request="editRequest($event)"
@update-team-collections="updateTeamCollections" @update-team-collections="updateTeamCollections"
@select-collection="$emit('use-collection', index)" @select-collection="$emit('use-collection', collection)"
@unselect-collection="$emit('remove-collection', collection)"
@select-folder=" @select-folder="
$emit('select-folder', { $emit('select-folder', {
folderName: folderName:
@@ -128,11 +130,10 @@
picked = $event.id picked = $event.id
} }
" "
@unselect-collection="$emit('remove-collection', collection)"
@expand-collection="expandCollection" @expand-collection="expandCollection"
@remove-collection="removeCollection" @remove-collection="removeCollection"
@remove-request="removeRequest" @remove-request="removeRequest"
:picked="picked" :picked="picked.toString()"
/> />
</li> </li>
</ul> </ul>

View File

@@ -12,7 +12,9 @@
<button class="icon" @click="toggleShowChildren"> <button class="icon" @click="toggleShowChildren">
<i class="material-icons" v-show="!showChildren && !isFiltered">arrow_right</i> <i class="material-icons" v-show="!showChildren && !isFiltered">arrow_right</i>
<i class="material-icons" v-show="showChildren || isFiltered">arrow_drop_down</i> <i class="material-icons" v-show="showChildren || isFiltered">arrow_drop_down</i>
<i v-if="picked === collectionIndex" class="text-green-400 material-icons">check_circle</i> <i v-if="picked === collectionIndex.toString()" class="text-green-400 material-icons"
>check_circle</i
>
<i v-else class="material-icons">folder</i> <i v-else class="material-icons">folder</i>
<span>{{ collection.name }}</span> <span>{{ collection.name }}</span>
</button> </button>
@@ -92,7 +94,7 @@
}) })
" "
@remove-request="removeRequest" @remove-request="removeRequest"
:picked="picked" :picked="picked.toString()"
/> />
</li> </li>
</ul> </ul>

View File

@@ -99,7 +99,7 @@
" "
@expand-collection="expandCollection" @expand-collection="expandCollection"
@remove-request="removeRequest" @remove-request="removeRequest"
:picked="picked" :picked="picked.toString()"
/> />
</li> </li>
</ul> </ul>
@@ -110,7 +110,7 @@
class="ml-8 border-l border-brdColor" class="ml-8 border-l border-brdColor"
> >
<CollectionsTeamsRequest <CollectionsTeamsRequest
:request="JSON.parse(request.request)" :request="request.request"
:collection-index="collectionIndex" :collection-index="collectionIndex"
:folder-index="-1" :folder-index="-1"
:folder-name="collection.name" :folder-name="collection.name"

View File

@@ -93,7 +93,7 @@
class="flex ml-8 border-l border-brdColor" class="flex ml-8 border-l border-brdColor"
> >
<CollectionsTeamsRequest <CollectionsTeamsRequest
:request="JSON.parse(request.request)" :request="request.request"
:collection-index="collectionIndex" :collection-index="collectionIndex"
:folder-index="folderIndex" :folder-index="folderIndex"
:folder-name="folder.name" :folder-name="folder.name"

View File

@@ -4,10 +4,14 @@
<i class="material-icons">folder</i> <i class="material-icons">folder</i>
{{ collection.name || $t("none") }} {{ collection.name || $t("none") }}
</h2> </h2>
<span class="folder" v-for="(folder, index) in collection.folders" :key="index"> <span
class="folder"
v-for="(folder, index) in collection.folders"
:key="`sub-collection-${index}`"
>
<DocsFolder :folder="folder" /> <DocsFolder :folder="folder" />
</span> </span>
<div v-for="(request, index) in collection.requests" :key="index"> <div v-for="(request, index) in collection.requests" :key="`request-${index}`">
<DocsRequest :request="request" /> <DocsRequest :request="request" />
</div> </div>
</div> </div>

View File

@@ -165,6 +165,7 @@
<script> <script>
import * as team_utils from "~/helpers/teams/utils" import * as team_utils from "~/helpers/teams/utils"
import cloneDeep from "lodash/cloneDeep" import cloneDeep from "lodash/cloneDeep"
import TeamMemberAdapter from "~/helpers/teams/TeamMemberAdapter"
export default { export default {
props: { props: {
@@ -177,21 +178,19 @@ export default {
rename: null, rename: null,
doneButton: '<i class="material-icons">done</i>', doneButton: '<i class="material-icons">done</i>',
members: [], members: [],
membersSubject: null,
membersSubscription: null,
newMembers: [], newMembers: [],
membersAdapter: new TeamMemberAdapter(null),
} }
}, },
mounted() {
this.membersAdapter.members$.subscribe((list) => {
console.log(list)
this.members = cloneDeep(list)
})
},
watch: { watch: {
editingteamID(teamID) { editingteamID(teamID) {
team_utils.getLiveTeamMembersList(this.$apollo, teamID).then((subject) => { this.membersAdapter.changeTeamID(teamID)
this.membersSubject = subject
this.membersSubscription = this.membersSubject.subscribe((memberList) => {
console.log(memberList)
this.members = cloneDeep(memberList)
})
})
}, },
}, },
computed: { computed: {

View File

@@ -32,13 +32,12 @@
class="icon" class="icon"
@click="exitTeam" @click="exitTeam"
v-close-popover v-close-popover
:disabled="!(team.myRole === 'OWNER' && team.ownersCount == 1)" :disabled="team.myRole === 'OWNER' && team.ownersCount == 1"
> >
<i class="material-icons">remove</i> <i class="material-icons">remove</i>
<div <div
v-tooltip.left="{ v-tooltip.left="{
content: content: team.myRole === 'OWNER' && team.ownersCount == 1 ? $t('disable_exit') : '',
team.myRole === 'OWNER' && team.ownersCount == 1 ? null : $t('disable_exit'),
}" }"
> >
<span>{{ $t("exit") }}</span> <span>{{ $t("exit") }}</span>

View File

@@ -1,5 +1,16 @@
<template> <template>
<AppSection class="green" icon="history" :label="$t('teams')" ref="teams" no-legend> <AppSection class="green" icon="history" :label="$t('teams')" ref="teams" no-legend>
<div class="flex flex-col">
<label>{{ $t("teams") }}</label>
<div v-if="fb.currentUser"></div>
<div v-else>
<label>{{ $t("login_with") }}</label>
<p>
<FirebaseLogin />
</p>
</div>
</div>
<TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" /> <TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
<TeamsEdit <TeamsEdit
:team="myTeams[0]" :team="myTeams[0]"
@@ -53,6 +64,7 @@ ul {
<script> <script>
import gql from "graphql-tag" import gql from "graphql-tag"
import { fb } from "~/helpers/fb"
export default { export default {
data() { data() {
@@ -64,6 +76,7 @@ export default {
editingteamID: "", editingteamID: "",
me: {}, me: {},
myTeams: [], myTeams: [],
fb,
} }
}, },
apollo: { apollo: {

View File

@@ -50,12 +50,8 @@ const wsLink = new WebSocketLink({
reconnect: true, reconnect: true,
lazy: true, lazy: true,
connectionParams: () => { connectionParams: () => {
if (authToken) { return {
return {} authorization: `Bearer ${authToken}`,
} else {
return {
authorization: `Bearer ${authToken}`,
}
} }
}, },
}, },

View File

@@ -466,6 +466,8 @@ export default class TeamCollectionAdapter {
}, },
}) })
.subscribe(({ data }) => { .subscribe(({ data }) => {
console.log("from adapter")
this.updateRequest({ this.updateRequest({
id: data.teamRequestUpdated.id, id: data.teamRequestUpdated.id,
collectionID: data.teamRequestUpdated.collectionID, collectionID: data.teamRequestUpdated.collectionID,
@@ -526,7 +528,7 @@ export default class TeamCollectionAdapter {
id: el.id, id: el.id,
collectionID: collectionID, collectionID: collectionID,
title: el.title, title: el.title,
request: el.request, request: JSON.parse(el.request),
} }
}) })

View File

@@ -12,7 +12,6 @@ interface TeamsTeamMember {
} }
export default class TeamMemberAdapter { export default class TeamMemberAdapter {
members$: BehaviorSubject<TeamsTeamMember[]> members$: BehaviorSubject<TeamsTeamMember[]>
private teamMemberAdded$: ZenObservable.Subscription | null private teamMemberAdded$: ZenObservable.Subscription | null
@@ -21,7 +20,7 @@ export default class TeamMemberAdapter {
constructor(private teamID: string | null) { constructor(private teamID: string | null) {
this.members$ = new BehaviorSubject<TeamsTeamMember[]>([]) this.members$ = new BehaviorSubject<TeamsTeamMember[]>([])
this.teamMemberAdded$ = null this.teamMemberAdded$ = null
this.teamMemberUpdated$ = null this.teamMemberUpdated$ = null
this.teamMemberRemoved$ = null this.teamMemberRemoved$ = null
@@ -66,72 +65,76 @@ export default class TeamMemberAdapter {
variables: { variables: {
teamID: this.teamID, teamID: this.teamID,
}, },
}); })
this.members$.next(data.team.members) this.members$.next(data.team.members)
} }
private registerSubscriptions() { private registerSubscriptions() {
this.teamMemberAdded$ = apolloClient.subscribe({ this.teamMemberAdded$ = apolloClient
query: gql` .subscribe({
subscription TeamMemberAdded($teamID: String!) { query: gql`
teamMemberAdded(teamID: $teamID) { subscription TeamMemberAdded($teamID: String!) {
user { teamMemberAdded(teamID: $teamID) {
uid user {
email uid
email
}
role
} }
role
} }
} `,
`, variables: {
variables: { teamID: this.teamID,
teamID: this.teamID },
} })
}).subscribe(({ data }) => { .subscribe(({ data }) => {
this.members$.next([...this.members$.value, data.teamMemberAdded]) this.members$.next([...this.members$.value, data.teamMemberAdded])
}) })
this.teamMemberRemoved$ = apolloClient.subscribe({ this.teamMemberRemoved$ = apolloClient
query: gql` .subscribe({
subscription TeamMemberRemoved($teamID: String!) { query: gql`
teamMemberRemoved(teamID: $teamID) subscription TeamMemberRemoved($teamID: String!) {
} teamMemberRemoved(teamID: $teamID)
`, }
variables: { `,
teamID: this.teamID variables: {
} teamID: this.teamID,
}).subscribe(({ data }) => { },
this.members$.next( })
this.members$.value.filter( .subscribe(({ data }) => {
el => el.user.uid !== data.teamMemberRemoved console.log(data)
this.members$.next(
this.members$.value.filter((el) => el.user.uid !== data.teamMemberRemoved)
) )
) })
})
this.teamMemberUpdated$ = apolloClient.subscribe({ this.teamMemberUpdated$ = apolloClient
query: gql` .subscribe({
subscription TeamMemberUpdated($teamID: String!) { query: gql`
teamMemberUpdated(teamID: $teamID) { subscription TeamMemberUpdated($teamID: String!) {
user { teamMemberUpdated(teamID: $teamID) {
uid user {
email uid
email
}
role
} }
role
} }
} `,
`, variables: {
variables: { teamID: this.teamID,
teamID: this.teamID },
} })
}).subscribe(({ data }) => { .subscribe(({ data }) => {
const list = cloneDeep(this.members$.value) const list = cloneDeep(this.members$.value)
const obj = list.find( const obj = list.find((el) => el.user.uid === data.teamMemberUpdated.user.uid)
el => el.user.uid === data.teamMemberUpdated.user.uid
)
if (!obj) return if (!obj) return
Object.assign(obj, data.teamMemberUpdated) Object.assign(obj, data.teamMemberUpdated)
}) })
} }
} }

View File

@@ -76,7 +76,7 @@
</div> </div>
</div> </div>
<div> <div>
<span v-for="(collection, index) in this.items" :key="index"> <span v-for="(collection, index) in this.items" :key="`collection-${index}`">
<DocsCollection :collection="collection" /> <DocsCollection :collection="collection" />
</span> </span>
</div> </div>