-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4afdf04
commit 1ad24e6
Showing
91 changed files
with
2,728 additions
and
1,296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { Suspense, useRef } from 'preact/compat' | ||
import { Bucket } from 'synapse:srl/storage' | ||
import { createWebsite } from '@cohesible/synapse-preact' | ||
import { useServer, openBrowser } from '@cohesible/synapse-websites' | ||
|
||
const website = createWebsite() | ||
const bucket = new Bucket() | ||
|
||
const getData = (key: string) => { | ||
return bucket.get(key, 'utf-8').catch(e => { | ||
return (e as any).message | ||
}) | ||
} | ||
|
||
function BucketContents(props: { bucketKey: string }) { | ||
const data = useServer(getData, props.bucketKey) | ||
|
||
return <pre>{data}</pre> | ||
} | ||
|
||
function BucketPage(props: { bucketKey: string }) { | ||
return ( | ||
<div> | ||
<Suspense fallback={<div>loading</div>}> | ||
<BucketContents bucketKey={props.bucketKey}/> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
const addData = website.bind(async (key: string, data: string) => { | ||
await bucket.put(key, data) | ||
}) | ||
|
||
function BucketForm() { | ||
const keyRef = useRef<HTMLInputElement>() | ||
const valueRef = useRef<HTMLInputElement>() | ||
|
||
function submit() { | ||
const key = keyRef.current.value | ||
const value = valueRef.current.value | ||
|
||
addData(key, value).then(() => { | ||
window.location = window.location | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<label> | ||
Key | ||
<input type='text' ref={keyRef}></input> | ||
</label> | ||
<label> | ||
Value | ||
<input type='text' ref={valueRef}></input> | ||
</label> | ||
<button onClick={submit} style={{ marginLeft: '10px' }}>Add Item</button> | ||
</div> | ||
) | ||
} | ||
|
||
async function getItems() { | ||
console.log('getting items') | ||
return await bucket.list() | ||
} | ||
|
||
const doDelete = website.bind((key: string) => bucket.delete(key)) | ||
|
||
function BucketItem(props: { bucketKey: string }) { | ||
const k = props.bucketKey | ||
|
||
function deleteItem() { | ||
doDelete(k).then(() => { | ||
window.location = window.location | ||
}) | ||
} | ||
|
||
return ( | ||
<li> | ||
<div style={{ display: 'flex', maxWidth: '250px', marginBottom: '10px' }}> | ||
<a href={`/bucket/${k}`} style={{ flex: 'fit-content', alignSelf: 'flex-start' }}>{k}</a> | ||
<button onClick={deleteItem} style={{ alignSelf: 'flex-end' }}>Delete</button> | ||
</div> | ||
</li> | ||
) | ||
} | ||
|
||
function ItemList() { | ||
const items = useServer(getItems) | ||
|
||
if (items.length === 0) { | ||
return <div><b>There's nothing in the bucket!</b></div> | ||
} | ||
|
||
return ( | ||
<ul> | ||
{items.map(k => <BucketItem key={k} bucketKey={k}/>)} | ||
</ul> | ||
) | ||
} | ||
|
||
function HomePage() { | ||
return ( | ||
<div> | ||
<BucketForm></BucketForm> | ||
<br></br> | ||
<Suspense fallback='loading'> | ||
<ItemList/> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
website.page('/', HomePage) | ||
website.page('/bucket/{bucketKey}', BucketPage) | ||
|
||
export async function main() { | ||
openBrowser(website.url) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"@cohesible/synapse-preact": "spr:#synapse-preact" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"jsx": "react-jsx", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"jsxImportSource": "preact" | ||
}, | ||
"include": ["app.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { Suspense, useRef } from 'react' | ||
import { Bucket } from 'synapse:srl/storage' | ||
import { createWebsite } from '@cohesible/synapse-react' | ||
import { useServer, openBrowser } from '@cohesible/synapse-websites' | ||
|
||
const website = createWebsite() | ||
const bucket = new Bucket() | ||
|
||
const getData = (key: string) => { | ||
return bucket.get(key, 'utf-8').catch(e => { | ||
return (e as any).message | ||
}) | ||
} | ||
|
||
function BucketContents(props: { bucketKey: string }) { | ||
const data = useServer(getData, props.bucketKey) | ||
|
||
return <pre>{data}</pre> | ||
} | ||
|
||
function BucketPage(props: { bucketKey: string }) { | ||
return ( | ||
<div> | ||
<Suspense fallback={<div>loading</div>}> | ||
<BucketContents bucketKey={props.bucketKey}/> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
const addData = website.bind(async (key: string, data: string) => { | ||
await bucket.put(key, data) | ||
}) | ||
|
||
function BucketForm() { | ||
const keyRef = useRef<HTMLInputElement>() | ||
const valueRef = useRef<HTMLInputElement>() | ||
|
||
function submit() { | ||
const key = keyRef.current.value | ||
const value = valueRef.current.value | ||
|
||
addData(key, value).then(() => { | ||
window.location = window.location | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<label> | ||
Key | ||
<input type='text' ref={keyRef}></input> | ||
</label> | ||
<label> | ||
Value | ||
<input type='text' ref={valueRef}></input> | ||
</label> | ||
<button onClick={submit} style={{ marginLeft: '10px' }}>Add Item</button> | ||
</div> | ||
) | ||
} | ||
|
||
async function getItems() { | ||
return await bucket.list() | ||
} | ||
|
||
const doDelete = website.bind((key: string) => bucket.delete(key)) | ||
|
||
function BucketItem(props: { bucketKey: string }) { | ||
const k = props.bucketKey | ||
|
||
function deleteItem() { | ||
doDelete(k).then(() => { | ||
window.location = window.location | ||
}) | ||
} | ||
|
||
return ( | ||
<li> | ||
<div style={{ display: 'flex', maxWidth: '250px', marginBottom: '10px' }}> | ||
<a href={`/bucket/${k}`} style={{ flex: 'fit-content', alignSelf: 'flex-start' }}>{k}</a> | ||
<button onClick={deleteItem} style={{ alignSelf: 'flex-end' }}>Delete</button> | ||
</div> | ||
</li> | ||
) | ||
} | ||
|
||
function ItemList() { | ||
const items = useServer(getItems) | ||
|
||
if (items.length === 0) { | ||
return <div><b>There's nothing in the bucket!</b></div> | ||
} | ||
|
||
return ( | ||
<ul> | ||
{items.map(k => <BucketItem key={k} bucketKey={k}/>)} | ||
</ul> | ||
) | ||
} | ||
|
||
function HomePage() { | ||
return ( | ||
<div> | ||
<BucketForm></BucketForm> | ||
<br></br> | ||
<Suspense fallback='loading'> | ||
<ItemList/> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
website.page('/', HomePage) | ||
website.page('/bucket/{bucketKey}', BucketPage) | ||
|
||
export async function main() { | ||
openBrowser(website.url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"@cohesible/synapse-react": "spr:#synapse-react" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"jsx": "react-jsx", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext" | ||
}, | ||
"include": ["app.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.