Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita708d56

Browse files
committed
test: update examples to test file uploads
1 parentd5e59cf commita708d56

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

‎.hintrc‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
],
55
"hints": {
66
"typescript-config/consistent-casing": "off",
7-
"typescript-config/strict": "off"
7+
"typescript-config/strict": "off",
8+
"axe/forms": [
9+
"default",
10+
{
11+
"label": "off"
12+
}
13+
]
814
}
915
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use server";
2+
import{action,zodFile}from"@davstack/action";
3+
exportconstuploadFile=action()
4+
.input({
5+
file:zodFile({type:"*"}),
6+
})
7+
.mutation(async({ input, ctx})=>{
8+
console.log("FILE UPLOADING! ",{ input, ctx});
9+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client";
2+
import{objectToFormData}from"@davstack/action";
3+
import{uploadFile}from"./file.action";
4+
exportinterfaceFilePageProps{}
5+
6+
exportdefaultfunctionFilePage(props:FilePageProps){
7+
const{}=props;
8+
9+
return(
10+
<>
11+
<formaction={uploadFileasany}>
12+
<inputtype="file"name="file"/>
13+
<buttontype="submit">Upload via form action</button>
14+
</form>
15+
16+
<button
17+
onClick={async()=>{
18+
try{
19+
constfile=newBlob([],{type:"123"});
20+
awaituploadFile(objectToFormData({ file}));
21+
}catch(e){
22+
console.error(e);
23+
}
24+
}}
25+
>
26+
upload via direct action call
27+
</button>
28+
</>
29+
);
30+
}

‎examples/t3-with-davstack/src/app/with-server-actions/actions.tsx‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use server";
22

3-
import{unstable_cache}from'next/cache';
43
import{authedAction}from"@/lib/action";
5-
import{revalidatePath}from"next/cache";
64
import{z}from"zod";
75

86
exportconstgetTodos=authedAction.query(async({ ctx})=>{
@@ -16,16 +14,12 @@ export const getTodos = authedAction.query(async ({ ctx }) => {
1614
exportconstcreateTodo=authedAction
1715
.input({name:z.string().min(1)})
1816
.mutation(async({ ctx, input})=>{
19-
returnctx.db.todo
20-
.create({
21-
data:{
22-
name:input.name,
23-
createdBy:{connect:{id:ctx.user.id}},
24-
},
25-
})
26-
.then(()=>{
27-
// revalidatePath("/with-server-actions");
28-
});
17+
returnctx.db.todo.create({
18+
data:{
19+
name:input.name,
20+
createdBy:{connect:{id:ctx.user.id}},
21+
},
22+
});
2923
});
3024

3125
exportconstupdateTodo=authedAction

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp