From f1ed37d361e5d7f4027d1c81a0b6b2c0b4bc47d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Mon, 6 Jan 2025 17:59:45 +0100 Subject: [PATCH] feat: display Space guidelines and template (#1084) * refactor: move guidelines and template to Space * feat: use guidelines and template --- apps/ui/src/composables/useEditor.ts | 35 +++++++++++++++---- apps/ui/src/composables/useSpaceSettings.ts | 10 +++--- .../src/networks/common/graphqlApi/index.ts | 4 ++- apps/ui/src/networks/offchain/api/index.ts | 4 +-- apps/ui/src/types.ts | 4 +-- apps/ui/src/views/Space/Editor.vue | 12 +++++++ 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/apps/ui/src/composables/useEditor.ts b/apps/ui/src/composables/useEditor.ts index eb3158ef1..d28c5ee1c 100644 --- a/apps/ui/src/composables/useEditor.ts +++ b/apps/ui/src/composables/useEditor.ts @@ -27,7 +27,8 @@ const processedProposals = Object.fromEntries( ); const proposals = reactive(processedProposals as Drafts); -const spaceVoteType = reactive(new Map()); +const spaceVoteType = new Map(); +const spaceTemplate = new Map(); function generateId() { return (Math.random() + 1).toString(36).substring(7); @@ -38,6 +39,8 @@ function getSpaceId(draftId: string) { } export function useEditor() { + const spacesStore = useSpacesStore(); + const drafts = computed(() => { return Object.entries(removeEmpty(proposals)) .map(([k, value]) => { @@ -56,11 +59,13 @@ export function useEditor() { function removeEmpty(proposals: Drafts): Drafts { return Object.entries(proposals).reduce((acc, [id, proposal]) => { - const { executions, type, choices, labels, ...rest } = omit(proposal, [ - 'updatedAt' - ]); + const { executions, type, body, choices, labels, ...rest } = omit( + proposal, + ['updatedAt'] + ); const hasFormValues = Object.values(rest).some(val => !!val); const hasChangedVotingType = type !== spaceVoteType.get(getSpaceId(id)); + const hasChangedBody = body !== spaceTemplate.get(getSpaceId(id)); const hasFormChoices = type !== 'basic' && (choices || []).some(val => !!val); @@ -69,6 +74,7 @@ export function useEditor() { labels.length === 0 && !hasFormValues && !hasChangedVotingType && + !hasChangedBody && !hasFormChoices ) { return acc; @@ -85,8 +91,23 @@ export function useEditor() { }, {}); } + async function getInitialProposalBody(spaceId: string) { + if (spaceTemplate.has(spaceId)) { + return spaceTemplate.get(spaceId) as string; + } + + if (!spacesStore.spacesMap.has(spaceId)) { + await spacesStore.fetchSpaces([spaceId]); + } + + const template = spacesStore.spacesMap.get(spaceId)?.template ?? ''; + + spaceTemplate.set(spaceId, template); + + return template; + } + async function setSpacesVoteType(spaceIds: string[]) { - const spacesStore = useSpacesStore(); const newIds = spaceIds.filter(id => !spaceVoteType.has(id)); if (!newIds.length) return; @@ -122,9 +143,11 @@ export function useEditor() { const id = draftKey ?? generateId(); const key = `${spaceId}:${id}`; + const body = await getInitialProposalBody(spaceId); + proposals[key] = { title: '', - body: '', + body, discussion: '', type, choices, diff --git a/apps/ui/src/composables/useSpaceSettings.ts b/apps/ui/src/composables/useSpaceSettings.ts index 513b6118a..a0f42d2a0 100644 --- a/apps/ui/src/composables/useSpaceSettings.ts +++ b/apps/ui/src/composables/useSpaceSettings.ts @@ -702,8 +702,8 @@ export function useSpaceSettings(space: Ref) { if (offchainNetworks.includes(space.value.network)) { proposalValidation.value = getInitialProposalValidation(space.value); - guidelines.value = space.value.additionalRawData?.guidelines ?? ''; - template.value = space.value.additionalRawData?.template ?? ''; + guidelines.value = space.value.guidelines ?? ''; + template.value = space.value.template ?? ''; const initialVotingProperties = getInitialVotingProperties(space.value); quorumType.value = initialVotingProperties.quorumType; @@ -816,14 +816,12 @@ export function useSpaceSettings(space: Ref) { return; } - if ( - guidelinesValue !== (space.value.additionalRawData?.guidelines ?? '') - ) { + if (guidelinesValue !== (space.value.guidelines ?? '')) { isModified.value = true; return; } - if (templateValue !== (space.value.additionalRawData?.template ?? '')) { + if (templateValue !== (space.value.template ?? '')) { isModified.value = true; return; } diff --git a/apps/ui/src/networks/common/graphqlApi/index.ts b/apps/ui/src/networks/common/graphqlApi/index.ts index 21513866a..e82cbe81c 100644 --- a/apps/ui/src/networks/common/graphqlApi/index.ts +++ b/apps/ui/src/networks/common/graphqlApi/index.ts @@ -252,7 +252,9 @@ function formatSpace( space.strategies_indices ), children: [], - parent: null + parent: null, + template: null, + guidelines: null }; } diff --git a/apps/ui/src/networks/offchain/api/index.ts b/apps/ui/src/networks/offchain/api/index.ts index 7687bb91a..3526002c2 100644 --- a/apps/ui/src/networks/offchain/api/index.ts +++ b/apps/ui/src/networks/offchain/api/index.ts @@ -142,8 +142,6 @@ function formatSpace( private: space.private, domain: space.domain, skin: space.skin, - guidelines: space.guidelines, - template: space.template, strategies: space.strategies, categories: space.categories, admins: space.admins, @@ -212,6 +210,8 @@ function formatSpace( children: space.children.map(formatRelatedSpace), parent: space.parent ? formatRelatedSpace(space.parent) : null, terms: space.terms, + guidelines: space.guidelines, + template: space.template, additionalRawData }; } diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts index c2ce64d2e..e9a52ec78 100644 --- a/apps/ui/src/types.ts +++ b/apps/ui/src/types.ts @@ -139,8 +139,6 @@ export type OffchainAdditionalRawData = { | 'private' | 'domain' | 'skin' - | 'guidelines' - | 'template' | 'strategies' | 'categories' | 'admins' @@ -210,6 +208,8 @@ export type Space = { created: number; children: RelatedSpace[]; parent: RelatedSpace | null; + template: string | null; + guidelines: string | null; // only use this for settings, if it's actually used for other things // move it to main space type additionalRawData?: OffchainAdditionalRawData; diff --git a/apps/ui/src/views/Space/Editor.vue b/apps/ui/src/views/Space/Editor.vue index c46043236..eae1c58fa 100644 --- a/apps/ui/src/views/Space/Editor.vue +++ b/apps/ui/src/views/Space/Editor.vue @@ -1,4 +1,5 @@