From f9100245f20c088f185a8d5a1922bc6a468d7a12 Mon Sep 17 00:00:00 2001 From: bartosz-io Date: Tue, 5 Nov 2024 11:50:46 +0100 Subject: [PATCH 01/14] feat: add members space page --- apps/ui/src/components/App/Nav.vue | 20 ++++ apps/ui/src/networks/offchain/api/index.ts | 23 ++++ apps/ui/src/networks/offchain/api/queries.ts | 15 +++ apps/ui/src/networks/types.ts | 5 + apps/ui/src/routes/common.ts | 6 + apps/ui/src/views/Space/Members.vue | 120 +++++++++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 apps/ui/src/views/Space/Members.vue diff --git a/apps/ui/src/components/App/Nav.vue b/apps/ui/src/components/App/Nav.vue index 2791f38fc..efeab399c 100644 --- a/apps/ui/src/components/App/Nav.vue +++ b/apps/ui/src/components/App/Nav.vue @@ -10,6 +10,7 @@ import IHCog from '~icons/heroicons-outline/cog'; import IHGlobeAlt from '~icons/heroicons-outline/globe-alt'; import IHGlobe from '~icons/heroicons-outline/globe-americas'; import IHHome from '~icons/heroicons-outline/home'; +import IHIdentification from '~icons/heroicons-outline/identification'; import IHLightningBolt from '~icons/heroicons-outline/lightning-bolt'; import IHNewspaper from '~icons/heroicons-outline/newspaper'; import IHStop from '~icons/heroicons-outline/stop'; @@ -63,6 +64,17 @@ const canSeeSettings = computed(() => { return admins.includes(web3.value.account.toLowerCase()); } + return false; +}); + +const canSeeMembers = computed(() => { + const data = space.value?.additionalRawData; + + return ( + (data?.admins?.length ?? 0) > 0 || + (data?.moderators?.length ?? 0) > 0 || + (data?.members?.length ?? 0) > 0 + ); }); const navigationConfig = computed< @@ -81,6 +93,14 @@ const navigationConfig = computed< name: 'Leaderboard', icon: IHUserGroup }, + ...(canSeeMembers.value + ? { + members: { + name: 'Members', + icon: IHIdentification + } + } + : undefined), ...(space.value?.delegations && space.value.delegations.length > 0 ? { delegates: { diff --git a/apps/ui/src/networks/offchain/api/index.ts b/apps/ui/src/networks/offchain/api/index.ts index 8e81877d2..db883101e 100644 --- a/apps/ui/src/networks/offchain/api/index.ts +++ b/apps/ui/src/networks/offchain/api/index.ts @@ -40,6 +40,7 @@ import { RANKING_QUERY, SPACE_QUERY, SPACES_QUERY, + STATEMENTS_AND_USERS_QUERY, STATEMENTS_QUERY, STRATEGIES_QUERY, STRATEGY_QUERY, @@ -765,6 +766,28 @@ export function createApi( return statements; }, + loadStatementsAndUsers: async ( + networkId: NetworkID, + spaceId: string, + userIds: string[] + ): Promise<{ statements: Statement[]; users: User[] }> => { + const { data } = await apollo.query({ + query: STATEMENTS_AND_USERS_QUERY, + variables: { + where: { + delegate_in: userIds, + network: networkId, + space: spaceId + }, + userIds + } + }); + + return { + statements: data.statements, + users: data.users + }; + }, loadStrategies: async () => { const { data } = await apollo.query({ query: STRATEGIES_QUERY diff --git a/apps/ui/src/networks/offchain/api/queries.ts b/apps/ui/src/networks/offchain/api/queries.ts index 4b018bb86..51c8494a9 100644 --- a/apps/ui/src/networks/offchain/api/queries.ts +++ b/apps/ui/src/networks/offchain/api/queries.ts @@ -360,3 +360,18 @@ export const STRATEGY_QUERY = gql` } ${STRATEGY_FRAGMENT} `; + +export const STATEMENTS_AND_USERS_QUERY = gql` + query ($where: StatementsWhere, $userIds: [String!]) { + statements(where: $where) { + delegate + space + network + statement + } + users(where: { id_in: $userIds }) { + id + about + } + } +`; diff --git a/apps/ui/src/networks/types.ts b/apps/ui/src/networks/types.ts index 78a67475d..12256f919 100644 --- a/apps/ui/src/networks/types.ts +++ b/apps/ui/src/networks/types.ts @@ -318,6 +318,11 @@ export type NetworkApi = { spaceId: string, userIds: string[] ): Promise; + loadStatementsAndUsers( + networkId: NetworkID, + spaceId: string, + userIds: string[] + ): Promise<{ statements: Statement[]; users: User[] }>; loadStrategies(): Promise; loadStrategy(address: string): Promise; }; diff --git a/apps/ui/src/routes/common.ts b/apps/ui/src/routes/common.ts index ac4d41067..6f7e4e662 100644 --- a/apps/ui/src/routes/common.ts +++ b/apps/ui/src/routes/common.ts @@ -6,6 +6,7 @@ import SpaceDelegates from '@/views/Space/Delegates.vue'; import SpaceDiscussions from '@/views/Space/Discussions.vue'; import SpaceEditor from '@/views/Space/Editor.vue'; import SpaceLeaderboard from '@/views/Space/Leaderboard.vue'; +import SpaceMembers from '@/views/Space/Members.vue'; import SpaceOverview from '@/views/Space/Overview.vue'; import SpaceProposals from '@/views/Space/Proposals.vue'; import SpaceSearch from '@/views/Space/Search.vue'; @@ -71,6 +72,11 @@ export const spaceChildrenRoutes: RouteRecordRaw[] = [ name: 'space-leaderboard', component: SpaceLeaderboard }, + { + path: 'members', + name: 'space-members', + component: SpaceMembers + }, { path: 'profile/:user', name: 'space-user', diff --git a/apps/ui/src/views/Space/Members.vue b/apps/ui/src/views/Space/Members.vue new file mode 100644 index 000000000..fc35f622c --- /dev/null +++ b/apps/ui/src/views/Space/Members.vue @@ -0,0 +1,120 @@ + + + From d8738d39d3ac71c8bdf65462a1252758d0e37594 Mon Sep 17 00:00:00 2001 From: bartosz-io Date: Thu, 7 Nov 2024 17:32:47 +0100 Subject: [PATCH 02/14] Show Members even if only controller present --- apps/ui/src/components/App/Nav.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/ui/src/components/App/Nav.vue b/apps/ui/src/components/App/Nav.vue index efeab399c..b5f762f57 100644 --- a/apps/ui/src/components/App/Nav.vue +++ b/apps/ui/src/components/App/Nav.vue @@ -43,15 +43,17 @@ const space = computed(() => : null ); -const isController = computedAsync(async () => { - if (!networkId.value || !space.value) return false; - - const { account } = web3.value; +const controller = computedAsync(async () => { + if (!networkId.value || !space.value) return null; const network = getNetwork(networkId.value); - const controller = await network.helpers.getSpaceController(space.value); + return await network.helpers.getSpaceController(space.value); +}); + +const isController = computed(() => { + const { account } = web3.value; - return compareAddresses(controller, account); + return compareAddresses(controller.value ?? '', account); }); const canSeeSettings = computed(() => { @@ -71,6 +73,7 @@ const canSeeMembers = computed(() => { const data = space.value?.additionalRawData; return ( + controller.value || (data?.admins?.length ?? 0) > 0 || (data?.moderators?.length ?? 0) > 0 || (data?.members?.length ?? 0) > 0 From 707bc7d8b497016bc3566405275eca1b96e1dfce Mon Sep 17 00:00:00 2001 From: bartosz-io Date: Thu, 7 Nov 2024 18:00:56 +0100 Subject: [PATCH 03/14] Display names, remove label, load members at once --- apps/ui/src/views/Space/Members.vue | 95 +++++++++++++++-------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/apps/ui/src/views/Space/Members.vue b/apps/ui/src/views/Space/Members.vue index fc35f622c..c90e2667e 100644 --- a/apps/ui/src/views/Space/Members.vue +++ b/apps/ui/src/views/Space/Members.vue @@ -1,5 +1,6 @@