mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-09-11 15:26:19 +03:00
Update waspc/todo-typescript to latest changes
This commit is contained in:
parent
31161d131e
commit
fd67f94f37
@ -1,6 +1,6 @@
|
||||
app TodoTypescript {
|
||||
wasp: {
|
||||
version: "^0.13.0"
|
||||
version: "^0.14.0"
|
||||
},
|
||||
title: "ToDo TypeScript",
|
||||
|
||||
|
@ -40,7 +40,7 @@ export const MainPage = ({ user }: { user: AuthUser }) => {
|
||||
<Link to="/chat">Wonna chat?</Link>
|
||||
{user && (
|
||||
<h1>
|
||||
{getFirstProviderUserId(user)}
|
||||
{user.getFirstProviderUserId()}
|
||||
{`'s tasks :)`}
|
||||
</h1>
|
||||
)}
|
||||
|
@ -8,6 +8,7 @@ import type { AuthUser } from 'wasp/auth'
|
||||
import { getMe } from 'wasp/client/auth'
|
||||
import { getTasks } from 'wasp/client/operations'
|
||||
import { Tasks } from 'wasp/client/crud'
|
||||
import { makeAuthUserIfPossible } from 'wasp/auth/user'
|
||||
|
||||
const mockTasks = [
|
||||
{
|
||||
@ -39,22 +40,21 @@ test('handles rendering in context', () => {
|
||||
|
||||
const { mockQuery } = mockServer()
|
||||
|
||||
const mockUser = {
|
||||
// Abusing leaky private API, but it's fine for testing.
|
||||
// To whoever has to deal with this when we hide the private API:
|
||||
// Sorry, but it's probably me anyway :)
|
||||
//
|
||||
// On a more serious note, if this function
|
||||
// is useful in testing, perhaps we should make it public
|
||||
const mockUser = makeAuthUserIfPossible({
|
||||
id: 12,
|
||||
auth: {
|
||||
id: '123',
|
||||
userId: 12,
|
||||
identities: [
|
||||
{
|
||||
authId: '123',
|
||||
providerName: 'email',
|
||||
providerUserId: 'elon@tesla.com',
|
||||
providerData: '',
|
||||
},
|
||||
],
|
||||
address: 'test address',
|
||||
identities: {
|
||||
username: {
|
||||
id: '123',
|
||||
},
|
||||
},
|
||||
address: '',
|
||||
} satisfies AuthUser
|
||||
})
|
||||
|
||||
test('handles mock data', async () => {
|
||||
mockQuery(getTasks, mockTasks)
|
||||
|
@ -1,13 +1,31 @@
|
||||
import { FormEventHandler } from 'react'
|
||||
import { Task } from 'wasp/entities'
|
||||
import { updateTask, deleteTasks } from 'wasp/client/operations'
|
||||
import {
|
||||
updateTask,
|
||||
deleteTasks,
|
||||
useAction,
|
||||
getTasks,
|
||||
OptimisticUpdateDefinition,
|
||||
} from 'wasp/client/operations'
|
||||
|
||||
export function Todo({ id, isDone, description }: Task) {
|
||||
const updateTaskOptimistically = useAction(updateTask, {
|
||||
optimisticUpdates: [
|
||||
{
|
||||
getQuerySpecifier: () => [getTasks],
|
||||
updateQuery: (updatedTask, oldTasks) =>
|
||||
oldTasks &&
|
||||
oldTasks.map((task) =>
|
||||
task.id === updatedTask.id ? { ...task, ...updatedTask } : task
|
||||
),
|
||||
} as OptimisticUpdateDefinition<{ id: number; isDone: boolean }, Task[]>,
|
||||
],
|
||||
})
|
||||
const handleIsDoneChange: FormEventHandler<HTMLInputElement> = async (
|
||||
event
|
||||
) => {
|
||||
try {
|
||||
await updateTask({
|
||||
await updateTaskOptimistically({
|
||||
id,
|
||||
isDone: event.currentTarget.checked,
|
||||
})
|
||||
|
@ -49,6 +49,8 @@ export const updateTask: UpdateTask<UpdateArgs> = async (
|
||||
if (!context.user) {
|
||||
throw new HttpError(401)
|
||||
}
|
||||
// sleep for 2 seconds (to test optimistic updates)
|
||||
await new Promise((resolve) => setTimeout(resolve, 2_000))
|
||||
|
||||
return context.entities.Task.update({
|
||||
where: {
|
||||
|
@ -7,7 +7,7 @@ export const webSocketFn: WebSocketDefinition<
|
||||
InterServerEvents
|
||||
> = (io, context) => {
|
||||
io.on('connection', (socket) => {
|
||||
const username = getFirstProviderUserId(socket.data.user) ?? 'Unknown'
|
||||
const username = socket.data.user?.getFirstProviderUserId() ?? 'Unknown'
|
||||
console.log('a user connected: ', username)
|
||||
|
||||
socket.on('chatMessage', async (msg) => {
|
||||
|
@ -14,9 +14,9 @@ export function getName(user?: AuthUser) {
|
||||
return `Google user ${user.identities.google.id}`
|
||||
}
|
||||
|
||||
if (user.identities.github !== null) {
|
||||
return `GitHub user ${user.identities.github.id}`
|
||||
}
|
||||
// if (user.identities.github !== null) {
|
||||
// return `GitHub user ${user.identities.github.id}`
|
||||
// }
|
||||
|
||||
// if (user.identities.keycloak !== undefined) {
|
||||
// return `Keycloak user ${user.identities.keycloak.id}`
|
||||
|
Loading…
Reference in New Issue
Block a user