Skip to content

Commit

Permalink
feat(Client): mockConnection
Browse files Browse the repository at this point in the history
Co-authored-by: Johan Nyman <[email protected]>
  • Loading branch information
jstarpl and nytamin committed Nov 15, 2023
1 parent 3e81a6e commit 9fdde6c
Show file tree
Hide file tree
Showing 16 changed files with 615 additions and 51 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
26 changes: 7 additions & 19 deletions packages/apps/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import React from 'react'
import { TestInterface } from './TestInterface.tsx'
import { APIConnection } from './api/ApiConnection.ts'

import './App.css'
import { RundownList } from './RundownList/RundownList.tsx'
import { CurrentRundown } from './CurrentRundown/CurrentRundown.tsx'
import { TestPlaylists } from './TestPlaylists.tsx'
function App(props: { api: APIConnection }) {
const [count, setCount] = useState(0)

function App(props: { api: APIConnection }): React.JSX.Element {
return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
<RundownList />
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>count is {count}</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
<div>
<CurrentRundown />
</div>
<p className="read-the-docs">Click on the Vite and React logos to learn more!!</p>
<div>
<TestInterface api={props.api} />
</div>
Expand Down
35 changes: 35 additions & 0 deletions packages/apps/client/src/CurrentRundown/CurrentRundown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import { observer } from 'mobx-react-lite'
import { AppStore } from '../stores/AppStore'
import { Segment } from './Segment'

const CurrentRundown = observer((): React.JSX.Element => {
const openRundown = AppStore.rundownStore.openRundown

if (!openRundown) {
return <p>No open rundown</p>
}

function onClose() {
openRundown?.close()
}

return (
<>
<h1>{openRundown.name}</h1>
<p>
<button onClick={onClose}>Close</button>
</p>
<ul>
{openRundown.segmentsInOrder.map((segment) => (
<li key={segment.id}>
<Segment segment={segment} />
</li>
))}
</ul>
</>
)
})
CurrentRundown.displayName = 'CurrentRundown'

export { CurrentRundown }
11 changes: 11 additions & 0 deletions packages/apps/client/src/CurrentRundown/Line.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import { observer } from 'mobx-react-lite'
import { UILine } from '../model/UILine'

const Line = observer(({ line }: { line: UILine | undefined }): React.JSX.Element | null => {
if (!line) return null
return <p>{line.slug}</p>
})
Line.displayName = 'Line'

export { Line }
24 changes: 24 additions & 0 deletions packages/apps/client/src/CurrentRundown/Segment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import { observer } from 'mobx-react-lite'
import { UISegment } from '../model/UISegment'
import { Line } from './Line'

const Segment = observer(({ segment }: { segment: UISegment | undefined }): React.JSX.Element | null => {
if (!segment) return null

return (
<>
<p>{segment.name}</p>
<ul>
{segment.linesInOrder.map((line) => (
<li key={line.id}>
<Line line={line} />
</li>
))}
</ul>
</>
)
})
Segment.displayName = 'Segment'

export { Segment }
22 changes: 22 additions & 0 deletions packages/apps/client/src/RundownList/RundownEntry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import { observer } from 'mobx-react-lite'
import { AppStore } from '../stores/AppStore'
import { UIRundownId } from '../model/UIRundown'

const RundownEntry = observer(({ rundownId }: { rundownId: UIRundownId }): React.JSX.Element => {
const rundownEntry = AppStore.rundownStore.allRundowns.get(rundownId)

function onOpen() {
if (!rundownEntry) return
AppStore.rundownStore.loadRundown(rundownEntry.playlistId)
}

return (
<p>
{rundownEntry?.name} <button onClick={onOpen}>Open</button>
</p>
)
})
RundownEntry.displayName = 'RundownEntry'

export { RundownEntry }
25 changes: 25 additions & 0 deletions packages/apps/client/src/RundownList/RundownList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'
import { keys } from 'mobx'
import { observer } from 'mobx-react-lite'
import { AppStore } from '../stores/AppStore'
import { UIRundownId } from '../model/UIRundown'
import { RundownEntry } from './RundownEntry'

const RundownList = observer((): React.JSX.Element => {
const allRundownIds = keys<UIRundownId>(AppStore.rundownStore.allRundowns)

return (
<>
<ul>
{allRundownIds.map((rundownId) => (
<li key={rundownId}>
<RundownEntry rundownId={rundownId} />
</li>
))}
</ul>
</>
)
})
RundownList.displayName = 'RundownList'

export { RundownList }
4 changes: 2 additions & 2 deletions packages/apps/client/src/lib/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid from 'uuid';
import { v4 } from 'uuid'

export function randomId() {
return uuid.v4()
return v4()
}
Loading

0 comments on commit 9fdde6c

Please sign in to comment.