Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Sky 1.0 #4

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env

This file was deleted.

3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_SKY_API_KEY=""
VITE_SKY_HOST='localhost:1999'
VITE_SKY_API_URL='http://localhost:3000/registry/api/sky'
1,432 changes: 676 additions & 756 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
"sky": "xstate sky \"./src/**/*.ts?(x)\""
},
"dependencies": {
"@statelyai/sky": "0.0.11",
"@statelyai/sky-react": "0.0.11",
"@xstate/react": "4.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"xstate": "5.2.1"
"@statelyai/sky": "0.0.14",
"@statelyai/sky-react": "0.0.14",
"@xstate/react": "4.1.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"xstate": "5.15.0"
},
"devDependencies": {
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@vitejs/plugin-react": "^4.1.1",
"@xstate/cli": "0.5.12",
"prettier": "^3.1.0",
"prettier-plugin-organize-imports": "^3.2.4",
"typescript": "5.2.2",
"vite": "^4.5.0"
"@types/node": "^20.14.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"@xstate/cli": "0.5.17",
"prettier": "^3.3.3",
"prettier-plugin-organize-imports": "^4.0.0",
"typescript": "5.5.4",
"vite": "^5.3.4"
}
}
83 changes: 31 additions & 52 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,43 @@
import { useEffect, useState } from 'react';
import Counter from './examples/counter';
import TrafficLight from './examples/trafficLight/trafficLight';
import Home from './home';
import { createSkyClient } from '@statelyai/sky';
import { useMachine } from '@xstate/react';
import { useState } from 'react';
import { __unsafe_getAllOwnEventDescriptors, InspectionEvent } from 'xstate';
import { NextEvents } from './components/NextEvents';
import { machine } from './machine';

const pages = ['home', 'counter', 'trafficlight'] as const;
type Page = (typeof pages)[number];
const sky = createSkyClient({
apiKey: import.meta.env.VITE_SKY_API_KEY,
sessionId: 'onboarding',
});

function getComponent(page: Page) {
switch (page) {
case 'home':
return <Home />;
case 'counter':
return <Counter />;
case 'trafficlight':
return <TrafficLight />;
}
}
export default function App() {
const [receivedEvents, setReceivedEvents] = useState<InspectionEvent[]>([]);
const [state, send, actor] = useMachine(machine, {
inspect: sky.inspect,
});

function getPage() {
if (typeof window !== 'undefined') {
const queryParams = new URLSearchParams(window.location.search);
const pageQueryParam = queryParams.get('page');
if (pageQueryParam && pages.includes(pageQueryParam as Page)) {
return pageQueryParam as Page;
}
}
return 'home';
}
sky.inspectListener = (event) => {
console.log('event received from Sky', event);
setReceivedEvents((events) => [...events, event]);
};

function setPageQueryParam(page: Page) {
if (typeof window !== 'undefined') {
window.history.replaceState(
null,
'',
`?page=${page}` + window.location.hash,
);
}
}

export default function App() {
const [page, setPage] = useState<Page>(getPage());
useEffect(() => setPageQueryParam(page), [page]);
const nextEvents = __unsafe_getAllOwnEventDescriptors(actor.getSnapshot());

return (
<div className="app">
<div className="app-header">
<p className="sky-header">Stately Sky Starter ⛅</p>
<div className="app-pages">
{pages.map((p) => (
<button
key={p}
className={p === page ? 'app-active-page' : 'app-page'}
onClick={() => setPage(p)}
>
{p}
</button>
))}
</div>
<p className="sky-header">Stately Sky 1.0 WIP ⛅</p>
</div>
<NextEvents nextEvents={nextEvents} send={send} />
<div>
<p>State of local actor</p>
<pre>actor.sessionId: {actor.sessionId}</pre>
<pre>{JSON.stringify(state)}</pre>
<p>{`Received ${receivedEvents.length} events from Sky`}</p>
{receivedEvents.map((event, index) => (
<pre key={`event-${index}`}>{JSON.stringify(event)}</pre>
))}
</div>
{getComponent(page)}
</div>
);
}
20 changes: 0 additions & 20 deletions src/components/Footer.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/NextEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function NextEvents<T extends AnyEventObject>({
}) {
return (
<div className="next-events">
<h2>{nextEvents.length > 1 ? 'Next possible events' : 'Next event'}</h2>
<p>Next possible event{nextEvents.length > 1 ? 's' : ''}</p>
<div className="event-buttons">
{nextEvents.map((event) => (
<button key={event} onClick={() => send?.({ type: event } as T)}>
Expand Down
47 changes: 0 additions & 47 deletions src/examples/counter.sky.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/examples/counter.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/examples/trafficLight/Light.tsx

This file was deleted.

38 changes: 0 additions & 38 deletions src/examples/trafficLight/lights.css

This file was deleted.

55 changes: 0 additions & 55 deletions src/examples/trafficLight/trafficLight.sky.ts

This file was deleted.

Loading