Placeholder Image

Subtitles section Play video

  • Hello.

  • Welcome to the drop box, A p I editorial.

  • In this tutorial, we're going to see a few different methods that are available to us in the drop box, a p I that allow us to interact with files and folders and manipulate them.

  • My name is Cristian.

  • I'll be your instructor for this course, and I'm sure you're wondering what we're gonna do and what you need to know.

  • So let's jump right in here as far as what you want to know.

  • It's good to know HTML and Java script, but it's not necessary, really.

  • Ah, lot of these methods were looking at will be available for other languages such as Python, for example.

  • They just might be a little bit difference in Texas, but the overarching principles will remain the same.

  • So as long as you're wanting to learn about the drop box a P I.

  • Even if you don't use the JavaScript as decay, which we're going to use, I think you'll find this useful.

  • As for what you'll learn, we'll go over getting some files, getting the thumbnails for those files and moving those files around.

  • Now I want to mention again.

  • There are many more options available in the drop box a p I many different methods you can use to manipulate files and folders, but these are the ones we're going to go over, and hopefully that will give you a good basis for how the FBI generally works.

  • Additionally, we'll use summary methods that maybe you've never seen before, or maybe needs some clarification how they work well, use some s six features such as Aargh functions, and we'll learn how to use a sink a weight, which is a fairly new way of dealing with a spear guns data and is perfect for our use case.

  • As for what we're building specifically well, take a look here and you'll see that we have a file organizer 3000 As I've affectionately named it.

  • We have a path where we can search for files or folders, and we have them Listen out here with thumbnails at the end of this lesson, will be able to organize every file in any given folder using the path here, and once we hit organized, it'll move those files into different folders based on their datemodified.

  • So that's the apple gonna build.

  • Let's jump right in before we start coating out the app.

  • I'd like to go over the developer documentation real quick.

  • So if you want to click right here on the slide or just go to dropbox dot com such developers, you should see something like this.

  • It will show you a dashboard of swords.

  • And if you go over to my APS on the left hand side, you should see a blank page because most likely you don't have any APS yet.

  • And then you can click on create AP up at the top, right?

  • That'll get an AP started for you.

  • Now, before I go further, I should mention you don't need to do this to take this course just going to give you some brief information on how to set up a nap so that when you do set up a nap, you could be familiar with it and it will help You know how I set up this app.

  • So first is gonna ask you which a p I you want to use for this app?

  • We're using the regular Dropbox a p I.

  • If you wanted to support teams for Dropbox So multiple people collaborating with in Dropbox then you might slip Dropbox business a p I.

  • But most likely you're gonna go with the regular A p I.

  • Next.

  • We need to choose if we're going to use just one folder for our app inside the user's dropbox account, or if we need access to the user's entire Dropbox account for this app.

  • I went ahead and shows APP folder, although in reality, if we were actually building this app would probably want to choose full Dropbox because this app is essentially going to organize the user's files, and that would require access to their files.

  • Last thing we want to pick a name for AP.

  • If that's taken already, then it'll tell you that, and you could pick a new one monster.

  • Don't go ahead and click.

  • Create app.

  • Okay, great.

  • So now that should take you to a setting screen and will quickly go through these.

  • First, we have our status, which would currently be in development.

  • When you're ready, you can go ahead and apply for production so that it could be reviewed by the Dropbox team.

  • Currently, you are also only the user that can access this, and if you want to enable additional users.

  • You can click here now that still has a limit on it, since it's a development app.

  • And if you want to enable more users than you would want to apply for production here we have the permission type that we just chose and step to.

  • When we first set up our app, That's Apt Folder were only one of the access to one folder in the use of Dropbox account.

  • We don't want access to their entire Dropbox account, and then we have our APP.

  • Folder name.

  • Now this is by default, going to be the same name as our app itself.

  • But if you wanted to change the name of just that folder, you're apt name would remain the same.

  • Just the folder in the drop box user's account would change.

  • Then you can change it here.

  • Next, we have the APP, key and secret.

  • Now, in this tutorial, we're not going to use these, but in a really life app, you probably would app.

  • Keys and secrets are good for when you need to do authorization, which is actually the next section here.

  • We can choose where we want to redirect the user once they have been authorized Allow implicit grant.

  • I'm not going to really go into If you hover over the eye when you actually go to the page, you can see a little more detail.

  • You should probably leave it as is, if you're building a client side app, which you probably are and generate access token is where you can get your own token to work with.

  • This is something I've already done and that will use in our app.

  • Although I should note that the token I'm using will be expired by the time you're viewing this.

  • So you may want to go ahead and do this and plug that in discrim ba or your own code base wherever in order to actually play with some files.

  • But this was basically going to skip the authorization set up and just give you a quick way to authorize Dropbox to check out the folders and files.

  • Next, we have options for what are called choosers and savers, and they look like this basically just little buttons that drop box has already created for you so that if you need to do something simple, like get some files or maybe you just need to save if out of their account.

  • Then instead of building entire AP, you may just want to use the chooser or a saver.

  • And if you do decide to use one of those, this is where you would put your web address.

  • So the Dropbox knows that hostess okay, to use a chooser or saver.

  • Next, we have Web books.

  • Basically, it's the idea that once I do something here, I want to trigger an action there.

  • Once I do something, that drop box I wanna trigger in action with Gmail or something similar.

  • Actually, if you are done with this happening, we don't need any more.

  • You can go and leave here.

  • Just be warned.

  • This is an irreversible action, so be careful.

  • The next page we have is the branding page these options a rather obvious.

  • Lastly, we have the analytic stab.

  • This naturally shows nothing because we haven't done anything yet, But after a while you should see some stuff here real quick.

  • Before we go on to coding our app, I want to mention the job script sdk, documentation.

  • You can click on this thing to go there.

  • It looks something like this basically It's a list of all the different methods that are available in this app.

  • We're only going to use a few different methods, so it's really not going to give you a good idea.

  • Everything Dropbox can do.

  • So go to the documentation, check out all the different methods you can use, even if you're not going to use the JavaScript s decaying you're at.

  • Maybe you're coding and python or something else.

  • This will be helpful because all these methods are the same, are very similar to what you might use in another language.

  • Once again, you can head over to dropbox dot com slash developers when you're ready to set up account.

  • Until then, let's go ahead and start this tutorial.

  • Let's begin by importing the Dropbox sdk.

  • One thing you make sure of is to surround Dropbox with curly braces because this is a named import or export, and once we do that, we can go ahead and use it to create a class or rather in Stan.

  • She ate a class and assign it to a very book.

  • We'll call that B B X for Dropbox, and they were just going to say new and then drop box with parentheses and we're gonna pass in an object to this function, which is creating a class for us that once again we're assigning to D B X.

  • Now that objects gonna take two properties, one is gonna be an access token, and the other is going to be a fetch library.

  • Now, there are different fresh libraries you can use, in which case you'd put whatever fetch library here.

  • But if you just want to use the native window, fetch library, then you could just put a patch that uses the six feature of simply assuming that the property and the variable are the same lips there.

  • For the excess token, you're going to go ahead and use your own, because by the time you view this, the excess token I'm going to put right here is not going to be valid any longer.

  • So go ahead and go to dropbox dot com slash developers.

  • I'll go ahead and pace that link up here and set up your account to get your own token and wants to do that.

  • You can replace the token here in whatever lesson you want to play around with.

  • If you don't really want to play a round of the code.

  • Of course, you don't have to do this.

  • Everything will still work.

  • It's not absolutely necessary.

  • But part of the beauty of scramble and having lessons on here is that you could play around with the code and you're not gonna be able to do that unless you change out this access tokens.

  • So I do encourage doing that.

  • But either way, we've imported our drop access decay, and we're now ready to use this D B X variable.

  • So far, all we've done is in Stan.

  • She ate our class in order to see what methods are available on that class.

  • You can go to the documentation here.

  • We're just going to go ahead and use as our first method something called Files List folder, which will essentially take a folder and list out of files inside that folder.

  • So this takes a lot of different options on the object that we pass in.

  • But we're just going to use for now.

  • The path now could specify the route path.

  • We actually pass an empty string, not a slash, and I should note the route path here is going to be the root of our APP folder, not the user's dropbox account.

  • And this is because when I set up my developer app, I chose that option.

  • You can set it to the user's dropbox account, but I set mine to the AP folder, so the roots will actually be the root of the app.

  • Older, not the drop box of camp.

  • Okay, now, what's that gonna do for us?

  • That's going to return a promise and all I want to do for now.

  • Let's go ahead and see what we're getting back.

  • What sits safe.

  • Okay, You weren't we got back.

  • It looks like an object with entries, property and that value of that entries.

  • Property is an array of different objects, and each object seems to represent either a folder or a file.

  • So you'll see here.

  • This 1st 1 we have is a folder named Other Stuff.

  • We have another folder here named 2018.

  • Another folder here in new 2019.

  • Looks like we've got a bunch of files in there and you can see that we have a lot of data on each of these files.

  • So in the next lesson will go ahead and render these to the browsers that we're looking at it in a pretty way.

  • That's nice to see instead of in the council.

  • But before we move on, I need to know real quick before you go off and use this new files list folder method you've learned.

  • You need to know this might not be all the files in the account or whatever the path is that we're trying to get them from.

  • There might be more files, and there is a way, and we're gonna learn later on how to use this to get more files called Files List folder continue.

  • There's a different method that drop box provides to us, so I just need to make that note really quickly.

  • Learn how to get more files later on.

  • For now, we're just learning how to get that first response, however many files Dropbox is willing to give us, and in the next dozen, once again, we'll learn how to render those files to the browser.

  • As it is now.

  • Our application on Lee logs the result that we're getting back from Dropbox.

  • That's fun and all, but let's see if we can render things to the browser I know this tutorial is more about drop box, but I thought I might be useful to see how we're making things happen in the dom.

  • First of all, we need to declare an element to interact with.

  • Here I am declaring a variable called finalist LM for Element and using document a Crease Lecter to select an element with the class of Js file list.

  • I like to put day.

  • It's the beginning of my class names just to know that I'm dealing with JavaScript so I don't accidentally mess with them when I'm just dealing with a female or CSS, we're gonna go ahead and do a little re factoring here to set up a rap.

  • What I've just done is declare a state variable that will hold our state.

  • Right now it's just one files property, which is an imperial.

  • I've moved our call to the files list folder and point into an NIT function which we can call it the end.

  • After declaring our other functions, I've declared an update files function which will take some files and update the state accordingly so that we keep all our old files that were in state as well as updated with the new ones and inside that were also calling our render files function, which will fill in now inside render files will first need to get our element so that we can place some H e mail in there.

  • Now there are two things I want to do with the files here.

  • First, I want a sort Ben Ben.

  • I want a map over them and for every one of them creating l I element so that we can see the list.

  • Let's sort alphabetically and let's go ahead and put the folders on top.

  • Okay, real quick.

  • I'll go over what we're doing here on this line.

  • We're comparing the dot tag property of each item.

  • If you recall what we logged to the council, every item in the array is gonna have a doc tag property that is either a folder or file.

  • What we're basically saying here is our either one of these items a folder.

  • If so, we're gonna need to prioritize the folder.

  • Next we're checking.

  • Are they the same?

  • If they're both folders or if they're both files, we don't need to do anything with them, except for organized alphabetically, which we do here.

  • But if one of the most folder and one of them is a file, we're gonna check which one is a folder.

  • If it's the 1st 1 we return negative one to say that it should come first.

  • And if it's the 2nd 1 we returned positive one to say That should come second.

  • In this way, we're sorting all our folders on top and resorting everything alphabetically.

  • Next we turn to our dot map method, which is gonna loop through every item in the array and return in a rape theme At Method of Honore accepts a function First argument is each item in that array in our case, a file or folder?

  • In fact, let's go ahead and check what type this is.

  • Well, say CONST.

  • Type equals file.

  • And then, if you'll recall the DOT Paige property is what stores, whether it's a file or a folder, we just want to return our actual H e mail.

  • I'm gonna go ahead and use back ticks to create a temporal literal inside this temple, literal.

  • Whatever I put will be what's returned.

  • It will take it literally.

  • Hence the name.

  • So let's return and out I element and what we want to see ultimately in the browser is the name of the file.

  • If we were to look at our council again and see what is being returned from John, Box will see that there's a dot main property on every file, so we'll put that in there.

  • I also want to go ahead and do some styling real quick.

  • I've already declared a class of D B X list item for each individual item on the list, and then I also want to put the type that we just declared above.

  • So we know if it's a file or folder, Okay, now, before that actually can do anything.

  • We do need to replace our council dot log up here so that instead of logging it were actually calling all this logic.

  • And to do that, we will call a pit files with the files that we get back from Dropbox once again.

  • If you were to look at that console that we logged earlier in the last lesson, you'll see that there's a dot entries property on that object, which holds the array of files.

  • So now we have our innit function calling our update files function, which calls are render files function, which will ultimately render something to the dumb.

  • However, if we were to call this right now, we would see a bunch of commas in between every ally element.

  • Let me go ahead and hit Save to show you what I mean.

  • As you can see, we've successfully logged the items of the array.

  • However, we are seeing commas in between every item, and that's simply because we're not returning a string here to our dot inner HTML.

  • We're returning in a ray.

  • We don't really want to do that.

  • We want to return a string.

  • So let's take this rate.

  • Let's call the dot join method, which will join every element in the array into one string.

  • And inside we can pass what kind of separated everyone we use.

  • In our case, we don't want a separator.

  • We just want one long string, so we'll pass an empty string where it's safe again.

  • And now Voila!

  • We can see all of our items.

  • We can see that our folders up on top, other stuff, and we can see that they're ordered alphabetically Now.

  • That's not really easy to tell that this is a folder.

  • So in the next lesson, we'll go ahead and add some thumbnails.

  • Right now our APP is working and we're displaying our files, but it doesn't look great yet.

  • What we'd like to do in this lesson is go ahead and add some thumbnails.

  • Now, this lesson's gonna concentrate on simply rendering those thumbnails.

  • And the next lesson we'll see how we can get the actual thumbnails for each file from Dropbox.

  • What we want to do here ultimately is in our render function.

  • While we're mapping over each file is check if that file has a thumb, no property and if so, use it.

  • And if not, go ahead and use the default.

  • Now, the first thing to keep in mind here is that folders do not have some nails.

  • So essentially our first check is gonna say, Are we dealing with file?

  • And if we are dealing with a file, then we can go ahead and use the thumbnail.

  • If not, we'll just use a default folder thumbnail.

  • Let's start by declaring a thumbnail variable burns.

  • We have our check to see if it's a file.

  • If it is, we want to go ahead and use the thumbnail property on the file.

  • In other words, the actual thumbnail.

  • And if not, we want to go ahead and use a default from you.

  • We're gonna go ahead and check this with a turn.

  • Every expression.

  • In case you're not familiar with Turner expressions, they essentially take the form of if something.

  • And if that's true, do something.

  • And if it's not, do something else.

  • Okay, let's go ahead and write that out.

  • What are we gonna test?

  • Well, first of all, we need to assign something to our thumbnail variable.

  • And here's where eternity expression starts.

  • We're going to go ahead and check if there is a family, a property on our file.

  • If there is ren, we're gonna go and use that from you.

  • And if not, we'll use a default.

  • Okay, Now the thumbnail being returned by Dropbox is going to be a base 64 image.

  • Essentially, that's just one big, long string.

  • That's a representation of an image.

  • Instead of an actual file.

  • It's a string that represents an image.

  • How do we use that in HTML?

  • Well, it looks something like this.

  • The important part expos here is in the beginning, we're gonna start with data, call an image and then our type of image and then a 64 comma and then our 8 64 string.

  • This big long string is just a default file from the in case we don't have a formula available on her file, But if we do, we want to go ahead and use that money.

  • Okay, so you'll see we're essentially starting with the same thing.

  • Except this file is going to be a J pick.

  • That is the default of the file format from Dropbox.

  • Then we're using a temperate literal with an inserted variable to insert our base 64 string.

  • So this is gonna be whatever based 64 string Dropbox provides.

  • Just review one more time.

  • We're assigning our thumbnail variable to either the actual thumbnail if it exists or a default the mail.

  • If it does not for our folders.

  • Once again, folders don't have prom nails so we can simply use the default.

  • Okay, once again, that's just a big, long string.

  • It's ah pulled her thumbnail as we'll see in just a moment, the last thing we need to do is actually insert the thumbnail in R H E mail.

  • So we're gonna go ahead and use an image tag here.

  • I'm gonna put a class on the image because I've already set this up in my success just to make it look nice.

  • And then, of course, we need to declare our source for our image tag.

  • It is going to be from a which is the variable we have declared and assign based on whether or not there is one.

  • And whether or not it's a file or a folder.

  • OK, let's save on to see what happens.

  • There we go.

  • We've got our thumbnails.

  • As you can see, you have a folder here, and the rest of them are files.

  • Now, obviously, these are default thumbnails.

  • And in the next lesson, we'll learn how we can get the actual thumbnails from Dropbox.

  • In the last lesson, we learned how to render thumbnails with our files.

  • This lesson will go ahead and learn how to get the actual thumbnails from Dropbox.

  • If you look at the documentation which I've linked at the top here, you'll find there is a method available to us called files.

  • Get a meal batch and that function takes an argument, which is an object that hasn't entries.

  • Property, which is an array of objects, each object having a path and optional size.

  • This is the basic format for the request will be making.

  • Okay, so we're getting an array of files and we want to turn that into an array of paths.

  • So let's go ahead and do that now.

  • Will say con spats equals what we need to do to our a first Well, first, it's filter out all the folders because holders don't have some dates here.

  • We're using these filter method on an array, and that takes a function, the first argument of which is the item in the array we're working on.

  • And it's simply returns, true or false that the returns true, we keep that item returns false.

  • We get rid of it.

  • In this case, we're checking to see if the dot tag property is equal to file, because if it is, it's file and we want to keep it.

  • If it's not, we don't want to keep it.

  • Allah, we filtered are array, so we only have files and no folders.

  • We can go ahead and map over every item and what will ultimately want to return for every item.

  • Is this object down here?

  • Okay, so we need to return that item.

  • But how do we do that?

  • Instead of just typing curly braces, we can actually surround those curly braces in parentheses to return a literal object.

  • All right, so what is our path?

  • Well, that's actually available on the file itself as path lower.

  • If you'll recall.

  • We originally started this pap by making a call to files this folder which gave us a list of folders and files, each of which had lots of information.

  • And one of those pieces of information is passed lower for the sides.

  • You'll have to go ahead and look at the documentation to see what sizes are available.

  • But for our uses, we want to go ahead and use 30 to 5 32 Okay, So instead of this array here, we will pass the cat's away.

  • We just created, and that will return a promise.

  • So let's go ahead and see what we get back simply by long into the concert.

  • Before we can do that.

  • However, there are a couple things we need to do.

  • First off, if we look at our documentation will find that this thumbnail batch call actually has a limit on it, so we can't get more than 25 at a time.

  • It turns out this files this folder call also has an option for a limit.

  • So this would be a good place to remedy that.

  • Let's go ahead and put a limit of 20 for our demo purposes.

  • Then, of course, we need to call our new function somewhere.

  • Let's go ahead and call it in the update files function and make sure to pass in the files for rate.

  • Okay, So when we initialize our app, we're making a call to files its holder to get the files and folders.

  • Then we're calling update files and then we're calling.

  • Get some nails.

  • Let's go ahead and save to see what happens.

  • All right.

  • Looks like we got a success.

  • If we look at the council, you see, there's a lot of information there, but essentially, we're just getting objects within entries, property and an array of files and folders.

  • Well, in this case, actually, just an array of files.

  • All right, so now that we have our response back from Dropbox we're ready to start working with it.

  • And a sign are thumbnails to our files.

  • Essentially, what we want to do is just create a thumbnail property on each file object that holds the thumbnail data.

  • This next part gets a little bit complicated, so I'm just gonna go ahead and pace it out, and then we can walk through it step by step.

  • First of all, we're going to make a copy of our current state that files, Ray, We do that very easily with the E S six spread operator as those three dots here at the beginning, that's essentially telling JavaScript to spread the items of the array into this a new, this new array.

  • So we do that and we call our new variable new state files.

  • Next, we want toe loop through the rez dot entries array.

  • That we got back from Dropbox at Red's dot entries array is just gonna be an array of objects.

  • Each object has a lot of information on it, but one of the properties on the object is thumbnail, and that's the one we're interested in.

  • We want to get the thumbnail of that object so we're gonna loop through each item in the array.

  • And in order to know which item we need to update your thumbnail of, we first need to figure out where it is in the array.

  • So we're declaring here variable called indexed updates.

  • That's gonna figure out okay, What item in our new state files array, Remember, that's just a copy of our current state.

  • Which item do we need to put a thumbnail on?

  • And the way we figure that out is using a method called find Index.

  • This is a method available on the array prototype.

  • So any array you work with is gonna have this find index method.

  • And it's similar to thedot filter method that we use failure in that it's ultimately going to return either true or false.

  • And what we're testing here is just see if the path is the same.

  • So if the path is the same, it's the same file, right?

  • And if it's the same file, that's the one we want update.

  • So we has an argument to the Adam we're gonna be working on, and we just test to see if the half is the same.

  • And if it is, that's the index that we want to use.

  • So we plugged that index in here, and we say in our new state files array, find this index and abby dot thumbnail property to it and make it equal to whatever the thumbnail was.

  • That drop box returned for that file.

  • And once we do all that for every single item in the array, we can finally a sign ST dot files to our new array of files.

  • And the only difference here is this.

  • Ray has some nails.

  • That's the only difference between these two rates.

  • So, we've added are thumbnails to our items in our ray.

  • And finally we render them to the screen.

  • That's it.

  • Saving.

  • See what happens.

  • All right.

  • Looks like everything is working.

  • We've got our actual thumbnails.

  • Next to each item, everything seems to be working.

  • Fine.

  • You'll notice that at the top here we have a folder and that does not have a thumbnail, which is normal.

  • But every other file does.

  • So everything was successful and we're ready to move on.

  • So far, we've introduced to a P I calls into our app.

  • The first was files this holder in the second files get the mail bench.

  • Both of these have returned promises using dot then which make working with a certain gonna ST a little easier.

  • However, we're gonna need to make some more calls in the future.

  • And we'd like to move away from promises into a feature and he s seven called a sink await the way a sink wait.

  • Works is simply we declare a sink before our function.

  • So instead of just reading at the function with a scene keyword right before it now inside of that function, we can use the awaits.

  • Keyword.

  • Let's go ahead and call our variable reds just like before.

  • Chris Time will put a weight before our function.

  • So concerts people's await whatever our asynchronous call is long was that return to promise This should work and we can get rid of heart, then called and instead act like this just a regular variable.

  • Essentially, if you picture this function being a synchronous function, we're working with asynchronous data the same way.

  • It's a ziff.

  • We were saying constructs equals one plus two and then using it just like we normally what only this function is a sickness and by using a sink Oh, wait.

  • We are telling Javascript to wait until this function is complete before moving on to the update files call and then using this variable, let's go ahead and do the same thing with our get thumbnails.

  • Function again will declare the casing keyword before the function, and we will simplify here by signing our data to a rez variable.

  • Once again, we can get rid of the dot.

  • Then call and we can go ahead and use all the stuff we've done earlier in pretty much the same for men only.

  • Now it's a lot cleaner.

  • It just looks like we're dealing with synchronous data.

  • We're assigning of variable reds to whatever data we get back here.

  • And as long as we include the await key word before our asynchronous call, we should be good.

  • Let's go ahead and save and see if this still works.

  • Looks like everything still works, so that's I use a single weight, simplify your coat and make working with a synchronous data a little bit more manageable.

  • Well, go ahead and continue to use a single weight in future lessons.

  • We just learned how to render thumbnails after getting them from Dropbox in order to get those thumbnails.

  • We had to limit our first call to get files to only 25 at the very most, and we chose 20.

  • However, there are more than 20 files in our folder in this folder that we're using for a demo.

  • There, actually 37 files.

  • So what do we do if we want our thumbnails?

  • But we still want to get all the files.

  • While drop box has a way to do this For the sake of demo purposes, let's go ahead and change this limit to five.

  • As you can see here, we're only getting five files.

  • One of them is a folder to show how we can resolve this.

  • I'm gonna take a look at an online tool the drop box provides, and I linked it right here.

  • They call it the AP I explorer.

  • If you go ahead and open up that link, you might see something like this.

  • There are a bunch of methods.

  • Listen, the left hand side that you don't see in the side here, but one of those methods is list folder and you may recognize that name because we're using the job script sdk equivalent right here files this folder now online.

  • If you look at the tool, you'll be able to see the different options that are available and you can enter a path and you can enter a limit, for example, and then you can go ahead and submit that called.

  • See what happens.

  • If you do that, you might see response that looks something like this.

  • This should look somewhat familiar to us.

  • We have our entries property, which is an array of files.

  • However, there are two things we haven't looked at yet, and that's these last two properties, the cursor and has more.

  • The cursor is essentially a very long string that keeps track of where we are in the process or in the folder.

  • It's sort of like a You were here last time you made this call pointer and that has more property tells us.

  • Are there more files to get?

  • In this case, it looks like there are so we can use the has more property to tell if we have more files to get, and we can use the cursor to actually get those files, and we would do that with another method that's similar to the one we already used.

  • If you look at the FBI Explorer, it would be under list folder slash Continue.

  • Now, the JavaScript SDK name will be a little bit different, but we'll go ahead and look at this for now.

  • If you look at the online tool, you'll be able to enter the cursor right here in a box and submit a call that will show you another object similar to what we've already seen.

  • You haven't entries property, which is an array of files.

  • And you can do this over and over again until finally, at the very end, once there are no more files you'll see has more equal to false.

  • In other words, for every response we get from Dropbox, we want to check that has more property.

  • And if it's true, used the cursor to get some more files and then repeat that process until eventually as more will be false.

  • And that's all they're gonna do in our next lesson.

  • Our APP is going to start by calling this and knit function.

  • Inside of that function, we are getting some files and folders from Dropbox were living them to only 20.

  • For the sake of getting thumbnails and then we're rendering them.

  • After we make this call, though, we want check if there are more files.

  • So let's check that has more property that we discussed in the last lesson.

  • And if it's true, we will call a function called Get More files, which we haven't set up yet.

  • But let's just type it up for now and into that function will need to pass the cursor so it can use that to get more files.

  • And in this case, since we'd like something to happen with those files right away will also passed a call back.

  • So this is gonna be a callback function here that's gonna receive more files.

  • I'm gonna get more files, function and what I'm gonna do with those files.

  • While we wanted the same thing we did with our first set of files, you would call up their files and remember that the entries property is where those files were stored.

  • Once again, we're gonna call it, get more files function that we still need to create, gonna pass in the cruiser, and we're also gonna pass in a callback function so that when more files are a treat those files could be passed into this function, and we can update fires.

  • Okay, Now, when we're doing this, I'd like to show a loading message to the users.

  • They know something's happening.

  • Let's go ahead and store that in your variable here.

  • Now that we have that variable weaken, simply hide or show that elements whenever we're loading or not loading.

  • Okay, so we're showing our loading message.

  • We're running our get more file.

  • Its function we're hiding are loading message.

  • And in case we don't actually have any more files, we'll skip that block all together, and we'll just make sure our loading message is hit it.

  • Now, this get more files.

  • Function is obviously going to be a synchronous.

  • So we need to make sure to put a weight here.

  • And that key word will work because this innit function is a synchronous.

  • If we didn't have this a sink, you would hear that awake you word.

  • And this is a key word would not work, but they do.

  • So after I get more fathers functions complete, then we can continue.

  • It's our code.

  • Now we get to create our get more files function.

  • Okay.

  • The first thing we need to do is figure out what Dropbox method there is for us to call.

  • If you look at the documentation will find that there is a method very similar to files this folder files list folder continue.

  • And that's method is gonna take an object with a cursor property, which is going to be the cursor using object structuring.

  • We can actually shorten prestigious ST Cursor because it is assumed when you write it like this that the property name and the variable that is the value will be the same, which they are.

  • We're getting our cursor value here, and so this is just a shorthand way of saying cursors equal to cursor after we do that and keep in mind, that's a sickness.

  • So we'll need to make sure this isn't facing dysfunction, and we'll check if there was a call that provided to this function.

  • And if so, call it with our response now, as it is right now, we're only checking for more files one time, but obviously we need to do that until there are no more files to get.

  • So once again we'll check that has more property.

  • And if there are more files to get.

  • We'll just use Riker Zhan to call this same file again.

  • This time we're passing the cursor we got from our second call and will pass in the same callback function.

  • Okay, so get more files will run.

  • It will check.

  • If there are more files using the cursor, it will make a call back.

  • And if there are more files Still, even after that call that we just made, then it will call this same function yet again.

  • And it will keep doing that until has more is false.

  • In which case it will skip this car right here.

  • One more thing we need to remember is this awake, keyword.

  • It's easy to forget, but do you recall this?

  • Get more files.

  • Function is a synchronous.

  • So our files a supporter continue functions asynchronous and are get more files function as it synchronous.

  • So they both need this await Hubert.

  • Okay, let's save and see what happens.

  • You may have noticed that the first response was updated shortly after with some new files.

  • And if you scroll down, you'll see we have a lot more than 20 right now.

  • Looks like it's working so we're making our initial call to get some files.

  • We're updating our browser.

  • Then we're checking if there are more files, If so, will show a loading message and we will wait for you.

  • Get more files function, which will get more files, call the call back and once again check if they're still more files.

  • And if so, repeat this loop until eventually there are no more files, at which point this code will continue because of our await keyword and hide the loading message.

  • We've done some pretty cool things and are up already.

  • However, one thing that would be nice is if we weren't restricted to just the route path.

  • Over time, let's go ahead and build that out.

  • Now, if we look at our app currently, you'll see I've made some changes with CSS html.

  • But the important thing for this lesson is this holder path input up here.

  • Ideally, we'd like to let the user enter some sort of path in here and go to it in our app.

  • Right now, we only have one folder, other stuff, So it be nice.

  • If User could say, Hey, I won't go to other stuff, Uh and it entered or it button and go to the path.

  • Right now it's not working.

  • It's just refreshing the page.

  • So let's go ahead and build out that logic.

  • First off, we'll need to declare a couple new variables to reference some HT male elements and get the data from that form.

  • So we've declared one element for the form and one element for the input.

  • Why do we need both?

  • Well, for the form we want to use that toe, listen to the submit event.

  • That's how we'll know when the user has actually changed anything about the path.

  • So we'll add an event listener and listen for that submit events, which will give us an event.

  • I've labeled that as e here, and the first thing we need to do is prevent the default behavior of forms because that will refresh the page.

  • And we don't want that next.

  • We need to get the value for the inputs.

  • Remember that Is that route path input that's declared up here and we can get the value simply by saying dot value.

  • However, in Dropbox, the route path is expensive and empty string and not a slash, which a lot of people are used to, so I do real quick.

  • I want to do a check and see if they entered eight people to slash.

  • If so, let's go ahead and use it to string.

  • If not, we can go ahead and use that value.

  • Also, people sometimes make the six with capitalization and such.

  • So let's turn this into a lower case string That way.

  • We're always dealing with lower case now.

  • We're not actually doing anything with this variable yet, so let's think about what we might need to do.

  • It would be nice if this Repap was available throughout our app.

  • We may need to use it elsewhere, So let's actually go ahead and put that on state.

  • It might change over time, so that seems like a good place to put it.

  • Okay, so now we are signing the route path.

  • Property of state object to whatever the route path is that user enters when they submit.

  • For what else do we need to do?

  • Well, we don't want to show the folders and files from the old path, so let's go ahead and clear those out.

  • Also, there is one quick thing I want to do with the female.

  • All I'm doing here is referencing that loading element that you see sometimes when the app first starts and I'm removing the hidden grass to show the user that it is loading and, well, if you think about it, we're basically starting over in our app.

  • When we first bought the app, it's voting files.

  • And then what's done loading that loading this just hidden and we can start using it.

  • We wanted the same thing here.

  • Every time you use it changes the path.

  • So let's just go ahead and call our innit function right now that will basically start our app over.

  • It will get this files.

  • This folder called and it will search for whatever the path is.

  • Except we don't want him to string here.

  • We want whatever our roof, half iss, the views are interested.

  • Okay.

  • So any time the user submits that Ridpath field, it will get the value, it will store it.

  • Our state, it will show a hidden message and it will re initialize our app.

  • Oh, I just realized I forgot to put parentheses after our two lower case method.

  • Sorry about that.

  • Now let's go ahead and save and see what happens.

  • Okay, we only have one folder here.

  • Other stuff.

  • So I guess that's the folder we're going to be testing.

  • Here we go and it works.

  • I can look in my Dropbox account and confirm this is indeed the contents of the other Stuff folder.

  • So everything is working as it should.

  • In the next lesson, we'll learn how to make this organized button work to magically move our files into their respective folders.

  • At last we reached the main function of our app, the ability to organize our files into folders based on the datemodified.

  • Let's get started.

  • First, we'll need to get a reference to the black.

  • An element will go ahead and call it organized button.

  • Then we need to listen for a click on that button.

  • Since organizing our files will be a synchronous, let's show some sort of message to our user to indicate that something's happening.

  • First we'll disable the button, and then after we disable the button, let's show a message.

  • Then we'll go ahead and carry out our organized operation that is a synchronous, so we'll need to make sure this is an asynchronous function and we'll need to rate that.

  • Once it completes, we can re enable our button.

  • And in order to restore the previous text, will need to grab that first and that we have a variable to reference the text before respect.

  • We can restore that.

  • Okay, now we're ready to create our move.

  • Files sedated.

  • Full dysfunction.

  • First off, let's establish which Dropbox method we need to use in order to move files round.

  • For this function, we will use trials.

  • Move batch V two.

  • They have a version to dysfunction.

  • That's what we'll use here.

  • That takes an object as an argument with a you guessed it entries property and that interests property is an array of objects.

  • Each object having a from path Annie to path.

  • So we're moving it from.

  • And where are we moving in too?

  • Now, of course, we want hard code, this array, we will generate it.

  • So let's call that array entries so that we can simplify it using object restructuring.

  • And let's create that entries array up here that will be based on our state back files.

  • Ray.

  • So we're taking whatever files are in our state currently, and we're gonna perform two operations on them.

  • First of all, we're gonna filter out the folders just like we did with our get thumbnails method.

  • Then we're gonna map over every file, and what we ultimately want to return is an object with a from path, any to bath.

  • Now the front path is gonna be pretty simple.

  • That's just filed.

  • A path of lower that's available on the major data we got from our very first dropbox call.

  • The two paths is what we'll need to build based on the date.

  • Now, the file does have a property on it called client commodified, and that will tell us the bait that was last modified.

  • So it's already taken care of for us.

  • Just so you know, there also is a server modified property.

  • But for this case, we will use client modified, and it's put in such a format that we can actually use it with the Dava script eight constructor.

  • So we will do that in order to have this bait variable something that will be able to work with in order to get the year in the month and whatever other information we need from this big.

  • Okay, So, essentially, what we're going to use to build our path is a template literal, with four different variables.

  • We have our roots than our year than a month and then the file me.

  • So for the route that's found on our state objects so state about route half are a year is gonna come from that date variable we just created.

  • And you can get that by being here and get a full year.

  • Our month is gonna be a little bit weirder than a year.

  • It's gonna be get ut si months and also the month number is one behind what you might think it would be.

  • So January is actually zero.

  • So we add one to whatever the month says it is in order to make it more reasonable.

  • And then finally, we have a file name.

  • All right, that's all for this lesson.

  • In the next lesson, we're gonna finish building our move files function, and we're actually going to see our app do its magic.

  • In the previous lesson, we set up this entries array and we pass it into the property of entries on our object, which he pass into files moved batch be too from Dropbox which is going to move our files around now we need to handle whatever Dropbox does.

  • So what is it going to do and what's it going to return to us?

  • Well, it could return one of two things.

  • It may be an object saying that the job is done, which will say success.

  • Or it may be an object with an asynchronous job.

  • I d Now, if we get back an asynchronous job, I d Then we know that still working.

  • So here I am, just pulling out that property from our response object.

  • And if that probably exists, whatever is inside of this, if block will run.

  • And so what we need to do in here while we need to check on that job.

  • Now, how do we do that?

  • Drop box actually provides a similar method to us, and that method is called files moved.

  • Batch

Hello.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it