Skip to content

Commit

Permalink
update to latest zenstack + optimistic update
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Nov 16, 2023
1 parent b338899 commit 5b6d19b
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 696 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ logs
node_modules/
.env.local
.next
.zenstack_repl*
12 changes: 7 additions & 5 deletions components/Todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import TimeInfo from './TimeInfo';

type Props = {
value: Todo & { owner: User };
optimistic?: boolean;
updated?: (value: Todo) => any;
deleted?: (value: Todo) => any;
};

export default function TodoComponent({ value }: Props) {
const update = useUpdateTodo();
const del = useDeleteTodo();
export default function TodoComponent({ value, optimistic }: Props) {
const update = useUpdateTodo(undefined, true, true); // optimistic
const del = useDeleteTodo(undefined, true, true); // optimistic

const deleteTodo = async () => {
del.mutate({ where: { id: value.id } });
Expand All @@ -33,11 +34,12 @@ export default function TodoComponent({ value }: Props) {
<div className="border rounded-lg px-8 py-4 shadow-lg flex flex-col items-center w-full lg:w-[480px]">
<div className="flex justify-between w-full mb-4">
<h3
className={`text-xl line-clamp-1 ${
value.completedAt ? 'line-through text-gray-400 italic' : 'text-gray-700'
className={`text-xl line-clamp-1 flex items-center
${value.completedAt ? 'line-through text-gray-400 italic' : 'text-gray-700'}
}`}
>
{value.title}
{optimistic && <span className="loading loading-spinner loading-sm ml-1"></span>}
</h3>
<div className="flex">
<input
Expand Down
Loading

0 comments on commit 5b6d19b

Please sign in to comment.