From 7ba5ce0f60fc9782842695688d6378009f4f41bb Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 20 Jan 2022 14:08:42 +0100 Subject: [PATCH] Refactor source params into separate object We had a lot variables that we had to pass down from the project view, and only very few where important to the reactivity of the components. By using the resolved Promise from `getProject` as transport we can use now the `source` variable and get the required params by destructuring it. In short we can pack now the following params: ``` urn, org, user, seed, peer, project, branches, peers, config, anchors ``` Signed-off-by: Sebastian Martinez --- src/base/projects/Browser.svelte | 12 +++------ src/base/projects/Commit/History.svelte | 10 +++---- src/base/projects/Header.svelte | 17 ++++-------- src/base/projects/PeerSelector.svelte | 2 +- src/base/projects/ProjectContentRoutes.svelte | 26 ++++++------------- src/base/projects/View.svelte | 21 +++++---------- src/project.ts | 16 ++++++++++++ 7 files changed, 44 insertions(+), 60 deletions(-) diff --git a/src/base/projects/Browser.svelte b/src/base/projects/Browser.svelte index 94a5dea7d..62f06361e 100644 --- a/src/base/projects/Browser.svelte +++ b/src/base/projects/Browser.svelte @@ -1,6 +1,5 @@ - - - - - diff --git a/src/base/projects/View.svelte b/src/base/projects/View.svelte index 1b35d1c12..23fcb87a3 100644 --- a/src/base/projects/View.svelte +++ b/src/base/projects/View.svelte @@ -40,8 +40,8 @@ } }).then(async (result) => { const profile = result?.profile; - const seed = profile?.seed ?? result?.seed; - const cfg = seed ? config.withSeed(seed) : config; + const seedInstance = profile?.seed ?? result?.seed; + const cfg = seedInstance ? config.withSeed(seedInstance) : config; const info = await proj.getInfo(urn, cfg); projectInfo = info; const anchors = await getAllAnchors(config, urn, profile?.anchorsAccount ?? org); @@ -57,7 +57,7 @@ } peers = await proj.getPeers(urn, cfg); } - return { project: info, branches, peers, anchors, config: cfg, profile }; + return { urn, org, user, seed, peer, project: info, branches, peers, config: cfg, profile, anchors }; }); const parentUrl = (profile: Profile) => { @@ -179,19 +179,12 @@
{result.project.meta.description}
{#await proj.getTree(urn, getOid(result.project.head, revision, result.branches), "/", config) then tree} -
- diff --git a/src/project.ts b/src/project.ts index a4071b804..9eaa6dd5b 100644 --- a/src/project.ts +++ b/src/project.ts @@ -2,6 +2,7 @@ import type { Config } from '@app/config'; import * as api from '@app/api'; import type { CommitsHistory } from '@app/base/projects/Commit/lib'; import { isOid } from '@app/utils'; +import type { Profile } from '@app/profile'; export type Urn = string; export type Peer = string; @@ -18,6 +19,21 @@ export interface Project { }; } +// Params to render correctly source code related views +export interface Source { + urn: string; + org: string; + user: string; + peer: string; + config: Config; + project: Info; + peers: Peer[]; + anchors: string[]; + seed: string; + branches: [string, string][]; + profile?: Profile; +} + export interface PendingProject extends Project { safeTxHash: string; // Safe transaction hash. confirmations: string[]; // Owner addresses who have confirmed.