Skip to content

Commit

Permalink
Merge pull request #141 from UCLA-IRL/varun/connect-root
Browse files Browse the repository at this point in the history
root: connect to testbed on any page
  • Loading branch information
zjkmxy authored Oct 20, 2024
2 parents 93ab83a + 14ba8ae commit 8abceae
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
4 changes: 1 addition & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Paper, Typography } from '@suid/material'
import { useNdnWorkspace, initTestbed } from './Context'
import { useNdnWorkspace } from './Context'
import { useNavigate } from '@solidjs/router'

function isSafari() {
Expand All @@ -10,8 +10,6 @@ function App() {
const { currentConnConfig } = useNdnWorkspace()!
const navigate = useNavigate()

initTestbed()

const configToDescription = () => {
const config = currentConnConfig()
if (!config) {
Expand Down
13 changes: 6 additions & 7 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Producer, produce, consume } from '@ndn/endpoint'
import { Name, Interest, Component } from '@ndn/packet'

Check warning on line 4 in src/backend/main.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/backend/main.ts#L4

'Component' is defined but never used (@typescript-eslint/no-unused-vars)
import * as nfdmgmt from '@ndn/nfdmgmt'
import { getYjsDoc} from '@syncedstore/core'
import { getYjsDoc } from '@syncedstore/core'
import * as Y from 'yjs'
import { CertStorage } from '@ucla-irl/ndnts-aux/security'
import { RootDocStore, initRootDoc, project, profiles, connections } from './models'
Expand Down Expand Up @@ -234,18 +234,17 @@ export async function bootstrapWorkspace(opts: {
let targetSVEncoded = targetName.at(-1).value
// load local state first with the snapshot.
await persistStore.set('localState', targetSVEncoded)
// Merge the SV with the local one so that when SyncAgent starts up,

// Merge the SV with the local one so that when SyncAgent starts up,
// it replays the local updates (in local storage), starting from snapshot's vector.
let localSVEncoded = await persistStore.get(aloSyncKey)
const localSVEncoded = await persistStore.get(aloSyncKey)
if (localSVEncoded) {
let localSV = Decoder.decode(localSVEncoded, StateVector)
let targetSV = Decoder.decode(targetSVEncoded, StateVector)
const localSV = Decoder.decode(localSVEncoded, StateVector)
const targetSV = Decoder.decode(targetSVEncoded, StateVector)
targetSV.mergeFrom(localSV)
targetSVEncoded = Encoder.encode(targetSV)
}
await persistStore.set(aloSyncKey, targetSVEncoded)

} catch (err: any) {

Check warning on line 248 in src/backend/main.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/backend/main.ts#L248

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
console.warn(err)
console.log('Aborting snapshot retrieval, falling back to SVS')
Expand Down
81 changes: 43 additions & 38 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,62 @@ import Root from './components/root-wrapper'
import App from './App'
import ShareLatex from './components/share-latex'
import OauthTest from './components/oauth-test'
import { NdnWorkspaceProvider, useNdnWorkspace } from './Context'
import { NdnWorkspaceProvider, useNdnWorkspace, initTestbed } from './Context'
import { Connect, StoredConns } from './components/connect'
import { Workspace, Profile, ConvertTestbed } from './components/workspace'
import { project } from './backend/models'
import { Toaster } from 'solid-toast'
import { Chat } from './components/chat/chat'
import ConfigPage from './components/config'

const root = document.getElementById('root')
const rootElement = document.getElementById('root')!

const rootComponent = (props: RouteSectionProps) => (
<Root
routes={[
{ icon: <HomeIcon />, href: '/', title: 'Home' },
{ icon: <AppsIcon />, href: '/profile', title: 'Workspace' },
{
icon: <DescriptionIcon />,
href: `/latex/${project.RootId}`,
title: 'Editor',
level: 1, // not displayed by default
trigger: () => {
const { booted } = useNdnWorkspace()!
return booted()
function RootComponent(props: RouteSectionProps) {
// Global initialization
initTestbed()

return (
<Root
routes={[
{ icon: <HomeIcon />, href: '/', title: 'Home' },
{ icon: <AppsIcon />, href: '/profile', title: 'Workspace' },
{
icon: <DescriptionIcon />,
href: `/latex/${project.RootId}`,
title: 'Editor',
level: 1, // not displayed by default
trigger: () => {
const { booted } = useNdnWorkspace()!
return booted()
},
},
},
{
icon: <ChatIcon />,
href: '/chat',
title: 'Chat',
level: 1, // not displayed by default
trigger: () => {
const { booted } = useNdnWorkspace()!
return booted()
{
icon: <ChatIcon />,
href: '/chat',
title: 'Chat',
level: 1, // not displayed by default
trigger: () => {
const { booted } = useNdnWorkspace()!
return booted()
},
},
},
{
icon: <SettingsEthernetIcon />,
href: '/connection',
title: 'Connection',
},
{ icon: <SettingsIcon />, href: '/config-page', title: 'Settings' },
]}
>
{props.children}
</Root>
)
{
icon: <SettingsEthernetIcon />,
href: '/connection',
title: 'Connection',
},
{ icon: <SettingsIcon />, href: '/config-page', title: 'Settings' },
]}
>
{props.children}
</Root>
)
}

render(
() => (
<NdnWorkspaceProvider>
<Router root={rootComponent}>
<Router root={RootComponent}>
<Route path="/" component={App} />
<Route path="/latex/:itemId" component={() => <ShareLatex rootUri="/latex" />} />
<Route path="/connection/add" component={Connect} />
Expand All @@ -81,5 +86,5 @@ render(
<Toaster />
</NdnWorkspaceProvider>
),
root!,
rootElement,
)

0 comments on commit 8abceae

Please sign in to comment.