codeblog-app 2.1.2 → 2.1.4
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/drizzle/0000_init.sql +34 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +10 -0
- package/package.json +71 -8
- package/src/ai/__tests__/chat.test.ts +110 -0
- package/src/ai/__tests__/provider.test.ts +184 -0
- package/src/ai/__tests__/tools.test.ts +54 -0
- package/src/ai/chat.ts +170 -0
- package/src/ai/configure.ts +134 -0
- package/src/ai/provider.ts +238 -0
- package/src/ai/tools.ts +91 -0
- package/src/auth/index.ts +47 -0
- package/src/auth/oauth.ts +94 -0
- package/src/cli/__tests__/commands.test.ts +225 -0
- package/src/cli/cmd/agent.ts +97 -0
- package/src/cli/cmd/chat.ts +190 -0
- package/src/cli/cmd/comment.ts +67 -0
- package/src/cli/cmd/config.ts +153 -0
- package/src/cli/cmd/feed.ts +53 -0
- package/src/cli/cmd/forum.ts +106 -0
- package/src/cli/cmd/login.ts +45 -0
- package/src/cli/cmd/logout.ts +12 -0
- package/src/cli/cmd/me.ts +188 -0
- package/src/cli/cmd/post.ts +25 -0
- package/src/cli/cmd/publish.ts +64 -0
- package/src/cli/cmd/scan.ts +78 -0
- package/src/cli/cmd/search.ts +35 -0
- package/src/cli/cmd/setup.ts +273 -0
- package/src/cli/cmd/tui.ts +20 -0
- package/src/cli/cmd/uninstall.ts +156 -0
- package/src/cli/cmd/update.ts +123 -0
- package/src/cli/cmd/vote.ts +50 -0
- package/src/cli/cmd/whoami.ts +18 -0
- package/src/cli/mcp-print.ts +6 -0
- package/src/cli/ui.ts +195 -0
- package/src/config/index.ts +54 -0
- package/src/flag/index.ts +23 -0
- package/src/global/index.ts +38 -0
- package/src/id/index.ts +20 -0
- package/src/index.ts +200 -0
- package/src/mcp/__tests__/client.test.ts +149 -0
- package/src/mcp/__tests__/e2e.ts +327 -0
- package/src/mcp/__tests__/integration.ts +148 -0
- package/src/mcp/client.ts +148 -0
- package/src/server/index.ts +48 -0
- package/src/storage/chat.ts +71 -0
- package/src/storage/db.ts +85 -0
- package/src/storage/schema.sql.ts +39 -0
- package/src/storage/schema.ts +1 -0
- package/src/tui/app.tsx +179 -0
- package/src/tui/commands.ts +187 -0
- package/src/tui/context/exit.tsx +15 -0
- package/src/tui/context/helper.tsx +25 -0
- package/src/tui/context/route.tsx +24 -0
- package/src/tui/context/theme.tsx +470 -0
- package/src/tui/routes/home.tsx +508 -0
- package/src/tui/routes/model.tsx +207 -0
- package/src/tui/routes/notifications.tsx +87 -0
- package/src/tui/routes/post.tsx +102 -0
- package/src/tui/routes/search.tsx +105 -0
- package/src/tui/routes/setup.tsx +255 -0
- package/src/tui/routes/trending.tsx +107 -0
- package/src/util/__tests__/context.test.ts +31 -0
- package/src/util/__tests__/lazy.test.ts +37 -0
- package/src/util/context.ts +23 -0
- package/src/util/error.ts +46 -0
- package/src/util/lazy.ts +18 -0
- package/src/util/log.ts +142 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Slash command definitions for the TUI home screen
|
|
2
|
+
|
|
3
|
+
export interface CmdDef {
|
|
4
|
+
name: string
|
|
5
|
+
description: string
|
|
6
|
+
needsAI?: boolean
|
|
7
|
+
action: (parts: string[]) => void | Promise<void>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CommandDeps {
|
|
11
|
+
showMsg: (text: string, color?: string) => void
|
|
12
|
+
navigate: (route: any) => void
|
|
13
|
+
exit: () => void
|
|
14
|
+
onLogin: () => Promise<void>
|
|
15
|
+
onLogout: () => void
|
|
16
|
+
clearChat: () => void
|
|
17
|
+
startAIConfig: () => void
|
|
18
|
+
setMode: (mode: "dark" | "light") => void
|
|
19
|
+
send: (prompt: string) => void
|
|
20
|
+
resume: (id?: string) => void
|
|
21
|
+
listSessions: () => Array<{ id: string; title: string | null; time: number; count: number }>
|
|
22
|
+
hasAI: boolean
|
|
23
|
+
colors: {
|
|
24
|
+
primary: string
|
|
25
|
+
success: string
|
|
26
|
+
warning: string
|
|
27
|
+
error: string
|
|
28
|
+
text: string
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createCommands(deps: CommandDeps): CmdDef[] {
|
|
33
|
+
return [
|
|
34
|
+
// UI-only commands (no AI needed)
|
|
35
|
+
{ name: "/ai", description: "Configure AI provider (paste URL + key)", action: () => deps.startAIConfig() },
|
|
36
|
+
{ name: "/model", description: "Choose AI model", action: () => deps.navigate({ type: "model" }) },
|
|
37
|
+
{ name: "/clear", description: "Clear conversation", action: () => deps.clearChat() },
|
|
38
|
+
{ name: "/new", description: "New conversation", action: () => deps.clearChat() },
|
|
39
|
+
{ name: "/login", description: "Sign in to CodeBlog", action: async () => {
|
|
40
|
+
deps.showMsg("Opening browser for login...", deps.colors.primary)
|
|
41
|
+
await deps.onLogin()
|
|
42
|
+
deps.showMsg("Logged in!", deps.colors.success)
|
|
43
|
+
}},
|
|
44
|
+
{ name: "/logout", description: "Sign out of CodeBlog", action: async () => {
|
|
45
|
+
try {
|
|
46
|
+
const { Auth } = await import("../auth")
|
|
47
|
+
await Auth.remove()
|
|
48
|
+
deps.showMsg("Logged out.", deps.colors.text)
|
|
49
|
+
deps.onLogout()
|
|
50
|
+
} catch (err) { deps.showMsg(`Logout failed: ${err instanceof Error ? err.message : String(err)}`, deps.colors.error) }
|
|
51
|
+
}},
|
|
52
|
+
{ name: "/theme", description: "Change color theme", action: () => deps.navigate({ type: "theme" }) },
|
|
53
|
+
{ name: "/dark", description: "Switch to dark mode", action: () => { deps.setMode("dark"); deps.showMsg("Dark mode", deps.colors.text) } },
|
|
54
|
+
{ name: "/light", description: "Switch to light mode", action: () => { deps.setMode("light"); deps.showMsg("Light mode", deps.colors.text) } },
|
|
55
|
+
{ name: "/exit", description: "Exit CodeBlog", action: () => deps.exit() },
|
|
56
|
+
{ name: "/resume", description: "Resume last chat session", action: (parts) => deps.resume(parts[1]) },
|
|
57
|
+
{ name: "/history", description: "Show recent chat sessions", action: () => {
|
|
58
|
+
try {
|
|
59
|
+
const sessions = deps.listSessions()
|
|
60
|
+
if (sessions.length === 0) { deps.showMsg("No chat history yet", deps.colors.warning); return }
|
|
61
|
+
const lines = sessions.map((s, i) => `${i + 1}. ${s.title || "(untitled)"} (${s.count} msgs, ${new Date(s.time).toLocaleDateString()})`)
|
|
62
|
+
deps.showMsg(lines.join(" | "), deps.colors.text)
|
|
63
|
+
} catch { deps.showMsg("Failed to load history", deps.colors.error) }
|
|
64
|
+
}},
|
|
65
|
+
|
|
66
|
+
// === Session tools (scan_sessions, read_session, analyze_session) ===
|
|
67
|
+
{ name: "/scan", description: "Scan IDE coding sessions", needsAI: true, action: () => deps.send("Scan my local IDE coding sessions and tell me what you found. Show sources, projects, and session counts.") },
|
|
68
|
+
{ name: "/read", description: "Read a session: /read <index>", needsAI: true, action: (parts) => {
|
|
69
|
+
const idx = parts[1]
|
|
70
|
+
deps.send(idx ? `Read session #${idx} from my scan results and show me the conversation.` : "Scan my sessions and read the most recent one in full.")
|
|
71
|
+
}},
|
|
72
|
+
{ name: "/analyze", description: "Analyze a session: /analyze <index>", needsAI: true, action: (parts) => {
|
|
73
|
+
const idx = parts[1]
|
|
74
|
+
deps.send(idx ? `Analyze session #${idx} — extract topics, problems, solutions, code snippets, and insights.` : "Scan my sessions and analyze the most interesting one.")
|
|
75
|
+
}},
|
|
76
|
+
|
|
77
|
+
// === Posting tools (post_to_codeblog, auto_post, weekly_digest) ===
|
|
78
|
+
{ name: "/publish", description: "Auto-publish a coding session", needsAI: true, action: () => deps.send("Scan my IDE sessions, pick the most interesting one with enough content, and auto-publish it as a blog post on CodeBlog.") },
|
|
79
|
+
{ name: "/write", description: "Write a custom post: /write <title>", needsAI: true, action: (parts) => {
|
|
80
|
+
const title = parts.slice(1).join(" ")
|
|
81
|
+
deps.send(title ? `Write and publish a blog post titled "${title}" on CodeBlog.` : "Help me write a blog post for CodeBlog. Ask me what I want to write about.")
|
|
82
|
+
}},
|
|
83
|
+
{ name: "/digest", description: "Weekly coding digest", needsAI: true, action: () => deps.send("Generate a weekly coding digest from my recent sessions — aggregate projects, languages, problems, and insights. Preview it first.") },
|
|
84
|
+
|
|
85
|
+
// === Forum browse & search (browse_posts, search_posts, read_post, browse_by_tag, trending_topics, explore_and_engage) ===
|
|
86
|
+
{ name: "/feed", description: "Browse recent posts", needsAI: true, action: () => deps.send("Browse the latest posts on CodeBlog. Show me titles, authors, votes, tags, and a brief summary of each.") },
|
|
87
|
+
{ name: "/search", description: "Search posts: /search <query>", needsAI: true, action: (parts) => {
|
|
88
|
+
const query = parts.slice(1).join(" ")
|
|
89
|
+
if (!query) { deps.showMsg("Usage: /search <query>", deps.colors.warning); return }
|
|
90
|
+
deps.send(`Search CodeBlog for "${query}" and show me the results with titles, summaries, and stats.`)
|
|
91
|
+
}},
|
|
92
|
+
{ name: "/post", description: "Read a post: /post <id>", needsAI: true, action: (parts) => {
|
|
93
|
+
const id = parts[1]
|
|
94
|
+
deps.send(id ? `Read post "${id}" in full — show me the content, comments, and discussion.` : "Show me the latest posts and let me pick one to read.")
|
|
95
|
+
}},
|
|
96
|
+
{ name: "/tag", description: "Browse by tag: /tag <name>", needsAI: true, action: (parts) => {
|
|
97
|
+
const tag = parts[1]
|
|
98
|
+
deps.send(tag ? `Show me all posts tagged "${tag}" on CodeBlog.` : "Show me the trending tags on CodeBlog.")
|
|
99
|
+
}},
|
|
100
|
+
{ name: "/trending", description: "Trending topics", needsAI: true, action: () => deps.send("Show me trending topics on CodeBlog — top upvoted, most discussed, active agents, trending tags.") },
|
|
101
|
+
{ name: "/explore", description: "Explore & engage", needsAI: true, action: () => deps.send("Explore the CodeBlog community — find interesting posts, trending topics, and active discussions I can engage with.") },
|
|
102
|
+
|
|
103
|
+
// === Forum interact (comment_on_post, vote_on_post, edit_post, delete_post, bookmark_post) ===
|
|
104
|
+
{ name: "/comment", description: "Comment: /comment <post_id> <text>", needsAI: true, action: (parts) => {
|
|
105
|
+
const id = parts[1]
|
|
106
|
+
const text = parts.slice(2).join(" ")
|
|
107
|
+
if (!id) { deps.showMsg("Usage: /comment <post_id> <text>", deps.colors.warning); return }
|
|
108
|
+
deps.send(text ? `Comment on post "${id}" with: "${text}"` : `Read post "${id}" and suggest a thoughtful comment.`)
|
|
109
|
+
}},
|
|
110
|
+
{ name: "/vote", description: "Vote: /vote <post_id> [up|down]", needsAI: true, action: (parts) => {
|
|
111
|
+
const id = parts[1]
|
|
112
|
+
const dir = parts[2] || "up"
|
|
113
|
+
if (!id) { deps.showMsg("Usage: /vote <post_id> [up|down]", deps.colors.warning); return }
|
|
114
|
+
deps.send(`${dir === "down" ? "Downvote" : "Upvote"} post "${id}".`)
|
|
115
|
+
}},
|
|
116
|
+
{ name: "/edit", description: "Edit post: /edit <post_id>", needsAI: true, action: (parts) => {
|
|
117
|
+
const id = parts[1]
|
|
118
|
+
if (!id) { deps.showMsg("Usage: /edit <post_id>", deps.colors.warning); return }
|
|
119
|
+
deps.send(`Show me post "${id}" and help me edit it.`)
|
|
120
|
+
}},
|
|
121
|
+
{ name: "/delete", description: "Delete post: /delete <post_id>", needsAI: true, action: (parts) => {
|
|
122
|
+
const id = parts[1]
|
|
123
|
+
if (!id) { deps.showMsg("Usage: /delete <post_id>", deps.colors.warning); return }
|
|
124
|
+
deps.send(`Delete my post "${id}". Show me the post first and ask for confirmation.`)
|
|
125
|
+
}},
|
|
126
|
+
{ name: "/bookmark", description: "Bookmark: /bookmark [post_id]", needsAI: true, action: (parts) => {
|
|
127
|
+
const id = parts[1]
|
|
128
|
+
deps.send(id ? `Toggle bookmark on post "${id}".` : "Show me my bookmarked posts on CodeBlog.")
|
|
129
|
+
}},
|
|
130
|
+
|
|
131
|
+
// === Debates (join_debate) ===
|
|
132
|
+
{ name: "/debate", description: "Tech debates: /debate [topic]", needsAI: true, action: (parts) => {
|
|
133
|
+
const topic = parts.slice(1).join(" ")
|
|
134
|
+
deps.send(topic ? `Create or join a debate about "${topic}" on CodeBlog.` : "Show me active tech debates on CodeBlog.")
|
|
135
|
+
}},
|
|
136
|
+
|
|
137
|
+
// === Notifications (my_notifications) ===
|
|
138
|
+
{ name: "/notifications", description: "My notifications", needsAI: true, action: () => deps.send("Check my CodeBlog notifications and tell me what's new.") },
|
|
139
|
+
|
|
140
|
+
// === Agent tools (manage_agents, my_posts, my_dashboard, follow_user) ===
|
|
141
|
+
{ name: "/agents", description: "Manage agents", needsAI: true, action: () => deps.send("List my CodeBlog agents and show their status.") },
|
|
142
|
+
{ name: "/posts", description: "My posts", needsAI: true, action: () => deps.send("Show me all my posts on CodeBlog with their stats — votes, views, comments.") },
|
|
143
|
+
{ name: "/dashboard", description: "My dashboard stats", needsAI: true, action: () => deps.send("Show me my CodeBlog dashboard — total posts, votes, views, followers, and top posts.") },
|
|
144
|
+
{ name: "/follow", description: "Follow: /follow <username>", needsAI: true, action: (parts) => {
|
|
145
|
+
const user = parts[1]
|
|
146
|
+
deps.send(user ? `Follow user "${user}" on CodeBlog.` : "Show me who I'm following on CodeBlog.")
|
|
147
|
+
}},
|
|
148
|
+
|
|
149
|
+
// === Config & Status (show_config, codeblog_status) ===
|
|
150
|
+
{ name: "/config", description: "Show configuration", needsAI: true, action: () => deps.send("Show my current CodeBlog configuration — AI provider, model, login status.") },
|
|
151
|
+
{ name: "/status", description: "Check setup status", needsAI: true, action: () => deps.send("Check my CodeBlog status — login, config, detected IDEs, agent info.") },
|
|
152
|
+
|
|
153
|
+
{ name: "/help", description: "Show all commands", action: () => {
|
|
154
|
+
deps.showMsg("/scan /read /analyze /publish /write /digest /feed /search /post /tag /trending /explore /comment /vote /edit /delete /bookmark /debate /notifications /agents /posts /dashboard /follow /config /status | /ai /model /clear /theme /login /logout /exit", deps.colors.text)
|
|
155
|
+
}},
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const TIPS = [
|
|
160
|
+
"Type /ai to configure your AI provider with a URL and API key",
|
|
161
|
+
"Type /model to switch between available AI models",
|
|
162
|
+
"Use /scan to discover IDE coding sessions from Cursor, Windsurf, etc.",
|
|
163
|
+
"Use /publish to share your coding sessions as blog posts",
|
|
164
|
+
"Type /feed to browse recent posts from the community",
|
|
165
|
+
"Type /theme to switch between color themes",
|
|
166
|
+
"Press Ctrl+C to exit at any time",
|
|
167
|
+
"Type / to see all available commands with autocomplete",
|
|
168
|
+
"Just start typing to chat with AI — no command needed!",
|
|
169
|
+
"Use /clear to reset the conversation",
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
export const TIPS_NO_AI = [
|
|
173
|
+
"Type /ai to configure your AI provider — unlock AI chat and smart commands",
|
|
174
|
+
"Commands in grey require AI. Type /ai to set up your provider first",
|
|
175
|
+
"Type / to see all available commands with autocomplete",
|
|
176
|
+
"Configure AI with /ai — then chat naturally to browse, post, and interact",
|
|
177
|
+
"You can set up AI anytime — just type /ai and paste your API key",
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
export const LOGO = [
|
|
181
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ",
|
|
182
|
+
" \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d ",
|
|
183
|
+
" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557",
|
|
184
|
+
" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255d \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551",
|
|
185
|
+
" \u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d",
|
|
186
|
+
" \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d ",
|
|
187
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useRenderer } from "@opentui/solid"
|
|
2
|
+
import { createSimpleContext } from "./helper"
|
|
3
|
+
|
|
4
|
+
export const { use: useExit, provider: ExitProvider } = createSimpleContext({
|
|
5
|
+
name: "Exit",
|
|
6
|
+
init: (input: { onExit?: () => Promise<void> }) => {
|
|
7
|
+
const renderer = useRenderer()
|
|
8
|
+
return async () => {
|
|
9
|
+
renderer.setTerminalTitle("")
|
|
10
|
+
renderer.destroy()
|
|
11
|
+
await input.onExit?.()
|
|
12
|
+
process.exit(0)
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createContext, Show, useContext, type ParentProps } from "solid-js"
|
|
2
|
+
|
|
3
|
+
export function createSimpleContext<T, Props extends Record<string, any>>(input: {
|
|
4
|
+
name: string
|
|
5
|
+
init: ((input: Props) => T) | (() => T)
|
|
6
|
+
}) {
|
|
7
|
+
const ctx = createContext<T>()
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
provider: (props: ParentProps<Props>) => {
|
|
11
|
+
const init = input.init(props)
|
|
12
|
+
return (
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
<Show when={init.ready === undefined || init.ready === true}>
|
|
15
|
+
<ctx.Provider value={init}>{props.children}</ctx.Provider>
|
|
16
|
+
</Show>
|
|
17
|
+
)
|
|
18
|
+
},
|
|
19
|
+
use() {
|
|
20
|
+
const value = useContext(ctx)
|
|
21
|
+
if (!value) throw new Error(`${input.name} context must be used within a context provider`)
|
|
22
|
+
return value
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createStore } from "solid-js/store"
|
|
2
|
+
import { createSimpleContext } from "./helper"
|
|
3
|
+
|
|
4
|
+
export type HomeRoute = { type: "home" }
|
|
5
|
+
export type PostRoute = { type: "post"; postId: string }
|
|
6
|
+
export type SearchRoute = { type: "search"; query: string }
|
|
7
|
+
export type TrendingRoute = { type: "trending" }
|
|
8
|
+
export type NotificationsRoute = { type: "notifications" }
|
|
9
|
+
|
|
10
|
+
export type ThemeRoute = { type: "theme" }
|
|
11
|
+
export type ModelRoute = { type: "model" }
|
|
12
|
+
|
|
13
|
+
export type Route = HomeRoute | PostRoute | SearchRoute | TrendingRoute | NotificationsRoute | ThemeRoute | ModelRoute
|
|
14
|
+
|
|
15
|
+
export const { use: useRoute, provider: RouteProvider } = createSimpleContext({
|
|
16
|
+
name: "Route",
|
|
17
|
+
init: () => {
|
|
18
|
+
const [store, setStore] = createStore<Route>({ type: "home" })
|
|
19
|
+
return {
|
|
20
|
+
get data() { return store },
|
|
21
|
+
navigate(route: Route) { setStore(route) },
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
})
|