@enbox/create-dapp 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/bin/create-dapp.mjs +10 -7
- package/package.json +1 -2
- package/template/README.md +25 -16
- package/template/package.json +2 -2
- package/template/src/App.tsx +2 -2
- package/template/src/application.ts +2 -2
- package/template/src/demo/TaskBoard.tsx +136 -0
- package/template/src/demo/demo.css +10 -12
- package/template/src/demo/protocol.ts +16 -18
- package/template/src/demo/use-task-board.ts +16 -0
- package/template/src/main.tsx +4 -38
- package/template/package-lock.json +0 -3211
- package/template/src/demo/Demo.tsx +0 -48
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useEnboxMutation, useRecords } from '@enbox/react';
|
|
2
|
-
|
|
3
|
-
import { CHOICES, DemoProtocol } from './protocol.js';
|
|
4
|
-
import type { ChoiceEmoji } from './protocol.js';
|
|
5
|
-
import './demo.css';
|
|
6
|
-
|
|
7
|
-
export function Demo({ disabled = false }: { disabled?: boolean }) {
|
|
8
|
-
const choices = useRecords(DemoProtocol, 'choice', { materialize: true, pagination: { limit: 1 } });
|
|
9
|
-
const save = useEnboxMutation((enbox, emoji: ChoiceEmoji) =>
|
|
10
|
-
enbox.using(DemoProtocol).records.set('choice', { data: { emoji } }));
|
|
11
|
-
const observed = CHOICES.find(({ emoji }) => emoji === choices.records[0]?.value.emoji);
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<section className="panel demo" aria-labelledby="demo-title">
|
|
15
|
-
<h2 id="demo-title">Your first record</h2>
|
|
16
|
-
<p>Choose a little hello. It’s encrypted for this app, separate from your public profile.</p>
|
|
17
|
-
<fieldset className="choice-options" disabled={disabled || save.isPending || choices.status !== 'ready'}>
|
|
18
|
-
<legend className="sr-only">Choose your hello</legend>
|
|
19
|
-
{CHOICES.map(({ emoji, label }) => (
|
|
20
|
-
<button type="button" className="choice-option" key={emoji}
|
|
21
|
-
aria-label={`Choose ${label.toLowerCase()}`}
|
|
22
|
-
aria-pressed={observed?.emoji === emoji}
|
|
23
|
-
onClick={() => { void save.run(emoji).catch(() => {}); }}>
|
|
24
|
-
<span className="choice-emoji" aria-hidden="true">{emoji}</span>
|
|
25
|
-
<span>{label}</span>
|
|
26
|
-
</button>
|
|
27
|
-
))}
|
|
28
|
-
</fieldset>
|
|
29
|
-
<p className="demo-status" role="status">
|
|
30
|
-
{save.isPending ? 'Saving your choice…'
|
|
31
|
-
: choices.status === 'loading' ? 'Reading your saved choice…'
|
|
32
|
-
: observed ? `Saved: ${observed.emoji} ${observed.label}` : 'Choose an emoji to get started.'}
|
|
33
|
-
</p>
|
|
34
|
-
{choices.status === 'error' && (
|
|
35
|
-
<div className="notice notice-error" role="alert">
|
|
36
|
-
<p>Couldn’t read your choice: {choices.error.message}</p>
|
|
37
|
-
<button type="button" className="button button-secondary" disabled={disabled || save.isPending}
|
|
38
|
-
onClick={() => { void choices.retry().catch(() => {}); }}>
|
|
39
|
-
Try again
|
|
40
|
-
</button>
|
|
41
|
-
</div>
|
|
42
|
-
)}
|
|
43
|
-
{save.error && (
|
|
44
|
-
<p className="error-detail" role="alert">Couldn’t save: {save.error.message} Choose an emoji again to retry.</p>
|
|
45
|
-
)}
|
|
46
|
-
</section>
|
|
47
|
-
);
|
|
48
|
-
}
|