Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit f326dae

Browse files
committed
Fix compilation errors.
1 parent 77116fd commit f326dae

6 files changed

Lines changed: 52 additions & 26 deletions

File tree

apps/frontend/Todo.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as A from "@effect-ts-demo/core/ext/Array"
22
import {
33
array,
44
constructor,
5+
identity,
56
Model,
67
literal,
78
NonEmptyString,
@@ -15,10 +16,13 @@ import {
1516
These,
1617
union,
1718
reasonableString,
19+
parseStringE,
20+
leafE,
21+
ReasonableString,
1822
} from "@effect-ts-demo/core/ext/Schema"
1923
import * as Todo from "@effect-ts-demo/todo-client/Tasks"
2024
import { TaskId, TaskListId } from "@effect-ts-demo/todo-client/Tasks"
21-
import { constant, flow, identity, pipe } from "@effect-ts/core/Function"
25+
import { constant, flow, pipe, identity as ident } from "@effect-ts/core/Function"
2226
import * as O from "@effect-ts/core/Option"
2327
import * as ORD from "@effect-ts/core/Ord"
2428
import { Lens } from "@effect-ts/monocle"
@@ -151,8 +155,12 @@ const isOrder = (u: any): u is Order & NonEmptyString => u in orders
151155
export const Order = nonEmptyString[">>>"](
152156
pipe(
153157
identity(isOrder),
154-
parser((x) => (isOrder(x) ? These.succeed(x) : These.fail("not order"))),
155-
constructor((x) => (isOrder(x) ? These.succeed(x) : These.fail("not order")))
158+
parser((x) =>
159+
isOrder(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
160+
),
161+
constructor((x) =>
162+
isOrder(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
163+
)
156164
)
157165
) // TODO
158166

@@ -162,8 +170,12 @@ const isOrderDir = (u: any): u is OrderDir & NonEmptyString => u in orders
162170
export const OrderDir = nonEmptyString[">>>"](
163171
pipe(
164172
identity(isOrderDir),
165-
parser((x) => (isOrderDir(x) ? These.succeed(x) : These.fail("not order"))),
166-
constructor((x) => (isOrderDir(x) ? These.succeed(x) : These.fail("not order")))
173+
parser((x) =>
174+
isOrderDir(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
175+
),
176+
constructor((x) =>
177+
isOrderDir(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
178+
)
167179
)
168180
) // TODO
169181

@@ -188,10 +200,10 @@ export function filterByCategory(category: TaskView | string) {
188200
return A.filter((t: Todo.Task) => t.listId === "inbox")
189201
}
190202
case "all": {
191-
return identity
203+
return ident
192204
}
193205
default:
194-
return A.filter((t: Todo.Task) => t.listId === category)
206+
return A.filter((t: Todo.Task) => t.listId === (category as any))
195207
}
196208
}
197209

@@ -207,8 +219,8 @@ function isSameDay(today: Date) {
207219

208220
export const emptyTasks = [] as readonly Todo.Task[]
209221

210-
export const Category = nonEmptyString
211-
export type Category = NonEmptyString
222+
export const Category = reasonableString
223+
export type Category = ReasonableString
212224

213225
export * from "@effect-ts-demo/todo-types"
214226
export * from "@effect-ts-demo/todo-types/Task"

apps/frontend/features/Tasks/FolderList/FolderList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function TLG(g: Todo.TaskListGroup) {
5555
>
5656
<TaskListEntry
5757
{...l}
58-
title={("| -- " + l.title) as S.NonEmptyString}
58+
title={("| -- " + l.title) as S.ReasonableString}
5959
/>
6060
</Box>
6161
)}

apps/frontend/features/Tasks/FolderList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ const FolderListView = ({ category }: { category: O.Option<Todo.Category> }) =>
5757
A.map(
5858
({ slug, tasks }) =>
5959
new TaskListView({
60-
title: toUpperCaseFirst(slug) as S.NonEmptyString,
60+
title: toUpperCaseFirst(slug) as S.ReasonableString,
6161
slug,
6262
count: tasks.length,
6363
})
6464
)
6565
),
6666
new TaskListView({
67-
title: "Tasks" as S.NonEmptyString,
67+
title: "Tasks" as S.ReasonableString,
6868
slug: "tasks",
6969
count: unfilteredTasks["|>"](filterByCategory("inbox")).length,
7070
}),

apps/frontend/features/Tasks/TaskList/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ import { TodoClient } from "@/index"
2121
import { Todo } from "@/index"
2222
import { renderIf_, toUpperCaseFirst } from "@/utils"
2323

24-
import { useGetTask, useMe, useModifyMe, useNewTask, useTasks } from "../data"
24+
import {
25+
parseRSunsafe,
26+
useGetTask,
27+
useMe,
28+
useModifyMe,
29+
useNewTask,
30+
useTasks,
31+
} from "../data"
2532
import { useRouting } from "../routing"
2633

2734
import TaskList from "./TaskList"
@@ -81,7 +88,9 @@ const TaskListView = memo(function ({
8188
? category === "tasks"
8289
? meResult.value.right.inboxOrder
8390
: A.findFirstMap_(meResult.value.right.lists, (l) =>
84-
l._tag === "TaskList" && l.id === category ? O.some(l.order) : O.none
91+
l._tag === "TaskList" && l.id === (category as any)
92+
? O.some(l.order)
93+
: O.none
8594
)["|>"](O.getOrElse(() => []))
8695
: []
8796
const tasks = unfilteredTasks["|>"](Todo.filterByCategory(category))
@@ -116,7 +125,9 @@ const TaskListView = memo(function ({
116125
? { inboxOrder: order }
117126
: {
118127
lists: A.map_(r.lists, (l) =>
119-
l.id === category && l._tag === "TaskList" ? { ...l, order } : l
128+
l.id === (category as any) && l._tag === "TaskList"
129+
? { ...l, order }
130+
: l
120131
),
121132
}),
122133
}))
@@ -166,7 +177,7 @@ const TaskListView = memo(function ({
166177
fullWidth
167178
placeholder="Add a Task"
168179
disabled={addTask.loading}
169-
onChange={addTask}
180+
onChange={flow(parseRSunsafe, addTask)}
170181
/>
171182
</Box>
172183
</>

apps/frontend/features/Tasks/data.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ export function useTasks() {
7777
}
7878

7979
const newTask =
80-
(v: Todo.TaskView | S.NonEmptyString, listId: Todo.TaskListIdU = "inbox") =>
81-
(newTitle: S.NonEmptyString) =>
80+
(v: Todo.TaskView | S.ReasonableString, listId: Todo.TaskListIdU = "inbox") =>
81+
(newTitle: S.ReasonableString) =>
8282
TodoClient.TasksClient.CreateTask({
8383
title: newTitle,
8484
isFavorite: v === "important",
8585
myDay: v === "my-day" ? O.some(new Date()) : O.none,
8686
listId,
8787
})
8888
export function useNewTask(
89-
v: Todo.TaskView | S.NonEmptyString,
89+
v: Todo.TaskView | S.ReasonableString,
9090
listId?: Todo.TaskListId
9191
) {
9292
return useFetch(newTask(v, listId))
@@ -224,7 +224,8 @@ export function useTaskCommandsResolved(t: Todo.Task) {
224224
}
225225
}
226226

227-
const parseNES = Parser.for(S.nonEmptyString)["|>"](S.condemnFail)
227+
export const parseRS = Parser.for(S.reasonableString)["|>"](S.condemnFail)
228+
export const parseRSunsafe = Parser.for(S.reasonableString)["|>"](S.unsafe)
228229

229230
export function useTaskCommands(id: Todo.TaskId) {
230231
const modifyTasks = useModifyTasks()
@@ -263,7 +264,7 @@ export function useTaskCommands(id: Todo.TaskId) {
263264
function updateStepTitle(t: Todo.Task) {
264265
return (s: Todo.Step) =>
265266
flow(
266-
parseNES,
267+
parseRS,
267268
T.map((stepTitle) => t["|>"](Todo.Task.updateStep(s, stepTitle))),
268269
T.chain(updateAndRefreshTask)
269270
)
@@ -287,7 +288,7 @@ export function useTaskCommands(id: Todo.TaskId) {
287288

288289
function addNewTaskStep(t: Todo.Task) {
289290
return flow(
290-
parseNES,
291+
parseRS,
291292
T.map((title) => t["|>"](Todo.Task.addStep(title))),
292293
T.chain(updateAndRefreshTask)
293294
)
@@ -303,7 +304,7 @@ export function useTaskCommands(id: Todo.TaskId) {
303304

304305
function setTitle(t: Todo.Task) {
305306
return flow(
306-
parseNES,
307+
parseRS,
307308
T.map((v) => t["|>"](Todo.Task.lens["|>"](Lens.prop("title")).set(v))),
308309
T.chain(updateAndRefreshTask)
309310
)
@@ -321,7 +322,7 @@ export function useTaskCommands(id: Todo.TaskId) {
321322
return (note: string | null) =>
322323
pipe(
323324
EO.fromNullable(note),
324-
EO.chainEffect(parseNES),
325+
EO.chainEffect(parseRS),
325326
T.chain((note) => updateAndRefreshTask({ id: t.id, note }))
326327
)
327328
}

packages/core/ext/Schema/_api/string.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export interface ReasonableStringBrand {
2828
readonly ReasonableString: unique symbol
2929
}
3030

31-
export type ReasonableString = S.NonEmptyString & ReasonableStringBrand
31+
// TODO: Evaluate if it makes sense to inherit the others too.
32+
export type ReasonableString = TextString & LongString & ReasonableStringBrand
3233

3334
export const reasonableStringFromString = pipe(
3435
makeConstrainedFromString<ReasonableString>(1, 256 - 1),
@@ -45,7 +46,8 @@ export interface LongStringBrand {
4546
readonly LongString: unique symbol
4647
}
4748

48-
export type LongString = S.NonEmptyString & LongStringBrand
49+
// TODO: Evaluate if it makes sense to inherit the others too.
50+
export type LongString = TextString & LongStringBrand
4951

5052
export const longStringFromString = pipe(
5153
makeConstrainedFromString<LongString>(1, 2048 - 1),

0 commit comments

Comments
 (0)