diff --git a/public/index.css b/public/index.css index 1146a8813..58b0dfdd6 100644 --- a/public/index.css +++ b/public/index.css @@ -359,6 +359,9 @@ label.input { .desktop { display: block !important; } +.desktop-inline { + display: inline !important; +} @media (max-width: 720px) { .mobile { @@ -367,6 +370,9 @@ label.input { .desktop { display: none !important; } + .desktop-inline { + display: none !important; + } } span.small, .text-xsmall { diff --git a/src/base/projects/Browser.svelte b/src/base/projects/Browser.svelte index 434d1e5fc..9c2dee169 100644 --- a/src/base/projects/Browser.svelte +++ b/src/base/projects/Browser.svelte @@ -79,32 +79,6 @@ mobileFileTree = !mobileFileTree; }; - const GetAllAnchors = ` - query GetAllAnchors($project: Bytes!, $org: ID!) { - anchors(orderBy: timestamp, orderDirection: desc, where: { objectId: $project, org: $org }) { - multihash - timestamp - } - } - `; - - interface AnchorObject { - timestamp: number; - commit: string; - multihash: string; - } - - async function getAllAnchors(anchors: string | null, urn: string): Promise { - if (! anchors) { - return null; - } - const unpadded = utils.decodeRadicleId(urn); - const id = ethers.utils.hexZeroPad(unpadded, 32); - const allAnchors = await utils.querySubgraph(config.orgs.subgraph, GetAllAnchors, { project: id, org: anchors }); - return allAnchors.anchors - .map((anchor: AnchorObject) => utils.formatProjectHash(ethers.utils.arrayify(anchor.multihash))); - } - // This is reactive to respond to path changes that don't originate from this // component, eg. when using the browser's "back" button. $: getBlob = loadBlob(path); diff --git a/src/base/projects/Commit/CommitTeaser.svelte b/src/base/projects/Commit/CommitTeaser.svelte new file mode 100644 index 000000000..f790b4d0f --- /dev/null +++ b/src/base/projects/Commit/CommitTeaser.svelte @@ -0,0 +1,57 @@ + + + + +
+
+ {formatCommit(commit.sha1)} + {commit.summary} +
+
+ {commit.committer.name} + {formatCommitTime(commit.committerTime)} +
+
diff --git a/src/base/projects/Commit/History.svelte b/src/base/projects/Commit/History.svelte new file mode 100644 index 000000000..a058cac4f --- /dev/null +++ b/src/base/projects/Commit/History.svelte @@ -0,0 +1,70 @@ + + + + +{#await fetchCommits()} + +{:then history} +
+ {#each history.headers as group (group.time)} +
+
+

{group.time}

+
+
+ {#each group.commits as commit (commit.sha1)} +
+ +
+ {/each} +
+
+ {/each} +
+{/await} diff --git a/src/base/projects/Commit/lib.ts b/src/base/projects/Commit/lib.ts new file mode 100644 index 000000000..8e9b508c8 --- /dev/null +++ b/src/base/projects/Commit/lib.ts @@ -0,0 +1,83 @@ +import type { CommitHeader, Stats } from "@app/project"; + +export interface CommitsHistory { + headers: CommitHeader[]; + stats: Stats; +} +export interface GroupedCommitsHistory { + headers: CommitGroup[]; + stats: Stats; +} + +export interface CommitStats { + branches: number; + commits: number; + contributors: number; +} + +export interface GroupedCommitsHistory { + headers: CommitGroup[]; + stats: Stats; +} + +// A set of commits grouped by time. +export interface CommitGroup { + time: string; + commits: CommitHeader[]; +} + + +export function formatGroupTime(timestamp: number): string { + return new Date(timestamp).toLocaleDateString("en-US", { + day: 'numeric', + weekday: 'long', + month: 'long', + year: 'numeric' + }); +} + +export const groupCommitHistory = ( + history: CommitsHistory +): GroupedCommitsHistory => { + return { ...history, headers: groupCommits(history.headers) }; +}; + +export function groupCommits(commits: CommitHeader[]): CommitGroup[] { + const groupedCommits: CommitGroup[] = []; + let groupDate: Date | undefined = undefined; + + commits = commits.sort((a, b) => { + if (a.committerTime > b.committerTime) { + return -1; + } else if (a.committerTime < b.committerTime) { + return 1; + } + + return 0; + }); + + for (const commit of commits) { + const time = commit.committerTime * 1000; + const date = new Date(time); + const isNewDay = + !groupedCommits.length || + !groupDate || + date.getDate() < groupDate.getDate() || + date.getMonth() < groupDate.getMonth() || + date.getFullYear() < groupDate.getFullYear(); + + if (isNewDay) { + groupedCommits.push({ + time: formatGroupTime(time), + commits: [], + }); + groupDate = date; + } + groupedCommits[groupedCommits.length - 1].commits.push(commit); + } + return groupedCommits; +} + +export const formatCommitTime = (t: number): string => { + return new Date(t * 1000).toUTCString(); +}; diff --git a/src/base/projects/Header.svelte b/src/base/projects/Header.svelte index 3169877b8..8175cc018 100644 --- a/src/base/projects/Header.svelte +++ b/src/base/projects/Header.svelte @@ -2,10 +2,10 @@ import type { Config } from '@app/config'; import * as utils from '@app/utils'; import Loading from '@app/Loading.svelte'; - import { Org } from '@app/base/orgs/Org'; + import { ethers } from "ethers"; import type { Info, Tree } from '@app/project'; + import { ProjectContent } from "@app/project"; import type { Profile } from '@app/profile'; - import { createEventDispatcher } from "svelte"; export let config: Config; export let anchors: string | null = null; @@ -14,17 +14,45 @@ export let project: Info; export let profile: Profile | null = null; export let tree: Tree; + export let content: ProjectContent; // Whether the clone dropdown is visible. let cloneDropdown = false; // Whether the seed dropdown is visible. let seedDropdown = false; - const dispatch = createEventDispatcher(); - const onClick = ({ detail: newCommit }: { detail: string }): void => { - dispatch("commitChange", newCommit); + + // Switches between the browser and commit view + const switchContent = () => { + content = content == ProjectContent.Browser ? ProjectContent.Commits : ProjectContent.Browser; }; - $: getAnchor = anchors ? Org.getAnchor(anchors, urn, config) : null; + const GetAllAnchors = ` + query GetAllAnchors($project: Bytes!, $org: ID!) { + anchors(orderBy: timestamp, orderDirection: desc, where: { objectId: $project, org: $org }) { + multihash + timestamp + } + } + `; + + interface AnchorObject { + timestamp: number; + multihash: string; + } + + async function getAllAnchors(anchors: string | null, urn: string): Promise { + if (! anchors) { + return null; + } + const unpadded = utils.decodeRadicleId(urn); + const id = ethers.utils.hexZeroPad(unpadded, 32); + const allAnchors = await utils.querySubgraph(config.orgs.subgraph, GetAllAnchors, { project: id, org: anchors }); + console.log(allAnchors); + return allAnchors.anchors + .map((anchor: AnchorObject) => utils.formatProjectHash(ethers.utils.arrayify(anchor.multihash))); + } + + $: getAnchor = anchors ? getAllAnchors(anchors, urn) : null;