Skip to content

Commit

Permalink
fix: file upload setFiles and clearFiles methods (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagebakers authored Oct 11, 2023
1 parent e6ba2a5 commit 8eea22c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .xstate/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const fetchMachine = createMachine({
},
"FILE.DELETE": {
actions: ["removeFile"]
},
"FILES.CLEAR": {
actions: ["clearFiles"]
}
},
on: {
Expand Down
4 changes: 2 additions & 2 deletions packages/machines/file-upload/src/file-upload.connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
files: state.context.files,
setFiles(files) {
const count = files.length
send({ type: "VALUE.SET", files, count })
send({ type: "FILES.SET", files, count })
},
clearFiles() {
send({ type: "VALUE.SET", files: [] })
send({ type: "FILES.CLEAR" })
},
getFileSize(file) {
return formatFileSize(file.size, { locale: state.context.locale })
Expand Down
6 changes: 6 additions & 0 deletions packages/machines/file-upload/src/file-upload.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export function machine(userContext: UserDefinedContext) {
"FILE.DELETE": {
actions: ["removeFile"],
},
"FILES.CLEAR": {
actions: ["clearFiles"],
},
},
states: {
idle: {
Expand Down Expand Up @@ -124,6 +127,9 @@ export function machine(userContext: UserDefinedContext) {
const nextFiles = ctx.files.filter((file) => file !== evt.file)
set.files(ctx, nextFiles)
},
clearFiles(ctx) {
set.files(ctx, [])
},
},
compareFns: {
files: (a, b) => a.length === b.length && a.every((file, i) => isFileEqual(file, b[i])),
Expand Down

4 comments on commit 8eea22c

@vercel
Copy link

@vercel vercel bot commented on 8eea22c Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-nextjs – ./examples/next-ts

zag-two.vercel.app
zag-nextjs-chakra-ui.vercel.app
zag-nextjs-git-main-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8eea22c Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-vue – ./examples/vue-ts

zag-vue.vercel.app
zag-vue-chakra-ui.vercel.app
zag-vue-git-main-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8eea22c Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-solid – ./examples/solid-ts

zag-solid-chakra-ui.vercel.app
zag-solid.vercel.app
zag-solid-git-main-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8eea22c Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.