Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahscott committed Oct 6, 2020
1 parent c0591be commit 92ac06f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import { createEventDispatcher } from "svelte";
import { isExperimental } from "../../../../native/ipc.js";
import * as source from "../../../src/source";
import Overlay from "../Overlay.svelte";
import { Icon } from "../../Primitive";
export let revisions: source.PeerRevisions;
export let currentRevision: source.Branch | source.Tag | undefined;
if (!currentRevision) currentRevision = revisions.branches[0];
export let currentRevision: source.Branch | source.Tag;
let expanded: boolean = false;
const toggle = () => (expanded = !expanded);
Expand Down
15 changes: 9 additions & 6 deletions ui/Screen/Project.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import * as notification from "../src/notification";
import * as path from "../src/path";
import { checkout, fetch, project as store } from "../src/project";
import type { Project } from "../src/project";
import type { Project } from "../src/project"; // Annoying but necessary type import
import * as remote from "../src/remote";
import * as screen from "../src/screen";
import {
commits as commitsStore,
currentPeerId,
currentRevision,
currentRevision as currentRevisionStore,
resetCurrentRevision,
resetCurrentPeerId,
revisions as revisionsStore,
Expand Down Expand Up @@ -122,7 +122,8 @@
// TODO(sos): should be removed if/when this is fixed.
let revisions: source.PeerRevisions[] | undefined,
project: Project | undefined,
commits: source.CommitsStore | undefined;
commits: source.CommitsStore | undefined,
currentRevision: source.Branch | source.Tag | undefined;
$: {
const rs = $revisionsStore;
Expand Down Expand Up @@ -155,6 +156,8 @@
// Revisions that belong to the current selected peer, formatted for display in revision selector
$: currentPeerRevisions =
revisions && revisions.find(rev => rev.identity.peerId === $currentPeerId);
$: currentRevision = $currentRevisionStore;
</script>

<style>
Expand All @@ -177,9 +180,9 @@
<div slot="left">
<div style="display: flex">
<div class="revision-selector-wrapper">
{#if currentPeerRevisions}
{#if currentPeerRevisions && currentRevision}
<RevisionSelector
currentRevision={$currentRevision}
{currentRevision}
revisions={currentPeerRevisions}
on:select={updateRevision} />
{/if}
Expand All @@ -206,7 +209,7 @@
{#if availablePeers}
<PeerSelector
{availablePeers}
currentPeerId={$currentPeerId || ''}
currentPeerId={$currentPeerId}
on:select={updatePeer} />
{/if}
<TrackToggle />
Expand Down
27 changes: 17 additions & 10 deletions ui/Screen/Project/PeerSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
import * as badge from "../../src/badge";
import * as identity from "../../src/identity";
import * as notification from "../../src/notification";
import * as path from "../../src/path";
import * as style from "../../src/style";
import { Avatar, Icon } from "../../DesignSystem/Primitive";
import { Badge, Overlay, Tooltip } from "../../DesignSystem/Component";
let expanded = false;
export let currentPeerId: string;
export let currentPeerId: string | undefined;
export let availablePeers: identity.Identity[];
let expanded = false,
currentPeer: identity.Identity;
if (currentPeerId) {
currentPeer =
availablePeers.find(peer => peer.id === currentPeerId) ||
availablePeers[0];
} else {
notification.error("Unable to load available peers");
}
const session = getContext("session");
const { metadata } = getContext("project");
Expand All @@ -39,9 +49,6 @@
hideDropdown();
dispatch("select", { peerId });
};
$: currentSelectedPeer =
availablePeers.find(peer => peer.id === currentPeerId) || availablePeers[0];
</script>

<style>
Expand Down Expand Up @@ -116,15 +123,15 @@
hidden={expanded}>
<div class="selector-avatar typo-overflow-ellipsis">
<Avatar
avatarFallback={currentSelectedPeer.avatarFallback}
avatarFallback={currentPeer.avatarFallback}
size="small"
style="display: flex; justify-content: flex-start; margin-right: 0.5rem;"
variant="circle" />
<p class="typo-text-bold typo-overflow-ellipsis">
{currentSelectedPeer.metadata.handle || currentSelectedPeer.shareableEntityIdentifier}
{currentPeer.metadata.handle || currentPeer.shareableEntityIdentifier}
</p>
<p>
{#if metadata.maintainers.includes(currentSelectedPeer.urn)}
{#if metadata.maintainers.includes(currentPeer.urn)}
<Badge
style="margin-left: 0.5rem"
variant={badge.BadgeType.Maintainer} />
Expand All @@ -141,7 +148,7 @@
{#each availablePeers as peer}
<div
class="peer"
class:selected={peer.peerId == currentSelectedPeer.peerId}
class:selected={peer.peerId == currentPeer.peerId}
data-peer-handle={peer.metadata.handle}>
<div style="display: flex;" on:click={() => selectPeer(peer.peerId)}>
<Avatar
Expand Down
2 changes: 1 addition & 1 deletion ui/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const creation = creationStore.readable;
const projectStore = remote.createStore<Project>();
export const project = projectStore.readable;

// Once we have the project, we can download its revisions.
// Once we have the project, we can fetch its revisions.
project.subscribe(store => {
if (store.status === remote.Status.Success) {
source.fetchRevisions({ projectId: store.data.id });
Expand Down
35 changes: 19 additions & 16 deletions ui/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ interface Tree extends SourceObject {

// All revisions of project from a particular peer
export interface PeerRevisions {
// The identity of the peer
identity: identity.Identity;
// All known branches
branches: Branch[];
// All known tags
tags: Tag[];
// Default branch, if we have it
defaultBranch?: string;
}

Expand All @@ -113,38 +117,43 @@ export enum RevisionType {
Sha = "sha",
}

// Client representation of a git branch
export interface Branch {
type: RevisionType.Branch;
projectId: string;
name: string;
// The id of the project this branch belongs to
projectId: string;
// The id of the peer this branch belongs to
peerId: string;
}

// Client representation of a git tag
export interface Tag {
type: RevisionType.Tag;
projectId: string;
name: string;
// The id of the project this tag belongs to
peerId: string;
// The id of the project this tag belongs to
projectId: string;
}

export interface Sha {
type: RevisionType.Sha;
sha: string;
}

// Proxy representation of all revisions for a project from a particular peer
export type RevisionQuery = Branch | Tag | Sha;

// Proxy representation of all known revisions of a project from a particular peer
type PeerRevisionsResponse = {
// The identity of the peer who owns these revisions
identity: identity.Identity;

// Names of associated branches and tags
branches: string[];
tags: string[];
}[];

export type RevisionQuery = Branch | Tag | Sha;

// STATE
// Remote stores
const commitStore = remote.createStore<Commit>();
export const commit = commitStore.readable;

Expand All @@ -154,10 +163,10 @@ export const commits = commitsStore.readable;
const objectStore = remote.createStore<SourceObject>();
export const object = objectStore.readable;

// Updated when the project store changes (i.e. when the user navigates to a new project)
const revisionsStore = remote.createStore<PeerRevisions[]>();
export const revisions = revisionsStore.readable;
revisions.subscribe(store => {
// If revisions change, we need to update everything that depends on them.
if (store.status === remote.Status.Success) {
// The first `PeerRevisions` in the response belongs to the default peer.
const defaultRevisions = store.data[0];
Expand All @@ -175,23 +184,17 @@ revisions.subscribe(store => {
}
});

// Local stores
export const objectType = writable(ObjectType.Tree);
export const resetObjectType = () => objectType.set(ObjectType.Tree);
export const objectPath = writable(null);
export const resetObjectPath = () => objectPath.set(null);

export const defaultRevision = (
peerRevisions: PeerRevisions,
projectDefaultBranch: string
) =>
peerRevisions.branches.find(branch => branch.name === projectDefaultBranch) ||
peerRevisions.branches[0];

export const currentRevision = writable<Branch | Tag | undefined>(undefined);
currentRevision.subscribe(revision => {
if (revision) {
// Fetch commits when the current revision is changed
fetchCommits({ projectId: revision?.projectId, revision });
fetchCommits({ projectId: revision.projectId, revision });
}
});

Expand Down

0 comments on commit 92ac06f

Please sign in to comment.