diff --git a/src/graphql/helpers.ts b/src/graphql/helpers.ts index fe2dcf7c..41e9dc71 100644 --- a/src/graphql/helpers.ts +++ b/src/graphql/helpers.ts @@ -37,6 +37,17 @@ const ARG_LIMITS = { } }; +const SKIN_SETTINGS = [ + 'bg_color', + 'link_color', + 'text_color', + 'content_color', + 'border_color', + 'heading_color', + 'header_color', + 'primary_color' +]; + export function checkLimits(args: any = {}, type) { const { where = {} } = args; const typeLimits = { ...ARG_LIMITS.default, ...(ARG_LIMITS[type] || {}) }; @@ -61,6 +72,15 @@ export function checkLimits(args: any = {}, type) { return true; } +function formatSkinSettings(result) { + return SKIN_SETTINGS.reduce((acc, color) => { + if (!result[color]) return acc; + + acc[color] = `#${result[color]}`; + return acc; + }, {}); +} + export function formatSpace({ id, settings, @@ -68,7 +88,8 @@ export function formatSpace({ verified, turbo, flagged, - hibernated + hibernated, + skinSettings }) { const spaceMetadata = spacesMetadata[id] || {}; const space = { ...jsonParse(settings, {}), ...spaceMetadata.counts }; @@ -115,6 +136,7 @@ export function formatSpace({ space.validation = space.validation || { name: 'any', params: {} }; space.treasuries = space.treasuries || []; space.labels = space.labels || []; + space.skinSettings = skinSettings; space.verified = verified ?? null; space.flagged = flagged ?? null; @@ -283,15 +305,20 @@ export async function fetchSpaces(args) { } const query = ` - SELECT s.* FROM spaces s + SELECT s.*, skins.*, s.id AS id FROM spaces s + LEFT JOIN skins ON s.id = skins.id WHERE s.deleted = 0 ${queryStr} - GROUP BY s.id ORDER BY s.${orderBy} ${orderDirection} LIMIT ?, ? `; params.push(skip, first); const spaces = await db.queryAsync(query, params); - return spaces.map(space => Object.assign(space, formatSpace(space))); + return spaces.map(space => + Object.assign( + space, + formatSpace({ skinSettings: formatSkinSettings(space), ...space }) + ) + ); } function checkRelatedSpacesNesting(requestedFields): void { @@ -410,7 +437,8 @@ export function formatProposal(proposal) { verified: proposal.spaceVerified, turbo: proposal.spaceTurbo, flagged: proposal.spaceFlagged, - hibernated: proposal.spaceHibernated + hibernated: proposal.spaceHibernated, + skinSettings: formatSkinSettings(proposal) }); const networkPrefix = network === 'testnet' ? 's-tn' : 's'; proposal.link = `https://${domain}/#/${networkPrefix}:${proposal.space.id}/proposal/${proposal.id}`; @@ -435,7 +463,8 @@ export function formatVote(vote) { verified: vote.spaceVerified, turbo: vote.spaceTurbo, flagged: vote.spaceFlagged, - hibernated: vote.spaceHibernated + hibernated: vote.spaceHibernated, + skinSettings: formatSkinSettings(vote) }); return vote; } @@ -448,7 +477,8 @@ export function formatFollow(follow) { verified: follow.spaceVerified, turbo: follow.spaceTurbo, flagged: follow.spaceFlagged, - hibernated: follow.spaceHibernated + hibernated: follow.spaceHibernated, + skinSettings: formatSkinSettings(follow) }); return follow; } @@ -461,7 +491,8 @@ export function formatSubscription(subscription) { verified: subscription.spaceVerified, turbo: subscription.spaceTurbo, flagged: subscription.spaceFlagged, - hibernated: subscription.spaceHibernated + hibernated: subscription.spaceHibernated, + skinSettings: formatSkinSettings(subscription) }); return subscription; } diff --git a/src/graphql/operations/follows.ts b/src/graphql/operations/follows.ts index d2785d37..77436ac3 100644 --- a/src/graphql/operations/follows.ts +++ b/src/graphql/operations/follows.ts @@ -28,7 +28,10 @@ export default async function (parent, args) { if (!['ASC', 'DESC'].includes(orderDirection)) orderDirection = 'DESC'; const query = ` - SELECT f.*, + SELECT + f.*, + skins.*, + f.id AS id, spaces.settings, spaces.domain as spaceDomain, spaces.flagged as spaceFlagged, @@ -37,6 +40,7 @@ export default async function (parent, args) { spaces.hibernated as spaceHibernated FROM follows f LEFT JOIN spaces ON spaces.id = f.space + LEFT JOIN skins ON spaces.id = skins.id WHERE 1=1 ${queryStr} ORDER BY ${orderBy} ${orderDirection} LIMIT ?, ? `; diff --git a/src/graphql/operations/proposal.ts b/src/graphql/operations/proposal.ts index 5eca83a8..6da7067a 100644 --- a/src/graphql/operations/proposal.ts +++ b/src/graphql/operations/proposal.ts @@ -5,7 +5,10 @@ import { formatProposal } from '../helpers'; export default async function (parent, { id }) { const query = ` - SELECT p.*, + SELECT + p.*, + skins.*, + p.id AS id, spaces.settings, spaces.domain as spaceDomain, spaces.flagged as spaceFlagged, @@ -14,6 +17,7 @@ export default async function (parent, { id }) { spaces.hibernated as spaceHibernated FROM proposals p INNER JOIN spaces ON spaces.id = p.space + LEFT JOIN skins ON spaces.id = skins.id WHERE p.id = ? AND spaces.settings IS NOT NULL LIMIT 1 `; diff --git a/src/graphql/operations/proposals.ts b/src/graphql/operations/proposals.ts index 3a6e383b..b46f700f 100644 --- a/src/graphql/operations/proposals.ts +++ b/src/graphql/operations/proposals.ts @@ -85,7 +85,10 @@ export default async function (parent, args) { if (!['ASC', 'DESC'].includes(orderDirection)) orderDirection = 'DESC'; const query = ` - SELECT p.*, + SELECT + p.*, + skins.*, + p.id AS id, spaces.settings, spaces.domain as spaceDomain, spaces.flagged as spaceFlagged, @@ -94,6 +97,7 @@ export default async function (parent, args) { spaces.hibernated as spaceHibernated FROM proposals p INNER JOIN spaces ON spaces.id = p.space + LEFT JOIN skins ON spaces.id = skins.id WHERE spaces.settings IS NOT NULL ${queryStr} ${searchSql} ORDER BY ${orderBy} ${orderDirection}, p.id ASC LIMIT ?, ? `; diff --git a/src/graphql/operations/subscriptions.ts b/src/graphql/operations/subscriptions.ts index 1f1edbb3..ceb45547 100644 --- a/src/graphql/operations/subscriptions.ts +++ b/src/graphql/operations/subscriptions.ts @@ -29,7 +29,10 @@ export default async function (parent, args) { let subscriptions: any[] = []; const query = ` - SELECT s.*, + SELECT + s.*, + skins.*, + s.id AS id, spaces.settings, spaces.domain as spaceDomain, spaces.flagged as spaceFlagged, @@ -38,6 +41,7 @@ export default async function (parent, args) { spaces.hibernated as spaceHibernated FROM subscriptions s INNER JOIN spaces ON spaces.id = s.space + LEFT JOIN skins ON spaces.id = skins.id WHERE spaces.settings IS NOT NULL ${queryStr} ORDER BY ${orderBy} ${orderDirection} LIMIT ?, ? `; diff --git a/src/graphql/operations/votes.ts b/src/graphql/operations/votes.ts index 4be9044a..dd36f5ca 100644 --- a/src/graphql/operations/votes.ts +++ b/src/graphql/operations/votes.ts @@ -87,7 +87,10 @@ async function query(parent, args, context?, info?) { if (requestedFields.proposal && votes.length > 0) { const proposalIds = votes.map(vote => vote.proposal); const query = ` - SELECT p.*, + SELECT + p.*, + skins.*, + p.id AS id, spaces.settings, spaces.domain as spaceDomain, spaces.flagged as spaceFlagged, @@ -96,6 +99,7 @@ async function query(parent, args, context?, info?) { spaces.hibernated as spaceHibernated FROM proposals p INNER JOIN spaces ON spaces.id = p.space + LEFT JOIN skins ON spaces.id = skins.id WHERE spaces.settings IS NOT NULL AND p.id IN (?) `; try { diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index a8aa2cd2..98de16b2 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -405,6 +405,7 @@ type Space { network: String symbol: String skin: String + skinSettings: SkinSettings domain: String strategies: [Strategy] admins: [String] @@ -651,3 +652,14 @@ type Option { name: String value: String } + +type SkinSettings { + bg_color: String + link_color: String + text_color: String + content_color: String + border_color: String + heading_color: String + header_color: String + primary_color: String +} diff --git a/src/helpers/schema.sql b/src/helpers/schema.sql index b4092cb4..0e372c67 100644 --- a/src/helpers/schema.sql +++ b/src/helpers/schema.sql @@ -192,3 +192,15 @@ CREATE TABLE options ( value VARCHAR(100) NOT NULL, PRIMARY KEY (name) ); + +CREATE TABLE `skins` ( + id VARCHAR(100) NOT NULL, + bg_color VARCHAR(6) DEFAULT NULL, + link_color VARCHAR(6) DEFAULT NULL, + text_color VARCHAR(6) DEFAULT NULL, + border_color VARCHAR(6) DEFAULT NULL, + heading_color VARCHAR(6) DEFAULT NULL, + primary_color VARCHAR(6) DEFAULT NULL, + header_color VARCHAR(6) DEFAULT NULL, + PRIMARY KEY (id) +)