@xeplr/cli 0.1.2 → 0.1.3
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 +28 -13
- package/bin/xeplr.js +10 -4
- package/lib/generate/index.js +123 -3
- package/lib/nextSteps.js +33 -18
- package/lib/plan.js +7 -0
- package/lib/questions.js +60 -1
- package/lib/setup.js +59 -0
- package/package.json +2 -1
- package/templates/api/app.js +20 -1
- package/templates/api/bin/www +18 -4
- package/templates/api/db/setup.js +1 -0
- package/templates/api/development.env.tpl +3 -2
- package/templates/api/migrations/README.md +9 -0
- package/templates/api/migrations-auth/0003_designer_menu.sql +19 -0
- package/templates/api/models/index.js +7 -6
- package/templates/api/package.json +4 -2
- package/templates/api/routes/index.js +6 -15
- package/templates/api/screens/index.js +32 -0
- package/templates/api/screens/task/task-edit.screen.json +103 -0
- package/templates/api/screens/task/task-list.screen.json +45 -0
- package/templates/api/screens/task/task.entity.json +10 -0
- package/templates/api/screens/task/task.hooks.js +37 -0
- package/templates/ui/package.json +4 -0
- package/templates/ui/src/App.jsx +18 -2
- package/templates/ui/src/api/factory.js +10 -0
- package/templates/ui/src/index.css +25 -0
- package/templates/ui/src/main.jsx +2 -0
- package/templates/ui/src/pages/Designer.jsx +74 -0
- package/templates/ui/src/pages/Home.jsx +4 -0
- package/templates/ui/src/pages/Tasks.jsx +18 -94
- package/templates/ui/src/pages/TasksHelp.jsx +35 -33
- package/templates/ui/vite.config.js +1 -1
- package/templates-tenancy/api/migrations/0001_tenants.sql +8 -0
- package/templates-tenancy/api/migrations-auth/0004_switch_menu.sql +10 -0
- package/templates-tenancy/api/routes/tenants.js +130 -0
- package/templates-tenancy/api/tenancy.js +12 -0
- package/templates-tenancy/ui/src/pages/SelectScope.css +45 -0
- package/templates-tenancy/ui/src/pages/SelectScope.jsx +154 -0
- package/templates-tenancy/ui/src/tenancy.js +3 -0
- package/templates/api/migrations/0001_tasks.sql +0 -23
- package/templates/api/models/Task.js +0 -48
- package/templates/ui/src/api/tasks.js +0 -34
- package/templates/ui/src/useTasksController.js +0 -83
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// CONTROLLER LAYER — state and handlers, no JSX.
|
|
2
|
-
//
|
|
3
|
-
// The same split the @xeplr/ui-* libraries use. A different design can import
|
|
4
|
-
// this hook and render the fields however it likes; the behaviour below is
|
|
5
|
-
// unchanged by that, which is what makes a rebrand safe.
|
|
6
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
7
|
-
import { listTasks, saveTasks, deleteTasks } from './api/tasks.js'
|
|
8
|
-
|
|
9
|
-
const EMPTY = { title: '', description: '', status: 'todo', dueDate: '' }
|
|
10
|
-
|
|
11
|
-
export function useTasksController() {
|
|
12
|
-
const [tasks, setTasks] = useState([])
|
|
13
|
-
const [form, setForm] = useState(EMPTY)
|
|
14
|
-
const [editingId, setEditingId] = useState(null)
|
|
15
|
-
const [busy, setBusy] = useState(false)
|
|
16
|
-
const [error, setError] = useState(null)
|
|
17
|
-
|
|
18
|
-
const refresh = useCallback(async () => {
|
|
19
|
-
try {
|
|
20
|
-
setTasks(await listTasks())
|
|
21
|
-
setError(null)
|
|
22
|
-
} catch (e) {
|
|
23
|
-
setError(e.message)
|
|
24
|
-
}
|
|
25
|
-
}, [])
|
|
26
|
-
|
|
27
|
-
useEffect(() => { refresh() }, [refresh])
|
|
28
|
-
|
|
29
|
-
const setField = useCallback((name, value) => {
|
|
30
|
-
setForm((f) => ({ ...f, [name]: value }))
|
|
31
|
-
}, [])
|
|
32
|
-
|
|
33
|
-
const edit = useCallback((task) => {
|
|
34
|
-
setEditingId(task.id)
|
|
35
|
-
setForm({
|
|
36
|
-
title: task.title || '',
|
|
37
|
-
description: task.description || '',
|
|
38
|
-
status: task.status || 'todo',
|
|
39
|
-
// The API returns a full timestamp; a date input wants just the day.
|
|
40
|
-
dueDate: task.dueDate ? String(task.dueDate).slice(0, 10) : ''
|
|
41
|
-
})
|
|
42
|
-
}, [])
|
|
43
|
-
|
|
44
|
-
const cancel = useCallback(() => {
|
|
45
|
-
setEditingId(null)
|
|
46
|
-
setForm(EMPTY)
|
|
47
|
-
}, [])
|
|
48
|
-
|
|
49
|
-
const submit = useCallback(async (e) => {
|
|
50
|
-
if (e) e.preventDefault()
|
|
51
|
-
setBusy(true)
|
|
52
|
-
try {
|
|
53
|
-
// An entry with no id is a create; with one, an update. Same call.
|
|
54
|
-
const entry = { ...form, dueDate: form.dueDate || null }
|
|
55
|
-
if (editingId) entry.id = editingId
|
|
56
|
-
await saveTasks([entry])
|
|
57
|
-
cancel()
|
|
58
|
-
await refresh()
|
|
59
|
-
setError(null)
|
|
60
|
-
} catch (e2) {
|
|
61
|
-
// The API refuses on the model's own jsonSchema and names the field, so
|
|
62
|
-
// showing its message beats inventing our own.
|
|
63
|
-
setError(e2.message)
|
|
64
|
-
} finally {
|
|
65
|
-
setBusy(false)
|
|
66
|
-
}
|
|
67
|
-
}, [form, editingId, cancel, refresh])
|
|
68
|
-
|
|
69
|
-
const remove = useCallback(async (id) => {
|
|
70
|
-
setBusy(true)
|
|
71
|
-
try {
|
|
72
|
-
await deleteTasks([id])
|
|
73
|
-
if (editingId === id) cancel()
|
|
74
|
-
await refresh()
|
|
75
|
-
} catch (e) {
|
|
76
|
-
setError(e.message)
|
|
77
|
-
} finally {
|
|
78
|
-
setBusy(false)
|
|
79
|
-
}
|
|
80
|
-
}, [editingId, cancel, refresh])
|
|
81
|
-
|
|
82
|
-
return { tasks, form, setField, submit, edit, cancel, remove, editingId, busy, error, refresh }
|
|
83
|
-
}
|