From 0e4a4935154317a6ef10eef8ab1536f143d6ddc9 Mon Sep 17 00:00:00 2001 From: jycouet Date: Mon, 2 Feb 2026 00:08:31 +0100 Subject: [PATCH] first test --- .../GitHubContributorsCard.svelte | 46 +++++++++++++------ .../GitHubContributorsCardSettings.svelte | 32 +++++++++++++ src/lib/cards/GitHubContributorsCard/index.ts | 2 + src/routes/(auth)/oauth/callback/+page.svelte | 3 +- 4 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 src/lib/cards/GitHubContributorsCard/GitHubContributorsCardSettings.svelte diff --git a/src/lib/cards/GitHubContributorsCard/GitHubContributorsCard.svelte b/src/lib/cards/GitHubContributorsCard/GitHubContributorsCard.svelte index 79a0576..6838794 100644 --- a/src/lib/cards/GitHubContributorsCard/GitHubContributorsCard.svelte +++ b/src/lib/cards/GitHubContributorsCard/GitHubContributorsCard.svelte @@ -13,6 +13,7 @@ let owner: string = $derived(item.cardData.owner ?? ''); let repo: string = $derived(item.cardData.repo ?? ''); let repoKey: string = $derived(owner && repo ? `${owner}/${repo}` : ''); + let layout: 'hex' | 'grid' = $derived(item.cardData.layout ?? 'hex'); let serverContributors: GitHubContributor[] = $derived.by(() => { if (!repoKey) return []; @@ -66,27 +67,35 @@ const colsNarrow = Math.max(1, colsWide - 1); const maxRows = Math.floor((availH + GAP) / (size + GAP)); let capacity = 0; + // Pattern: narrow, wide, narrow, wide... (row 0 is narrow) for (let r = 0; r < maxRows; r++) { - capacity += r % 2 === 0 ? colsWide : colsNarrow; + capacity += r % 2 === 0 ? colsNarrow : colsWide; } return capacity; } + function gridCapacity(size: number, availW: number, availH: number): number { + const cols = Math.floor((availW + GAP) / (size + GAP)); + const rows = Math.floor((availH + GAP) / (size + GAP)); + return cols * rows; + } + let computedSize = $derived.by(() => { if (!containerWidth || !containerHeight || totalItems === 0) return 40; let lo = MIN_SIZE; let hi = MAX_SIZE; + const capacityFn = layout === 'hex' ? hexCapacity : gridCapacity; while (lo <= hi) { const mid = Math.floor((lo + hi) / 2); - const availW = containerWidth - mid; - const availH = containerHeight - mid; + const availW = containerWidth - (layout === 'hex' ? mid : 0); + const availH = containerHeight - (layout === 'hex' ? mid : 0); if (availW <= 0 || availH <= 0) { hi = mid - 1; continue; } - if (hexCapacity(mid, availW, availH) >= totalItems) { + if (capacityFn(mid, availW, availH) >= totalItems) { lo = mid + 1; } else { hi = mid - 1; @@ -96,23 +105,34 @@ return Math.max(MIN_SIZE, hi); }); - let padding = $derived(computedSize / 2); + let padding = $derived(layout === 'hex' ? computedSize / 2 : 0); let rows = $derived.by(() => { - const availW = containerWidth - computedSize; + const availW = containerWidth - (layout === 'hex' ? computedSize : 0); if (availW <= 0) return [] as GitHubContributor[][]; + const colsWide = Math.floor((availW + GAP) / (computedSize + GAP)); - const colsNarrow = Math.max(1, colsWide - 1); + const colsNarrow = layout === 'hex' ? Math.max(1, colsWide - 1) : colsWide; - const result: GitHubContributor[][] = []; - let idx = 0; + // Calculate row sizes from bottom up, then reverse for incomplete row at top + const rowSizes: number[] = []; + let remaining = namedContributors.length; let rowNum = 0; - while (idx < namedContributors.length) { - const cols = rowNum % 2 === 0 ? colsWide : colsNarrow; - result.push(namedContributors.slice(idx, idx + cols)); - idx += cols; + while (remaining > 0) { + const cols = layout === 'hex' && rowNum % 2 === 0 ? colsNarrow : colsWide; + rowSizes.push(Math.min(cols, remaining)); + remaining -= cols; rowNum++; } + rowSizes.reverse(); + + // Fill rows with contributors in order + const result: GitHubContributor[][] = []; + let idx = 0; + for (const size of rowSizes) { + result.push(namedContributors.slice(idx, idx + size)); + idx += size; + } return result; }); diff --git a/src/lib/cards/GitHubContributorsCard/GitHubContributorsCardSettings.svelte b/src/lib/cards/GitHubContributorsCard/GitHubContributorsCardSettings.svelte new file mode 100644 index 0000000..865c922 --- /dev/null +++ b/src/lib/cards/GitHubContributorsCard/GitHubContributorsCardSettings.svelte @@ -0,0 +1,32 @@ + + +
+ +
+ {#each layoutOptions as opt (opt.value)} + + {/each} +
+
diff --git a/src/lib/cards/GitHubContributorsCard/index.ts b/src/lib/cards/GitHubContributorsCard/index.ts index 7c27691..db7f23f 100644 --- a/src/lib/cards/GitHubContributorsCard/index.ts +++ b/src/lib/cards/GitHubContributorsCard/index.ts @@ -1,6 +1,7 @@ import type { CardDefinition } from '../types'; import GitHubContributorsCard from './GitHubContributorsCard.svelte'; import CreateGitHubContributorsCardModal from './CreateGitHubContributorsCardModal.svelte'; +import GitHubContributorsCardSettings from './GitHubContributorsCardSettings.svelte'; export type GitHubContributor = { username: string; @@ -15,6 +16,7 @@ export const GitHubContributorsCardDefinition = { type: 'githubContributors', contentComponent: GitHubContributorsCard, creationModalComponent: CreateGitHubContributorsCardModal, + settingsComponent: GitHubContributorsCardSettings, createNew: (card) => { card.w = 4; card.h = 2; diff --git a/src/routes/(auth)/oauth/callback/+page.svelte b/src/routes/(auth)/oauth/callback/+page.svelte index 89ac157..097a332 100644 --- a/src/routes/(auth)/oauth/callback/+page.svelte +++ b/src/routes/(auth)/oauth/callback/+page.svelte @@ -12,7 +12,7 @@ goto('/' + getHandleOrDid(user.profile) + '/edit', {}); } - if(!user.isInitializing && !startedErrorTimer) { + if (!user.isInitializing && !startedErrorTimer) { startedErrorTimer = true; setTimeout(() => { @@ -30,7 +30,6 @@ >There was an error signing you in, please go back to the homepage and try again. - {/if} -- 2.51.2