Skip to content

Commit f72efc3

Browse files
feat(details): improve "go back" button, fix label
1 parent 02fea1d commit f72efc3

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/routes/[pid=pid]/[org]/[repo]/[id=number]/PageRenderer.svelte

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</script>
2121

2222
<script lang="ts">
23+
import { browser } from "$app/environment";
2324
import {
2425
ArrowUpRight,
2526
ChevronLeft,
@@ -194,6 +195,14 @@
194195
195196
return result;
196197
}
198+
199+
/**
200+
* Returns the previous page to go back to
201+
*/
202+
function getPreviousPath() {
203+
if (!browser || !document.referrer) return "/";
204+
return new URL(document.referrer).pathname;
205+
}
197206
</script>
198207

199208
<h2 class="group mb-8 scroll-m-20 border-b pb-2 text-2xl font-semibold xs:text-3xl">
@@ -522,25 +531,34 @@
522531
</div>
523532
<!-- Bottom links -->
524533
<div class="mt-16 flex w-full flex-col-reverse justify-between gap-8 md:flex-row md:items-center">
525-
<Button href="/" variant="link" class="group mr-auto md:mr-0">
534+
<Button href={getPreviousPath()} variant="link" class="group mr-auto md:mr-0">
526535
<ChevronLeft class="mr-1 size-4 transition-transform duration-300 group-hover:-translate-x-1" />
527-
Back to homepage
536+
Back
537+
{#if getPreviousPath() === "/"}
538+
to homepage
539+
{/if}
528540
</Button>
529541
<div class="flex flex-col-reverse items-end gap-4 md:flex-row md:items-center">
530-
<div class="flex flex-wrap justify-end gap-4">
531-
{#each linkedEntities as closingIssue (closingIssue.number)}
532-
<Button
533-
href="/{metadata.type === 'pull'
534-
? 'issues'
535-
: 'pull'}/{metadata.org}/{metadata.repo}/{closingIssue.number}"
536-
variant="secondary"
537-
>
538-
Open {metadata.type === "pull" ? "issue" : "pull request"} #{closingIssue.number}
539-
</Button>
540-
{/each}
541-
</div>
542+
{#if linkedEntities.length > 0}
543+
<div class="flex flex-wrap justify-end gap-4">
544+
{#each linkedEntities as closingIssue (closingIssue.number)}
545+
<Button
546+
href="/{metadata.type === 'pull'
547+
? 'issues'
548+
: 'pull'}/{metadata.org}/{metadata.repo}/{closingIssue.number}"
549+
variant="secondary"
550+
>
551+
Open {metadata.type === "pull" ? "issue" : "pull request"} #{closingIssue.number}
552+
</Button>
553+
{/each}
554+
</div>
555+
{/if}
542556
<Button href={info.html_url} target="_blank" class="group dark:text-black">
543-
Open {metadata.type === "pull" ? "pull request" : "issue"} on GitHub
557+
Open {metadata.type === "pull"
558+
? "pull request"
559+
: metadata.type === "issue"
560+
? "issue"
561+
: "discussion"} on GitHub
544562
<ArrowUpRight
545563
class="ml-2 size-4 transition-transform duration-300 group-hover:translate-x-1 group-hover:-translate-y-1"
546564
/>

0 commit comments

Comments
 (0)