Show local projects instead of network to landing page, if available

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-09-04 12:06:03 +02:00
parent 542630a7f7
commit 45830f6cd9
7 changed files with 29 additions and 11 deletions
+1 -2
View File
@@ -28,8 +28,7 @@
const activeRouteStore = router.activeRouteStore;
void router.loadFromLocation();
httpd.initialize();
void httpd.initialize().finally(() => void router.loadFromLocation());
if (!window.VITEST && !window.PLAYWRIGHT && import.meta.env.PROD) {
const plausible = Plausible({
+2 -2
View File
@@ -147,7 +147,7 @@ function pollSession() {
pollHttpdStateHandle = window.setInterval(() => checkState(), 10_000);
}
export function initialize() {
export async function initialize() {
// Sync session state changes with other open tabs and windows.
addEventListener("storage", event => {
if (
@@ -159,7 +159,7 @@ export function initialize() {
}
});
void checkState();
await checkState();
// Properly clean up setInterval and restart session polling when Vite
// performs hot module reload on file changes.
+10 -2
View File
@@ -1,12 +1,15 @@
<script lang="ts">
import type { ProjectBaseUrlActivity } from "./router";
import { api } from "@app/lib/httpd";
import { twemoji } from "@app/lib/utils";
import Link from "@app/components/Link.svelte";
import ProjectCard from "@app/components/ProjectCard.svelte";
export let projects: ProjectBaseUrlActivity[];
$: localProjects = projects[0]?.baseUrl === api.baseUrl;
</script>
<style>
@@ -61,8 +64,13 @@
{#if projects.length > 0}
<div class="heading">
Explore <span class="txt-bold">projects</span>
on the Radicle network.
{#if localProjects}
Explore <span class="txt-bold">projects</span>
on your local node.
{:else}
Explore <span class="txt-bold">projects</span>
on the Radicle network.
{/if}
</div>
<div class="projects">
+12 -1
View File
@@ -2,6 +2,9 @@ import type { LoadErrorRoute } from "@app/lib/router/definitions";
import type { ProjectBaseUrl } from "@app/lib/search";
import type { WeeklyActivity } from "@app/lib/commit";
import { get } from "svelte/store";
import { api, httpdStore } from "@app/lib/httpd";
import { config } from "@app/lib/config";
import { getProjectsFromNodes } from "@app/lib/search";
import { loadProjectActivity } from "@app/lib/commit";
@@ -22,7 +25,15 @@ export interface HomeLoadedRoute {
export async function loadHomeRoute(): Promise<
HomeLoadedRoute | LoadErrorRoute
> {
const projects = await getProjectsFromNodes(config.projects.pinned);
let projects: ProjectBaseUrl[] = [];
if (get(httpdStore).state !== "stopped") {
projects = (await api.project.getAll()).map(project => ({
project,
baseUrl: api.baseUrl,
}));
} else {
projects = await getProjectsFromNodes(config.projects.pinned);
}
const results = await Promise.all(
projects.map(async projectNode => {
const activity = await loadProjectActivity(
+1 -1
View File
@@ -13,7 +13,7 @@ test("show pinned projects", async ({ page }) => {
await page.addInitScript(appConfigWithFixture);
await page.goto("/");
await expect(
page.getByText("Explore projects on the Radicle network."),
page.getByText("Explore projects on your local node."),
).toBeVisible();
// Shows pinned project name.
+2 -2
View File
@@ -226,11 +226,11 @@ function log(text: string, label: string, outputLog: Stream.Writable) {
}
}
export function appConfigWithFixture() {
export function appConfigWithFixture(defaultLocalHttpdPort = 8081) {
window.APP_CONFIG = {
nodes: {
defaultHttpdPort: 8081,
defaultLocalHttpdPort: 8081,
defaultLocalHttpdPort: defaultLocalHttpdPort,
defaultHttpdScheme: "http",
defaultNodePort: 8776,
pinned: [
+1 -1
View File
@@ -36,7 +36,7 @@ test("load error", async ({ page }) => {
route => route.fulfill({ status: 500 }),
);
await page.addInitScript(appConfigWithFixture);
await page.addInitScript(appConfigWithFixture, 8090);
await page.goto("/", { waitUntil: "networkidle" });
await expect(page).toHaveScreenshot();
});