create-arona-app 0.0.1-dev.ff9c398 → 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/LICENSE +21 -0
- package/README.md +11 -44
- package/bin/create-arona-app.js +115 -112
- package/package.json +23 -21
- package/templates/alchemy/README.md +17 -0
- package/templates/alchemy/alchemy.run.ts +16 -0
- package/templates/alchemy/package.json +28 -0
- package/templates/alchemy/src/counter.ts +38 -0
- package/templates/alchemy/src/register.ts +26 -0
- package/templates/alchemy/src/resources.ts +8 -0
- package/templates/alchemy/src/worker.ts +29 -0
- package/templates/alchemy/tsconfig.json +22 -0
- package/templates/counter/.env.example +3 -0
- package/templates/counter/README.md +17 -0
- package/templates/counter/package.json +21 -0
- package/templates/counter/src/index.ts +72 -0
- package/templates/counter/tsconfig.json +22 -0
- package/templates/counter/vite.config.ts +6 -0
- package/templates/default/.env.example +3 -0
- package/templates/default/package.json +14 -12
- package/templates/default/src/counter.ts +65 -0
- package/templates/default/src/index.ts +36 -14
- package/templates/default/tsconfig.json +20 -26
- package/templates/default/vite.config.ts +7 -0
- package/templates/rick-and-morty/.env.example +4 -0
- package/templates/rick-and-morty/package.json +15 -12
- package/templates/rick-and-morty/src/commands/search.ts +15 -0
- package/templates/rick-and-morty/src/components/search/character.ts +57 -0
- package/templates/rick-and-morty/src/components/search/index.ts +99 -0
- package/templates/rick-and-morty/src/components/search/pagination.ts +49 -0
- package/templates/rick-and-morty/src/components/search/search-form.ts +60 -0
- package/templates/rick-and-morty/src/components/search/status.ts +22 -0
- package/templates/rick-and-morty/src/index.ts +40 -14
- package/templates/rick-and-morty/src/queries/characters.ts +89 -0
- package/templates/rick-and-morty/tsconfig.json +20 -26
- package/templates/rick-and-morty/vite.config.ts +7 -0
- package/templates/serverless/README.md +17 -0
- package/templates/serverless/package.json +22 -0
- package/templates/serverless/src/counter.ts +39 -0
- package/templates/serverless/src/handler.ts +38 -0
- package/templates/serverless/src/index.ts +78 -0
- package/templates/serverless/src/register.ts +21 -0
- package/templates/serverless/tsconfig.json +22 -0
- package/templates/simple/.env.example +3 -0
- package/templates/simple/package.json +13 -12
- package/templates/simple/src/app.ts +147 -0
- package/templates/simple/src/index.ts +57 -0
- package/templates/simple/tsconfig.json +20 -26
- package/templates/simple/vite.config.ts +6 -0
- package/templates/slack/.env.example +3 -0
- package/templates/slack/README.md +17 -0
- package/templates/slack/package.json +22 -0
- package/templates/slack/src/app.ts +45 -0
- package/templates/slack/src/index.ts +43 -0
- package/templates/slack/tsconfig.json +22 -0
- package/templates/slack/vite.config.ts +6 -0
- package/templates/default/src/commands/counter/counter.tsx +0 -53
- package/templates/default/src/commands/counter/index.ts +0 -7
- package/templates/rick-and-morty/src/commands/rick-and-morty/app.tsx +0 -28
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-display.tsx +0 -40
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-search-modal.tsx +0 -34
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-search.tsx +0 -29
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-select.tsx +0 -36
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/navigation.tsx +0 -58
- package/templates/rick-and-morty/src/commands/rick-and-morty/hooks/character-search-provider.tsx +0 -90
- package/templates/rick-and-morty/src/commands/rick-and-morty/hooks/useCharacters.ts +0 -38
- package/templates/rick-and-morty/src/commands/rick-and-morty/index.ts +0 -21
- package/templates/rick-and-morty/src/commands/rick-and-morty/types.ts +0 -24
- package/templates/simple/src/app.tsx +0 -38
- package/templates/simple/src/index.tsx +0 -33
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { UiSchema } from "effect/ui";
|
|
2
|
+
import * as Discord from "@arona/platform-discord";
|
|
3
|
+
import {
|
|
4
|
+
ActionRow,
|
|
5
|
+
Button,
|
|
6
|
+
Container,
|
|
7
|
+
DiscordGatewayClient,
|
|
8
|
+
Intent,
|
|
9
|
+
SlashCommand,
|
|
10
|
+
Text,
|
|
11
|
+
} from "@arona/platform-discord";
|
|
12
|
+
import { NodeRuntime } from "@effect/platform-node";
|
|
13
|
+
import { Config, Effect, Schema } from "effect";
|
|
14
|
+
|
|
15
|
+
const Clicked = UiSchema.TaggedEnum({ Clicked: {} });
|
|
16
|
+
const CounterProps = Schema.Struct({ start: Schema.optional(Schema.Int) });
|
|
17
|
+
|
|
18
|
+
const Counter = Discord.component({
|
|
19
|
+
name: "Counter",
|
|
20
|
+
props: CounterProps,
|
|
21
|
+
model: Schema.Struct({ count: Schema.Finite }),
|
|
22
|
+
message: Clicked,
|
|
23
|
+
}).make({
|
|
24
|
+
init: ($) => ({ count: $.props.start ?? 0 }),
|
|
25
|
+
update: {
|
|
26
|
+
Clicked: ($) => $.evolve({ count: (count) => count + 1 }),
|
|
27
|
+
},
|
|
28
|
+
view: (h, model) =>
|
|
29
|
+
Container(h, {
|
|
30
|
+
children: [
|
|
31
|
+
Text(h, `# Count: ${model.count}`),
|
|
32
|
+
ActionRow(h, {
|
|
33
|
+
children: [Button(h, { onClick: Clicked.Clicked(), children: ["+1"] })],
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const counter = SlashCommand.make("counter", {
|
|
40
|
+
description: "Increment a counter",
|
|
41
|
+
options: {
|
|
42
|
+
start: SlashCommand.integer({ description: "Starting count" }),
|
|
43
|
+
},
|
|
44
|
+
component: Counter,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const program = Effect.gen(function* () {
|
|
48
|
+
const config = yield* Config.all({
|
|
49
|
+
token: Config.Redacted("DISCORD_APP_TOKEN"),
|
|
50
|
+
clientId: Config.String("DISCORD_APP_ID"),
|
|
51
|
+
devGuildId: Config.option(Config.String("DISCORD_DEV_GUILD_ID")),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return yield* Effect.gen(function* () {
|
|
55
|
+
const client = yield* DiscordGatewayClient;
|
|
56
|
+
const user = yield* client.login;
|
|
57
|
+
yield* Effect.log(`Logged in as ${user.username}`);
|
|
58
|
+
return yield* Effect.never;
|
|
59
|
+
}).pipe(
|
|
60
|
+
Effect.provide(
|
|
61
|
+
DiscordGatewayClient.layerEphemeral({
|
|
62
|
+
token: config.token,
|
|
63
|
+
clientId: config.clientId,
|
|
64
|
+
devGuildId: config.devGuildId,
|
|
65
|
+
intents: [Intent.Guilds],
|
|
66
|
+
commands: [counter],
|
|
67
|
+
}),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
NodeRuntime.runMain(program);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"ESNext"
|
|
5
|
+
],
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"exactOptionalPropertyTypes": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arona-ex/default",
|
|
3
|
+
"private": true,
|
|
3
4
|
"description": "A basic Arona app setup with essential features",
|
|
4
|
-
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"module": "index.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"dev": "
|
|
9
|
-
"build": "
|
|
10
|
-
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"@types/bun": "latest"
|
|
13
|
-
},
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"typescript": "^5.8.3"
|
|
8
|
+
"dev": "vp build --watch --mode development",
|
|
9
|
+
"build": "vp build",
|
|
10
|
+
"check:types": "effect-tsgo tsrs --noEmit"
|
|
16
11
|
},
|
|
17
12
|
"dependencies": {
|
|
18
|
-
"@arona/
|
|
19
|
-
"@
|
|
13
|
+
"@arona/core": "0.0.2",
|
|
14
|
+
"@arona/devtools": "0.0.2",
|
|
15
|
+
"@arona/platform-discord": "0.0.2",
|
|
16
|
+
"effect": "4.2.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^26.6.10",
|
|
20
|
+
"typescript": "^5.8.3",
|
|
21
|
+
"vite-plus": "1.8.0"
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { UiSchema } from "effect/ui";
|
|
2
|
+
import {
|
|
3
|
+
ActionRow,
|
|
4
|
+
Button,
|
|
5
|
+
Canvas,
|
|
6
|
+
Container,
|
|
7
|
+
Gallery,
|
|
8
|
+
SlashCommand,
|
|
9
|
+
Text,
|
|
10
|
+
} from "@arona/platform-discord";
|
|
11
|
+
import * as Discord from "@arona/platform-discord";
|
|
12
|
+
import { Schema } from "effect";
|
|
13
|
+
|
|
14
|
+
const CounterMessage = UiSchema.TaggedEnum({
|
|
15
|
+
ClickedIncrement: {},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/** Draws the current count as an SVG that the host renders to PNG. */
|
|
19
|
+
const counterSvg = (count: number) => `
|
|
20
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="96">
|
|
21
|
+
<rect width="256" height="96" rx="12" fill="#111827" />
|
|
22
|
+
<text x="128" y="58" text-anchor="middle" fill="#f9fafb"
|
|
23
|
+
font-family="sans-serif" font-size="32" font-weight="700">${count}</text>
|
|
24
|
+
</svg>`;
|
|
25
|
+
|
|
26
|
+
export const Counter = Discord.component({
|
|
27
|
+
name: "Counter",
|
|
28
|
+
model: Schema.Struct({ count: Schema.Finite }),
|
|
29
|
+
message: CounterMessage,
|
|
30
|
+
}).make({
|
|
31
|
+
init: () => ({ count: 0 }),
|
|
32
|
+
update: {
|
|
33
|
+
ClickedIncrement: ($) => $.evolve({ count: (count) => count + 1 }),
|
|
34
|
+
},
|
|
35
|
+
view: (h, model) =>
|
|
36
|
+
Container(h, {
|
|
37
|
+
children: [
|
|
38
|
+
Text(h, `# Step: \`${model.count}\``),
|
|
39
|
+
ActionRow(h, {
|
|
40
|
+
children: [
|
|
41
|
+
Button(h, {
|
|
42
|
+
style: "Primary",
|
|
43
|
+
onClick: CounterMessage.ClickedIncrement(),
|
|
44
|
+
children: ["+"],
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
47
|
+
}),
|
|
48
|
+
Gallery(h, {
|
|
49
|
+
children: [
|
|
50
|
+
Canvas(h, {
|
|
51
|
+
svg: counterSvg(model.count),
|
|
52
|
+
width: 256,
|
|
53
|
+
height: 96,
|
|
54
|
+
name: "counter.png",
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const counter = SlashCommand.make("counter", {
|
|
63
|
+
description: "Counting example command",
|
|
64
|
+
component: Counter,
|
|
65
|
+
});
|
|
@@ -1,17 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Telemetry } from "@arona/core";
|
|
2
|
+
import { layerFromEnv } from "@arona/devtools";
|
|
3
|
+
import { DiscordGatewayClient, Intent } from "@arona/platform-discord";
|
|
4
|
+
import { NodeRuntime } from "@effect/platform-node";
|
|
5
|
+
import { Config, Effect, Layer } from "effect";
|
|
6
|
+
import { counter } from "./counter";
|
|
4
7
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})
|
|
8
|
+
const program = Effect.gen(function* () {
|
|
9
|
+
const config = yield* Config.all({
|
|
10
|
+
token: Config.Redacted("DISCORD_APP_TOKEN"),
|
|
11
|
+
clientId: Config.String("DISCORD_APP_ID"),
|
|
12
|
+
devGuildId: Config.option(Config.String("DISCORD_DEV_GUILD_ID")),
|
|
13
|
+
});
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
+
return yield* Effect.gen(function* () {
|
|
16
|
+
const client = yield* DiscordGatewayClient;
|
|
15
17
|
|
|
16
|
-
client.
|
|
17
|
-
|
|
18
|
+
const user = yield* client.login;
|
|
19
|
+
yield* Effect.log(`🚀 Logged in as ${user.username}`);
|
|
20
|
+
return yield* Effect.never;
|
|
21
|
+
}).pipe(
|
|
22
|
+
Effect.provide(
|
|
23
|
+
DiscordGatewayClient.layerEphemeral({
|
|
24
|
+
token: config.token,
|
|
25
|
+
clientId: config.clientId,
|
|
26
|
+
devGuildId: config.devGuildId,
|
|
27
|
+
intents: [Intent.Guilds],
|
|
28
|
+
commands: [counter],
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const telemetry =
|
|
35
|
+
process.env.NODE_ENV === "production"
|
|
36
|
+
? Telemetry.layerFromEnv
|
|
37
|
+
: Telemetry.layer({ console: true });
|
|
38
|
+
|
|
39
|
+
NodeRuntime.runMain(program.pipe(Effect.provide(Layer.merge(telemetry, layerFromEnv()))));
|
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Some stricter flags (disabled by default)
|
|
24
|
-
"noUnusedLocals": false,
|
|
25
|
-
"noUnusedParameters": false,
|
|
26
|
-
"noPropertyAccessFromIndexSignature": false
|
|
27
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"ESNext"
|
|
5
|
+
],
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"exactOptionalPropertyTypes": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*"
|
|
21
|
+
]
|
|
28
22
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Arona from "@arona/core/vite";
|
|
2
|
+
import { DevToolsVite } from "@arona/devtools/node";
|
|
3
|
+
import { defineConfig } from "vite-plus";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [Arona.plugin({ entry: "./src/index.ts" }), DevToolsVite.plugin({ dispatch: true })],
|
|
7
|
+
});
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arona-ex/rick-and-morty",
|
|
3
|
+
"private": true,
|
|
3
4
|
"description": "An example app that demonstrates API integration with the Rick and Morty API",
|
|
4
|
-
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"module": "index.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"dev": "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"@types/bun": "latest"
|
|
12
|
-
},
|
|
13
|
-
"peerDependencies": {
|
|
14
|
-
"typescript": "^5.8.3"
|
|
8
|
+
"dev": "vp build --watch --mode development",
|
|
9
|
+
"build": "vp build",
|
|
10
|
+
"check:types": "effect-tsgo tsrs --noEmit"
|
|
15
11
|
},
|
|
16
12
|
"dependencies": {
|
|
17
|
-
"@arona/
|
|
18
|
-
"@
|
|
19
|
-
"discord
|
|
13
|
+
"@arona/core": "0.0.2",
|
|
14
|
+
"@arona/devtools": "0.0.2",
|
|
15
|
+
"@arona/platform-discord": "0.0.2",
|
|
16
|
+
"@arona/store-sqlite": "0.0.2",
|
|
17
|
+
"effect": "4.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^26.6.10",
|
|
21
|
+
"typescript": "^5.8.3",
|
|
22
|
+
"vite-plus": "1.8.0"
|
|
20
23
|
}
|
|
21
24
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SlashCommand } from "@arona/platform-discord";
|
|
2
|
+
import { Search } from "../components/search";
|
|
3
|
+
import { SearchCharactersLive } from "../queries/characters";
|
|
4
|
+
|
|
5
|
+
/** `/search` opens the character browser. */
|
|
6
|
+
export const search = SlashCommand.provide(
|
|
7
|
+
SlashCommand.make("search", {
|
|
8
|
+
description: "Search Rick and Morty API",
|
|
9
|
+
options: {
|
|
10
|
+
query: SlashCommand.string({ description: "Search query" }),
|
|
11
|
+
},
|
|
12
|
+
component: Search,
|
|
13
|
+
}),
|
|
14
|
+
SearchCharactersLive,
|
|
15
|
+
);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActionRow,
|
|
3
|
+
Container,
|
|
4
|
+
Option,
|
|
5
|
+
Section,
|
|
6
|
+
Select,
|
|
7
|
+
Text,
|
|
8
|
+
Thumbnail,
|
|
9
|
+
type H,
|
|
10
|
+
} from "@arona/platform-discord";
|
|
11
|
+
import type { Character } from "../../queries/characters";
|
|
12
|
+
import { statusColor, statusEmoji } from "./status";
|
|
13
|
+
|
|
14
|
+
/** The selected character, or the empty state when the page has none. */
|
|
15
|
+
export const CharacterCard = <Msg>(h: H<Msg>, character: Character | undefined) =>
|
|
16
|
+
character
|
|
17
|
+
? Container(h, {
|
|
18
|
+
props: { accentColor: statusColor(character.status) },
|
|
19
|
+
children: [
|
|
20
|
+
Section(h, {
|
|
21
|
+
accessory: Thumbnail(h, { url: character.image }),
|
|
22
|
+
children: [Text(h, `${character.name} \`${character.species}\``)],
|
|
23
|
+
}),
|
|
24
|
+
Text(h, character.status),
|
|
25
|
+
],
|
|
26
|
+
})
|
|
27
|
+
: Container(h, { children: [Text(h, "No character selected")] });
|
|
28
|
+
|
|
29
|
+
/** Picker for the characters on the current page. Omitted when the page is empty. */
|
|
30
|
+
export const CharacterSelect = <Msg>(
|
|
31
|
+
h: H<Msg>,
|
|
32
|
+
options: {
|
|
33
|
+
readonly characters: ReadonlyArray<Character>;
|
|
34
|
+
readonly selectedId: number | undefined;
|
|
35
|
+
readonly disabled: boolean;
|
|
36
|
+
readonly onSelect: (id: string) => Msg;
|
|
37
|
+
},
|
|
38
|
+
) =>
|
|
39
|
+
options.characters.length === 0
|
|
40
|
+
? false
|
|
41
|
+
: ActionRow(h, {
|
|
42
|
+
children: [
|
|
43
|
+
Select(h, {
|
|
44
|
+
disabled: options.disabled,
|
|
45
|
+
onChange: (interaction) => options.onSelect(interaction.values[0] ?? ""),
|
|
46
|
+
children: options.characters.map((entry) =>
|
|
47
|
+
Option(h, {
|
|
48
|
+
value: String(entry.id),
|
|
49
|
+
label: entry.name,
|
|
50
|
+
description: `${entry.species} - ${entry.status}`,
|
|
51
|
+
selected: entry.id === options.selectedId,
|
|
52
|
+
emoji: statusEmoji(entry.status),
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { UiSchema } from "effect/ui";
|
|
2
|
+
import { Fragment, component } from "@arona/platform-discord";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
import { AsyncResult } from "effect/reactivity";
|
|
5
|
+
import { SearchCharacters, type PageMetadata } from "../../queries/characters";
|
|
6
|
+
import { CharacterCard, CharacterSelect } from "./character";
|
|
7
|
+
import { Pagination } from "./pagination";
|
|
8
|
+
import { SearchModal, SearchSection } from "./search-form";
|
|
9
|
+
|
|
10
|
+
const SearchMessage = UiSchema.TaggedEnum({
|
|
11
|
+
ClickedSearch: {},
|
|
12
|
+
SubmittedSearch: { search: Schema.String },
|
|
13
|
+
ChangedSelection: { id: Schema.String },
|
|
14
|
+
ChangedPage: { page: Schema.Finite },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const SearchProps = Schema.Struct({ query: Schema.optional(Schema.String) });
|
|
18
|
+
|
|
19
|
+
/** Character browser mounted by the `/search` command. */
|
|
20
|
+
export const Search = component({
|
|
21
|
+
name: "Search",
|
|
22
|
+
props: SearchProps,
|
|
23
|
+
model: Schema.Struct({
|
|
24
|
+
search: Schema.String,
|
|
25
|
+
page: Schema.Finite,
|
|
26
|
+
selected: Schema.String,
|
|
27
|
+
modalOpen: Schema.Boolean,
|
|
28
|
+
}),
|
|
29
|
+
message: SearchMessage,
|
|
30
|
+
queries: {
|
|
31
|
+
characters: {
|
|
32
|
+
query: SearchCharacters,
|
|
33
|
+
args: ({ model }) => ({ query: model.search, page: model.page }),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}).make({
|
|
37
|
+
init: ($) => ({
|
|
38
|
+
search: $.props.query ?? "",
|
|
39
|
+
page: 1,
|
|
40
|
+
selected: "",
|
|
41
|
+
modalOpen: false,
|
|
42
|
+
}),
|
|
43
|
+
update: {
|
|
44
|
+
ClickedSearch: ($) => $.evolve({ modalOpen: true }),
|
|
45
|
+
SubmittedSearch: ($, message) =>
|
|
46
|
+
$.evolve({
|
|
47
|
+
search: message.search,
|
|
48
|
+
page: 1,
|
|
49
|
+
selected: "",
|
|
50
|
+
modalOpen: false,
|
|
51
|
+
}),
|
|
52
|
+
ChangedSelection: ($, message) => $.evolve({ selected: message.id }),
|
|
53
|
+
ChangedPage: ($, message) => $.evolve({ page: Math.max(1, message.page), selected: "" }),
|
|
54
|
+
},
|
|
55
|
+
view: (h, model) => {
|
|
56
|
+
const result = h.queries.characters;
|
|
57
|
+
const loaded = AsyncResult.isSuccess(result) ? result.value : undefined;
|
|
58
|
+
const characters = loaded?.characters ?? [];
|
|
59
|
+
const pageMetadata: PageMetadata | null = loaded?.pageMetadata ?? null;
|
|
60
|
+
const isLoading = AsyncResult.isInitial(result) || AsyncResult.isWaiting(result);
|
|
61
|
+
const pages = pageMetadata?.pages ?? 0;
|
|
62
|
+
const canNavigate = !isLoading && pageMetadata !== null && pages > 0;
|
|
63
|
+
const character =
|
|
64
|
+
characters.find((entry) => String(entry.id) === model.selected) ?? characters[0];
|
|
65
|
+
const previousDisabled = !canNavigate || model.page <= 1;
|
|
66
|
+
const nextDisabled =
|
|
67
|
+
!canNavigate || (pageMetadata !== null && pageMetadata.pages <= model.page);
|
|
68
|
+
|
|
69
|
+
return Fragment(h, {
|
|
70
|
+
children: [
|
|
71
|
+
SearchSection(h, {
|
|
72
|
+
query: model.search,
|
|
73
|
+
disabled: isLoading,
|
|
74
|
+
onSearch: SearchMessage.ClickedSearch(),
|
|
75
|
+
}),
|
|
76
|
+
CharacterCard(h, character),
|
|
77
|
+
CharacterSelect(h, {
|
|
78
|
+
characters,
|
|
79
|
+
selectedId: character?.id,
|
|
80
|
+
disabled: isLoading,
|
|
81
|
+
onSelect: (id) => SearchMessage.ChangedSelection({ id }),
|
|
82
|
+
}),
|
|
83
|
+
Pagination(h, {
|
|
84
|
+
page: model.page,
|
|
85
|
+
pageCount: pageMetadata?.pages,
|
|
86
|
+
previousDisabled,
|
|
87
|
+
nextDisabled,
|
|
88
|
+
onPage: (page) => SearchMessage.ChangedPage({ page }),
|
|
89
|
+
}),
|
|
90
|
+
model.modalOpen
|
|
91
|
+
? SearchModal(h, {
|
|
92
|
+
query: model.search,
|
|
93
|
+
onSubmit: (search) => SearchMessage.SubmittedSearch({ search }),
|
|
94
|
+
})
|
|
95
|
+
: false,
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ActionRow, Button, type H } from "@arona/platform-discord";
|
|
2
|
+
|
|
3
|
+
/** First, previous, next, and last page controls. */
|
|
4
|
+
export const Pagination = <Msg>(
|
|
5
|
+
h: H<Msg>,
|
|
6
|
+
options: {
|
|
7
|
+
readonly page: number;
|
|
8
|
+
readonly pageCount: number | undefined;
|
|
9
|
+
readonly previousDisabled: boolean;
|
|
10
|
+
readonly nextDisabled: boolean;
|
|
11
|
+
readonly onPage: (page: number) => Msg;
|
|
12
|
+
},
|
|
13
|
+
) => {
|
|
14
|
+
const pageLabel = `Page ${options.page}${options.pageCount === undefined ? "" : ` / ${options.pageCount}`}`;
|
|
15
|
+
const lastPage = options.pageCount ?? 1;
|
|
16
|
+
return ActionRow(h, {
|
|
17
|
+
children: [
|
|
18
|
+
Button(h, {
|
|
19
|
+
style: "Secondary",
|
|
20
|
+
onClick: () => options.onPage(1),
|
|
21
|
+
disabled: options.previousDisabled,
|
|
22
|
+
children: ["<<"],
|
|
23
|
+
}),
|
|
24
|
+
Button(h, {
|
|
25
|
+
style: "Primary",
|
|
26
|
+
onClick: () => options.onPage(options.page - 1),
|
|
27
|
+
disabled: options.previousDisabled,
|
|
28
|
+
children: ["<"],
|
|
29
|
+
}),
|
|
30
|
+
Button(h, {
|
|
31
|
+
style: "Secondary",
|
|
32
|
+
disabled: true,
|
|
33
|
+
children: [pageLabel],
|
|
34
|
+
}),
|
|
35
|
+
Button(h, {
|
|
36
|
+
style: "Primary",
|
|
37
|
+
onClick: () => options.onPage(options.page + 1),
|
|
38
|
+
disabled: options.nextDisabled,
|
|
39
|
+
children: [">"],
|
|
40
|
+
}),
|
|
41
|
+
Button(h, {
|
|
42
|
+
style: "Secondary",
|
|
43
|
+
onClick: () => options.onPage(lastPage),
|
|
44
|
+
disabled: options.nextDisabled,
|
|
45
|
+
children: [">>"],
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { View } from "effect/ui";
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Label,
|
|
5
|
+
Modal,
|
|
6
|
+
Section,
|
|
7
|
+
Text,
|
|
8
|
+
TextInput,
|
|
9
|
+
type ButtonInteraction,
|
|
10
|
+
type H,
|
|
11
|
+
} from "@arona/platform-discord";
|
|
12
|
+
|
|
13
|
+
/** Current query and the button that opens the search modal. */
|
|
14
|
+
export const SearchSection = <Msg>(
|
|
15
|
+
h: H<Msg>,
|
|
16
|
+
options: {
|
|
17
|
+
readonly query: string;
|
|
18
|
+
readonly disabled: boolean;
|
|
19
|
+
readonly onSearch: View.Handler<Msg, ButtonInteraction>;
|
|
20
|
+
},
|
|
21
|
+
) =>
|
|
22
|
+
Section(h, {
|
|
23
|
+
accessory: Button(h, {
|
|
24
|
+
onClick: options.onSearch,
|
|
25
|
+
disabled: options.disabled,
|
|
26
|
+
children: ["Search"],
|
|
27
|
+
}),
|
|
28
|
+
children: [
|
|
29
|
+
Text(h, "### Search Character"),
|
|
30
|
+
options.query ? Text(h, `Current search: ${options.query}`) : Text(h, "No search term set."),
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/** Name field submitted back to the search component. */
|
|
35
|
+
export const SearchModal = <Msg>(
|
|
36
|
+
h: H<Msg>,
|
|
37
|
+
options: {
|
|
38
|
+
readonly query: string;
|
|
39
|
+
readonly onSubmit: (query: string) => Msg;
|
|
40
|
+
},
|
|
41
|
+
) =>
|
|
42
|
+
Modal(h, {
|
|
43
|
+
title: "Search Character",
|
|
44
|
+
onSubmit: (payload) => options.onSubmit(payload.values.search ?? ""),
|
|
45
|
+
children: [
|
|
46
|
+
Label(h, {
|
|
47
|
+
label: "Search for a character by name",
|
|
48
|
+
children: [
|
|
49
|
+
TextInput(h, {
|
|
50
|
+
name: "search",
|
|
51
|
+
style: "Short",
|
|
52
|
+
value: options.query,
|
|
53
|
+
placeholder: "e.g. Rick Sanchez, Morty Smith, etc.",
|
|
54
|
+
minLength: 1,
|
|
55
|
+
maxLength: 50,
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AccentColor } from "@arona/platform-discord";
|
|
2
|
+
|
|
3
|
+
const statusEmojis: Record<string, string> = {
|
|
4
|
+
Alive: "🙂",
|
|
5
|
+
Dead: "💀",
|
|
6
|
+
unknown: "❓",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Emoji shown beside a character in the picker. */
|
|
10
|
+
export const statusEmoji = (status: string): string => statusEmojis[status] ?? "❔";
|
|
11
|
+
|
|
12
|
+
/** Container accent for a character's life status. */
|
|
13
|
+
export const statusColor = (status: string): AccentColor => {
|
|
14
|
+
switch (status) {
|
|
15
|
+
case "Alive":
|
|
16
|
+
return "Green";
|
|
17
|
+
case "Dead":
|
|
18
|
+
return "Red";
|
|
19
|
+
default:
|
|
20
|
+
return "Default";
|
|
21
|
+
}
|
|
22
|
+
};
|