Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimistic file upload #717

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

akuokojnr
Copy link
Collaborator

@akuokojnr akuokojnr commented Apr 19, 2021

This PR lands optimistic upload in Slate. Files (images, video, audio, pdf, html, fonts) are immediately shown and can be previewed whilst the upload completes. When the upload fails, the file is removed from the data screen.

Corresponding PR at: https://github.com/slate-engineering/shovel

TODO

  • Find fix for optimistic file(s) appearing and disappearing between uploads on collection page

@akuokojnr akuokojnr self-assigned this Apr 19, 2021
@akuokojnr akuokojnr marked this pull request as draft April 19, 2021 16:19
@akuokojnr akuokojnr changed the title feat: optimistic image upload feat: optimistic file upload Apr 21, 2021
@akuokojnr akuokojnr marked this pull request as ready for review April 21, 2021 19:21
@akuokojnr akuokojnr requested a review from martinalong April 21, 2021 19:21
@martinalong
Copy link
Collaborator

Mind rebasing with the current version of main then I'll review? To merge it with the database migration changes

@akuokojnr akuokojnr force-pushed the @akuokojnr/optimistic-uploading branch from 10accef to eeec7b5 Compare April 26, 2021 11:48
@martinalong
Copy link
Collaborator

This looks fantastic! One thing I would change: can you set the carousel to not show any actions for files that are still uploading rather than just making them not clickable? This would be for the privacy, add to slate, delete, download options etc.

And also probably also not allow them to be multi-selected with the checkbox or with shift + click + drag? We don't want people trying to do actions that way on files that are still uploading either

@martinalong
Copy link
Collaborator

Also, I noticed that if you upload only duplicate files and it skips them (aka no files successfully upload), they just stay there and don't get removed. This is probably because it never reaches the websocket library update that happens at the end of successfully uploading a file.

There's two ways to go about fixing this: one is for every file that fails during upload, you manually remove it from the library. The other is you make some kind of a call that does ViewerManager.hydratePartial( id, { library: true }) like what happens when files successfully upload. I'm in favor of the former, since that would remove them instantly rather than after all files upload.

@martinalong
Copy link
Collaborator

martinalong commented Apr 26, 2021

I also noticed that when uploading to a slate, the files flash on screen then disappear? This could be because of some logic I have in SceneSlate, so let me know if you have trouble debugging this and I can help out

Actually I don't think it's uploading properly to slates at all. Since when I drop something into a slate it doesn't show up there even after it shows up in library. And when I upload to a slate, the uploading notification just stays there and doesn't ever go away even though it's done uploading.

This may be due to something that got deleted while rebasing with the new code?

let update = succeeded.map((item) => {
let data = item.json?.data;

let itemToUpdateIndex = library[0].children.findIndex((item) => item.id === data.id);
Copy link
Collaborator

@martinalong martinalong Apr 26, 2021

Choose a reason for hiding this comment

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

This is something that changed in the migration. Pleas make sure you take a look at the doc https://www.notion.so/slatesystem/Files-Database-Migration-84ccad66574d487fbad4a4a2a5857276 for changes and edit your code to fit the new data structure

It's no longer library[0].children, it's now just library

Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be the source of some of the other errors I mentioned (like uploads not resolving properly etc)

@@ -0,0 +1,758 @@
import * as React from "react";
Copy link
Collaborator

Choose a reason for hiding this comment

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

CarouselSidebarData.js and CarouselSidebarSlate.js have been removed and replaced with CarouselSidebar.js

If there's any changes you made to this, please add them to CarouselSidebar.js instead and delete this

type: files[i].type,
size: files[i].size,
},
decorator: "OPTIMISTIC-FILE",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instaed of using decorator = "OPTIMISTIC-FILE" maybe we can do something like file.optimistic = true

Decorator might be used for other things so we'd like to reserve it for that ideally. Plus it's easier to check for (if (file.optimistic)) and b/c with decorator.startsWith("OPTIMISTIC") you have to worry about keeping capitalization consistent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants