Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjg committed May 13, 2021
1 parent 61f82ea commit 4464fdf
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 81 deletions.
1 change: 0 additions & 1 deletion .envrc

This file was deleted.

30 changes: 0 additions & 30 deletions shell.nix

This file was deleted.

10 changes: 6 additions & 4 deletions ui/DesignSystem/Component/ConnectionStatusIndicator.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { status as store, StatusType } from "../../src/localPeer.ts";
<script lang="typescript">
import { status as store, StatusType } from "../../src/localPeer";
import Remote from "../Component/Remote.svelte";
import { Icon } from "../Primitive";
Expand All @@ -8,7 +8,8 @@
import Syncing from "./ConnectionStatusIndicator/Syncing.svelte";
import Offline from "./ConnectionStatusIndicator/Offline.svelte";
const peerCount = count => {
const peerCount = (peers: { [peerId: string]: string[] }) => {
const count = Object.keys(peers).length;
if (count === 1) {
return "1 peer";
} else {
Expand All @@ -35,7 +36,8 @@
<Remote {store} let:data={status}>
<div>
{#if status.type === StatusType.Online}
<Tooltip value={`You’re connected to ${peerCount(status.connected)}`}>
<Tooltip
value={`You’re connected to ${peerCount(status.connectedPeers)}`}>
<div class="item indicator" data-cy="connection-status-online">
<Icon.Network />
</div>
Expand Down
7 changes: 5 additions & 2 deletions ui/Screen/NetworkDiagnostics.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="typescript">
import Router from "svelte-spa-router";
import { StatusType } from "../src/localPeer";
import { store } from "../src/screen/network";
import * as path from "../src/path";
Expand Down Expand Up @@ -37,6 +36,7 @@
looseActiveStateMatching: true,
},
];
</script>

<style>
Expand All @@ -45,12 +45,15 @@
flex-direction: column;
justify-content: center;
}
</style>

<SidebarLayout>
<Remote {store} let:data={{ status }}>
<Header>
<div slot="left" class="title"><h1>Status: {status.type}</h1></div>
<div slot="left" class="title">
<h1>Status: {status.type}</h1>
</div>
</Header>

<ActionBar>
Expand Down
2 changes: 2 additions & 0 deletions ui/Screen/NetworkDiagnostics/ConnectedPeers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { store } from "../../src/screen/network";
import Remote from "../../DesignSystem/Component/Remote.svelte";
</script>

<style>
Expand All @@ -12,6 +13,7 @@
border-collapse: collapse;
border: 3px solid purple;
}
</style>

<Remote {store} let:data={{ status }}>
Expand Down
1 change: 1 addition & 0 deletions ui/Screen/NetworkDiagnostics/StateTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import StyledCopyable from "../../DesignSystem/Component/StyledCopyable.svelte";
export let state: RoomState;
</script>

<table>
Expand Down
9 changes: 7 additions & 2 deletions ui/Screen/NetworkDiagnostics/WaitingRoom.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import { DateTime } from "luxon";
import { onDestroy } from "svelte";
import JSONTree from "svelte-json-tree";
import StateTable from "./StateTable.svelte";
import { waitingRoomEventLog, WaitingRoomTransition } from "../../src/localPeer";
import {
waitingRoomEventLog,
WaitingRoomTransition,
} from "../../src/localPeer";
let lastEvent: WaitingRoomTransition | null = null;
let eventsWithoutTicks: WaitingRoomTransition[] = [];
Expand All @@ -13,6 +16,7 @@
eventsWithoutTicks = e.filter(e => e.event.type !== "tick");
});
onDestroy(unsub);
</script>

<style>
Expand All @@ -30,6 +34,7 @@
thead th:nth-child(2) {
width: 10%;
}
</style>

<div>
Expand Down
32 changes: 16 additions & 16 deletions ui/src/localPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import * as session from "./session";
import type * as urn from "./urn";
import * as error from "./error";
import * as bacon from "./bacon";
import type {
Event as RoomEvent,
RoomState,
} from "./waitingRoom";
import type { Event as RoomEvent, RoomState } from "./waitingRoom";
import { eventSchema as roomEventSchema, roomStateSchema } from "./waitingRoom";

// TYPES
Expand Down Expand Up @@ -128,7 +125,6 @@ export type Event =
| WaitingRoomTransition
| { type: EventType.StatusChanged; old: Status; new: Status };


const eventSchema: zod.Schema<Event> = zod.union([
zod.object({
type: zod.literal(EventType.ProjectUpdated),
Expand All @@ -155,7 +151,7 @@ const eventSchema: zod.Schema<Event> = zod.union([
zod.object({
type: zod.literal(EventType.WaitingRoomTransition),
timestamp: zod.number(),
state_before: roomStateSchema,
state_before: roomStateSchema,
state_after: roomStateSchema,
event: roomEventSchema,
}),
Expand Down Expand Up @@ -257,17 +253,21 @@ eventBus.onValue(event => {
}
});

const waitingRoomEvents: bacon.Property<WaitingRoomTransition[]> = bacon.filterMap(
eventBus,
event => {
const waitingRoomEvents: bacon.Property<WaitingRoomTransition[]> = bacon
.filterMap(eventBus, event => {
if (event.type === EventType.WaitingRoomTransition) {
return event
return event;
} else {
return undefined
return undefined;
}
}
).scan<WaitingRoomTransition[]>([], (acc, event) => [...acc, event].slice(-200))
})
.scan<WaitingRoomTransition[]>([], (acc, event) =>
[...acc, event].slice(-200)
);

const waitingRoomEventLogStore: Writable<WaitingRoomTransition[]> = writable([])
waitingRoomEvents.onValue(events => waitingRoomEventLogStore.set(events))
export const waitingRoomEventLog: Readable<WaitingRoomTransition[]> = waitingRoomEventLogStore
const waitingRoomEventLogStore: Writable<WaitingRoomTransition[]> = writable(
[]
);
waitingRoomEvents.onValue(events => waitingRoomEventLogStore.set(events));
export const waitingRoomEventLog: Readable<WaitingRoomTransition[]> =
waitingRoomEventLogStore;
1 change: 0 additions & 1 deletion ui/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ export const networkDiagnosticsEvents = (): string =>
"/network-diagnostics/events";
export const networkDiagnosticsWaitingRoom = (): string =>
"/network-diagnostics/waiting-room";

53 changes: 28 additions & 25 deletions ui/src/waitingRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export enum PeerStatus {

export const eventSchema = zod.union([
zod.object({
type: zod.literal("tick")
type: zod.literal("tick"),
}),
zod.object({
type: zod.literal("created"),
Expand All @@ -43,13 +43,13 @@ export const eventSchema = zod.union([
zod.object({
type: zod.literal("cloning"),
urn: zod.string(),
peer: zod.string()
peer: zod.string(),
}),
zod.object({
type: zod.literal("cloningFailed"),
urn: zod.string(),
peer: zod.string(),
reason: zod.string()
reason: zod.string(),
}),
zod.object({
type: zod.literal("cloned"),
Expand All @@ -59,27 +59,30 @@ export const eventSchema = zod.union([
zod.object({
type: zod.literal("canceled"),
urn: zod.string(),
})
])

}),
]);

export const roomStateSchema = zod.record(zod.object({
state: zod.union([
zod.literal("Created"),
zod.literal("Requested"),
zod.literal("Found"),
zod.literal("Cloning"),
zod.literal("Cloned"),
zod.literal("Cancelled"),
zod.literal("Failed"),
zod.literal("TimedOut"),
]),
peers: zod.record(zod.union([
zod.literal("available"),
zod.literal("inProgress"),
zod.literal("failed"),
]))
}))
export const roomStateSchema = zod.record(
zod.object({
state: zod.union([
zod.literal("Created"),
zod.literal("Requested"),
zod.literal("Found"),
zod.literal("Cloning"),
zod.literal("Cloned"),
zod.literal("Cancelled"),
zod.literal("Failed"),
zod.literal("TimedOut"),
]),
peers: zod.record(
zod.union([
zod.literal("available"),
zod.literal("inProgress"),
zod.literal("failed"),
])
),
})
);

export type Event = zod.infer<typeof eventSchema>
export type RoomState = zod.infer<typeof roomStateSchema>
export type Event = zod.infer<typeof eventSchema>;
export type RoomState = zod.infer<typeof roomStateSchema>;

0 comments on commit 4464fdf

Please sign in to comment.