✨ feat: update [...ref].astro page

swadhinbiswas committed 3 months ago
c3d05c4
1 parent a2678d7
commit c3d05c4
1 file changed
+26 -2
▼src/pages/[owner]/[repo]/tree/[...ref].astro
+26-2
87
87
88
88
const refParam = Astro.params.ref || "";
89
89
let currentBranch = repoData.defaultBranch;
90
+// Use actual git branch if default branch doesn't exist in git
91
+if (branches.length > 0 && !branches.includes(currentBranch)) {
92
+ currentBranch = branches[0]; // Use first actual branch from git
93
+}
90
94
let currentPath = "";
91
95
92
96
// Helper to check if a ref exists
339
343
class="hidden absolute left-0 top-full mt-1 w-64 rounded-md border bg-popover p-2 shadow-lg z-10"
340
344
>
341
345
<input
346
+ id="branch-search"
342
347
type="search"
343
348
placeholder="Find a branch..."
344
349
class="w-full mb-2 h-8 rounded-md border bg-background px-3 text-sm"
350
+ onclick="event.stopPropagation()"
345
351
/>
346
- <div class="max-h-64 overflow-y-auto">
352
+ <div id="branch-list" class="max-h-64 overflow-y-auto">
347
353
<div
348
354
class="text-xs font-semibold text-muted-foreground px-2 py-1"
349
355
>
352
358
{
353
359
branches.map((b) => (
354
360
<a
361
+ data-branch={b}
355
362
href={`/${repo.owner}/${repo.name}/tree/${b}`}
356
- class={`flex items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent ${b === currentBranch ? "bg-accent" : ""}`}
363
+ class={`branch-item flex items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent ${b === currentBranch ? "bg-accent" : ""}`}
357
364
>
358
365
{b === currentBranch && (
359
366
<span class="text-primary">✓</span>
535
542
// Branch dropdown
536
543
const branchBtn = document.getElementById("branch-btn");
537
544
const branchDropdown = document.getElementById("branch-dropdown");
545
+ const branchSearch = document.getElementById("branch-search") as HTMLInputElement;
538
546
539
547
branchBtn?.addEventListener("click", (e) => {
540
548
e.stopPropagation();
541
549
branchDropdown?.classList.toggle("hidden");
542
550
document.getElementById("clone-dropdown")?.classList.add("hidden");
551
+ if (!branchDropdown?.classList.contains("hidden")) {
552
+ branchSearch?.focus();
553
+ }
554
+ });
555
+
556
+ // Branch search/filter
557
+ branchSearch?.addEventListener("input", (e) => {
558
+ const query = (e.target as HTMLInputElement).value.toLowerCase();
559
+ document.querySelectorAll(".branch-item").forEach((el) => {
560
+ const branch = el.getAttribute("data-branch") || "";
561
+ (el as HTMLElement).style.display = branch.toLowerCase().includes(query) ? "" : "none";
562
+ });
563
+ });
564
+
565
+ branchSearch?.addEventListener("click", (e) => {
566
+ e.stopPropagation();
543
567
});
544
568
545
569
// Clone dropdown
546
570