Skip to content

Commit

Permalink
chore: update stats UI (#126)
Browse files Browse the repository at this point in the history
* feat: add 1h range

* chore: update label generation

* chore: update crane-link

* chore: update breadcrumbs
  • Loading branch information
tom-bywild authored Jan 5, 2023
1 parent 66c9e94 commit acd0f00
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 43 deletions.
2 changes: 1 addition & 1 deletion web/scripts/generate-trends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path from 'node:path';
// @ts-ignore Issue w/ node types.
const cwd = process.cwd();
const base = path.join(cwd, 'static', 'data', 'stats');
const ranges = ['6h', '12h', '24h', '48h', '72h', '1w', '2w', '1m'];
const ranges = ['1h', '6h', '12h', '24h', '48h', '72h', '1w', '2w', '1m'];

/**
* Simple parser for CLI arguments.
Expand Down
6 changes: 5 additions & 1 deletion web/src/lib/blocks/views/Hero.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
export let textVariant: 'dense' | 'fit' | undefined = undefined;
export let variant: 'prominent' | undefined = undefined;
let cn: string | undefined = undefined;
export { cn as class };
const isSingleLongTitle = checkForSingleLongTitle(title);
const defaultVariant = `
Expand All @@ -37,7 +40,8 @@
'h-full': height === 'full',
'flex-1': height === 'flex',
fixed: isFixed
}
},
cn
)}
>
<h1
Expand Down
5 changes: 4 additions & 1 deletion web/src/lib/page/views/BasePageInit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
export let title: string;
export let path: string;
export let withBreadcrumb = true;
</script>

<BaseMeta {title} {path} />
<BreadcrumbMeta items={[{ name: title, href: path }]} />
{#if withBreadcrumb}
<BreadcrumbMeta items={[{ name: title, href: path }]} />
{/if}
<ColorScheme scheme="dark" />

<SearchInit />
Expand Down
37 changes: 36 additions & 1 deletion web/src/lib/statistics/models/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
import type { GithubTrendItem } from '../types/github';

export const githubTrendRanges = ['6h', '12h', '24h', '48h', '72h', '1w', '2w', '1m'];
export const githubTrendRanges = [
'1h',
'6h',
'12h',
'24h',
'48h',
'72h',
'1w',
'2w',
'1m'
] as const;

export function mapRangeToLabel(source: string) {
switch (source) {
case '1h':
return '1 hour';
case '6h':
return '6 hours';
case '12h':
return '12 hours';
case '24h':
return '24 hours';
case '48h':
return '48 hours';
case '72h':
return '72 hours';
case '1w':
return '1 week';
case '2w':
return '2 weeks';
case '1m':
return '1 month';
default:
return source;
}
}

export async function fetchReposByStars(params: {
range: typeof githubTrendRanges[number];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const load: PageServerLoad = async ({ params, setHeaders }) => {
});

// @ts-expect-error Range not picked up by type inference.
const range: string = params.range;
const range: typeof githubTrendRanges[number] = params.range;

if (!githubTrendRanges.includes(range)) {
throw error(401, `Invalid range: ${range}`);
Expand Down
68 changes: 30 additions & 38 deletions web/src/routes/statistics/github/stars/[range]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,33 @@
import CommonControls from '$lib/controls/views/CommonControls.svelte';
import Link from '$lib/display/views/Link.svelte';
import BasePageInit from '$lib/page/views/BasePageInit.svelte';
import BreadcrumbMeta from '$lib/seo/views/BreadcrumbMeta.svelte';
import { mapRangeToLabel } from '$lib/statistics/models/github';
import clsx from 'clsx';
import type { PageServerData } from './$types';
export let data: PageServerData;
const { items, ranges } = data;
let selectedRange = data.selectedRange;
const mapRangeToLabel = (source: string) => {
switch (source) {
case '6h':
return '6 hours';
case '12h':
return '12 hours';
case '24h':
return '24 hours';
case '48h':
return '48 hours';
case '72h':
return '72 hours';
case '1w':
return '1 week';
case '2w':
return '2 weeks';
case '1m':
return '1 month';
default:
return source;
}
};
</script>

<BasePageInit
withBreadcrumb={false}
title="Trending R packages by Github stars for the last {mapRangeToLabel(selectedRange)}"
path="/statistics/github/stars/{selectedRange}"
/>
<BreadcrumbMeta
items={[
{ name: 'Statistics', href: '/statistics' },
{ name: 'Github statistics', href: '/github/statistics' },
{ name: 'Trending R packages by Github stars', href: '/statistics/github/stars' },
{
name: `Trending R packages by Github stars for the last ${mapRangeToLabel(selectedRange)}`,
href: `/statistics/github/stars/${selectedRange}`
}
]}
/>
<CommonControls variant="translucent" />

<main>
Expand All @@ -56,9 +47,10 @@
subtitleSize="xl"
height="50"
variant="prominent"
theme="gradient-dark-zinc"
/>

<SheetContent offset="50" class=" text-neutral-50 space-y-20 lg:space-y-40 pb-60 bg-zinc-900">
<SheetContent offset="50" class=" text-neutral-50 space-y-20 lg:space-y-52 pb-60 bg-zinc-900">
<Section withSpacingY="md" withPaddingX maxWidth="xl" class="mx-auto">
<div class="text-lg flex items-center justify-center gap-x-2">
Trends for last
Expand Down Expand Up @@ -90,13 +82,13 @@

<SubGrid size="1" class="gap-8">
{#each items as { original, trend, crane }}
<SubGridItem
withBorder
withSpaceY="md"
withValueSpaceY="xs"
key={original.name}
emphasis="key"
>
<SubGridItem withBorder withSpaceY="md" withValueSpaceY="xs" key="" emphasis="key">
<Link
slot="key"
title={original.name}
href={crane.packageSlug ? `/package/${crane.packageSlug}` : original.html_url}
>{original.name}
</Link>
<p class="flex items-center space-x-2">
<span class="text-sm"
>by
Expand Down Expand Up @@ -143,14 +135,14 @@
</span>
</p>

<div class="flex items-center space-x-2 text-neutral-200">
<div class="flex items-center space-x-3 pt-2 text-neutral-200">
{#if crane.packageSlug}
<SubGridIcon
meta={{
url: `/package/${crane.packageSlug}`,
icon: 'carbon:data-view-alt'
}}
/>
<Link
href="/package/{crane.packageSlug}"
class="rounded border border-neutral-500 px-2 py-1 text-xs"
>
Available on <strong>CRAN/E</strong>
</Link>
{/if}
<SubGridIcon
meta={{
Expand Down

0 comments on commit acd0f00

Please sign in to comment.