You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.ts 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. ADD_FILE,
  3. REMOVE_FILE,
  4. UPDATE_FILE_UPLOAD_PROGRESS,
  5. UPLOAD_FILES,
  6. DOWNLOAD_FILE
  7. } from './actionTypes';
  8. import { IFileMetadata } from './types';
  9. /**
  10. * Upload files.
  11. *
  12. * @param {File[]} files - The files to upload.
  13. * @returns {Object}
  14. */
  15. export function uploadFiles(files: File[]) {
  16. return {
  17. type: UPLOAD_FILES,
  18. files
  19. };
  20. }
  21. /**
  22. * Update a file's upload progress.
  23. *
  24. * @param {string} fileId - The ID of the file to update.
  25. * @param {number} progress - The new progress value.
  26. * @returns {Object}
  27. */
  28. export function updateFileProgress(fileId: string, progress: number) {
  29. return {
  30. type: UPDATE_FILE_UPLOAD_PROGRESS,
  31. fileId,
  32. progress
  33. };
  34. }
  35. /**
  36. * Add a file.
  37. *
  38. * @param {IFileMetadata} file - The file to add to the state.
  39. * @returns {Object}
  40. */
  41. export function addFile(file: IFileMetadata) {
  42. return {
  43. type: ADD_FILE,
  44. file
  45. };
  46. }
  47. /**
  48. * Remove a file.
  49. *
  50. * @param {string} fileId - The ID of the file to remove.
  51. * @returns {Object}
  52. */
  53. export function removeFile(fileId: string) {
  54. return {
  55. type: REMOVE_FILE,
  56. fileId
  57. };
  58. }
  59. /**
  60. * Download a file.
  61. *
  62. * @param {string} fileId - The ID of the file to download.
  63. * @returns {Object}
  64. */
  65. export function downloadFile(fileId: string) {
  66. return {
  67. type: DOWNLOAD_FILE,
  68. fileId
  69. };
  70. }