Add hash routing

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2022-11-15 15:24:12 +01:00
parent cd60ad7298
commit f38893407a
14 changed files with 87 additions and 35 deletions
+18 -10
View File
@@ -2,18 +2,19 @@
import type { Blob } from "@app/project";
import type { ProjectRoute } from "@app/router/definitions";
import Readme from "@app/base/projects/Readme.svelte";
import HeaderToggleLabel from "@app/base/projects/HeaderToggleLabel.svelte";
import ProjectLink from "@app/router/ProjectLink.svelte";
import Readme from "@app/base/projects/Readme.svelte";
import { isMarkdownPath, scrollIntoView, twemoji } from "@app/utils";
import { onMount } from "svelte";
import { updateProjectRoute } from "@app/router";
export let blob: Blob;
export let line: string | null;
export let getImage: (path: string) => Promise<Blob>;
export let activeRoute: ProjectRoute;
export let blob: Blob;
export let getImage: (path: string) => Promise<Blob>;
export let line: string | undefined = undefined;
$: lineNumber = line ? parseInt(line.substring(1)) : null;
$: lineNumber = line ? parseInt(line.substring(1)) : undefined;
const lastCommit = blob.info.lastCommit;
const lines = blob.binary ? 0 : (blob.content.match(/\n/g) || []).length;
@@ -25,16 +26,23 @@
?.values()
.next().value;
$: if (line) {
scrollIntoView(line);
}
// Waiting onMount, due to the line numbers still loading.
onMount(() => {
if (line) {
scrollIntoView(line);
}
});
const isMarkdown = isMarkdownPath(blob.path);
// If we have a line number we should show the raw output.
let showMarkdown = line ? false : isMarkdown;
const toggleMarkdown = () => {
updateProjectRoute({ hash: undefined });
updateProjectRoute({ line: undefined });
showMarkdown = !showMarkdown;
};
$: if (line) {
scrollIntoView(line);
}
</script>
<style>
@@ -215,7 +223,7 @@
<div class="line-numbers">
{#each lineNumbers as lineNumber}
<ProjectLink
projectParams={{ hash: `L${lineNumber}` }}
projectParams={{ line: `L${lineNumber}` }}
id="L{lineNumber}">
<span class="line-number" class:highlighted={lineNumber === line} />
{lineNumber}
+1 -1
View File
@@ -28,7 +28,7 @@
export let activeRoute: ProjectRoute;
$: path = activeRoute.params.path || "/";
$: line = activeRoute.params.hash || null;
$: line = activeRoute.params.line;
// When the component is loaded the first time, the blob is yet to be loaded.
let state: State = { status: Status.Loading, path };
+1
View File
@@ -51,6 +51,7 @@
router.updateProjectRoute({
revision,
path,
line: activeRoute.params.line,
hash: activeRoute.params.hash,
route: undefined,
});