diff --git a/_browser/multi-player-storage.md b/_browser/multi-player-storage.md index ce4330d7..988dfef6 100644 --- a/_browser/multi-player-storage.md +++ b/_browser/multi-player-storage.md @@ -2,23 +2,24 @@ layout: learn permalink: /:collection/:path.html --- + # Manage Data with Gaia + {:.no_toc} In this tutorial, you build a micro-blogging application using multi-player Gaia -storage. Gaia is Blockstack's [decentralized high-performance storage -system](https://github.com/blockstack/gaia). The tutorial contains the following -topics: +storage. Gaia is Blockstack's +[decentralized high-performance storage system](https://github.com/blockstack/gaia). +The tutorial contains the following topics: -* TOC -{:toc} +- TOC {:toc} -This tutorial does not teach you about authentication. That is covered in depth [in the hello-blockstack tutorial](hello-blockstack.html). +This tutorial does not teach you about authentication. That is covered in depth +[in the hello-blockstack tutorial](hello-blockstack.html). - ## About this tutorial and the prerequisites you need {% include note.html content="This tutorial was written for a user running macOS. If you are running a Windows @@ -26,18 +27,19 @@ machine, you can still work through this tutorial. You will need to adjust the instructions for your environment."%} The application you build is a React.js application that is completely -decentralized and server-less. While not strictly required to follow along, +decentralized and server-less. While not strictly required to follow along, basic familiarity with React.js is helpful. When complete, the app is capable of the following: -- authenticating users using Blockstack -- posting new statuses -- displaying statuses in the user profile -- looking up the profiles and statuses of other users +- authenticating users using Blockstack +- posting new statuses +- displaying statuses in the user profile +- looking up the profiles and statuses of other users The basic identity and storage services are provided by `blockstack.js`. To test -the application, you need to have already [registered a Blockstack ID](ids-introduction.html). +the application, you need to have already +[registered a Blockstack ID](ids-introduction.html). The tutorial relies on the `npm` dependency manager. Before you begin, verify you have installed `npm` using the `which` command. @@ -47,10 +49,11 @@ $ which npm /usr/local/bin/npm ``` -If you don't find `npm` in your system, [install -it](https://www.npmjs.com/get-npm). Finally, if you get stuck at any point -while working on the tutorial, the completed [source code is available for -you](https://github.com/larrysalibra/publik) to check your work against. +If you don't find `npm` in your system, +[install it](https://www.npmjs.com/get-npm). Finally, if you get stuck at any +point while working on the tutorial, the completed +[source code is available for you](https://github.com/larrysalibra/publik) to +check your work against. High Sierra 10.13.4. @@ -60,12 +63,12 @@ You use `npm` to install Yeoman. Yeoman is a generic scaffolding system that helps users rapidly start new projects and streamline the maintenance of existing projects. - 1. Install Yeoman. ```bash npm install -g yo ``` + 2. Install the Blockstack application generator. ```bash @@ -78,19 +81,20 @@ existing projects. In this section, you build an initial React.js application called Publik. -1. Create a the `publik` directory. +1. Create a the `publik` directory. ```bash mkdir publik ``` -2. Change into your new directory. +2. Change into your new directory. ```bash cd publik ``` -3. Use Yeoman and the Blockstack application generator to create your initial `publik` application. +3. Use Yeoman and the Blockstack application generator to create your initial + `publik` application. ```bash yo blockstack:react @@ -119,9 +123,10 @@ In this section, you build an initial React.js application called Publik. ? Are you ready to build a Blockstack app in React? (Y/n) ``` -4. Respond to the prompts to populate the initial app. +4. Respond to the prompts to populate the initial app. - After the process completes successfully, you see a prompt similar to the following: + After the process completes successfully, you see a prompt similar to the + following: ```bash [fsevents] Success: @@ -130,7 +135,7 @@ In this section, you build an initial React.js application called Publik. You should commit this file. added 1060 packages in 26.901s ``` -5. Run the initial application. +5. Run the initial application. ```bash npm start @@ -140,15 +145,15 @@ In this section, you build an initial React.js application called Publik. ![Network Connection](./images/network-connections.gif) -6. Choose **Allow**. +6. Choose **Allow**. -7. Open your browser to `http://localhost:8080`. +7. Open your browser to `http://localhost:8080`. - You should see a simple React app. + You should see a simple React app. - ![](images/initial-app.gif) + ![](images/initial-app.gif) -8. Choose **Sign In with Blockstack**. +8. Choose **Sign In with Blockstack**. The application tells you it will **Read your basic info**. @@ -177,7 +182,7 @@ Modify your authentication request to include the `publish_data` scope. } ``` -2. Modify the method to this: +3. Modify the method to this: ```javascript handleSignIn(e) { @@ -190,14 +195,14 @@ Modify your authentication request to include the `publish_data` scope. By default, authentication requests include the `store_write` scope which enables storage. This is what allows you to store information to Gaia. -3. Save your changes. -4. Go back to your app at `http://localhost:8080/`. -5. Log out and sign in again. +4. Save your changes. +5. Go back to your app at `http://localhost:8080/`. +6. Log out and sign in again. The authentication request now prompts the user for permission to **Publish data stored for the app**. - ![](images/publish-data-perm.png) + ![](images/publish-data-perm.png) ## Understand Gaia storage methods @@ -252,34 +257,37 @@ This design allows you to get only the files you need and avoid accidentally overwriting all lists. Further, you’re only updating the index file when you add or remove a grocery list; updating a list has no impact. - ## Add support for user status submission and lookup -In this step, you add three `blockstack.js` methods that support posting of "statuses". These are the `putFile()`, `getFile()`, and `lookupProfile()` methods. +In this step, you add three `blockstack.js` methods that support posting of +"statuses". These are the `putFile()`, `getFile()`, and `lookupProfile()` +methods. -1. Open the `src/components/Profile.jsx` file. +1. Open the `src/components/Profile.jsx` file. -2. Expand the `import from blockstack` statement with data methods. +2. Expand the `import from blockstack` statement with data methods. The `Person` object holds a Blockstack profile. Add `putFile`, `getFile`, and `lookupProfile` after `Person`. - When you are done, the import statement should look like the following: + When you are done, the import statement should look like the following: ```javascript import { - isSignInPending, - loadUserData, - Person, - getFile, - putFile, - lookupProfile + isSignInPending, + loadUserData, + Person, + getFile, + putFile, + lookupProfile } from 'blockstack'; ``` -3. Replace the `constructor()` initial state so that it holds the key properties required by the app. +3. Replace the `constructor()` initial state so that it holds the key + properties required by the app. - This code constructs a Blockstack `Person` object to hold the profile. Your constructor should look like this: + This code constructs a Blockstack `Person` object to hold the profile. Your + constructor should look like this: ```javascript constructor(props) { @@ -303,12 +311,12 @@ In this step, you add three `blockstack.js` methods that support posting of "sta } ``` +4) Locate the `render()` method. +5) Modify the `render()` method to add a text input and submit button to the + application. -4. Locate the `render()` method. -5. Modify the `render()` method to add a text input and submit button to the application. - - The following code echos the `person.name` and `person.avatarURL` - properties from the profile on the display: + The following code echos the `person.name` and `person.avatarURL` properties + from the profile on the display: ```javascript render() { @@ -367,14 +375,14 @@ In this step, you add three `blockstack.js` methods that support posting of "sta } ``` - This code allows the application to post statuses. It also displays the - user's Blockstack ID. To display this, your app must extract the ID from the - user profile data. + This code allows the application to post statuses. It also displays the + user's Blockstack ID. To display this, your app must extract the ID from the + user profile data. -6. Locate the `componentWillMount()` method. -7. Add the `username` property below the `person` property. +6) Locate the `componentWillMount()` method. +7) Add the `username` property below the `person` property. - You'll use the Blockstack `loadUserData()` method to access the `username`. + You'll use the Blockstack `loadUserData()` method to access the `username`. ```javascript @@ -426,37 +434,40 @@ In this step, you add three `blockstack.js` methods that support posting of "sta 9. Save the `Profile.jsk` file. - After the application compiles successfully, your application should appears as follows: + After the application compiles successfully, your application should appears + as follows: - ![](images/display-complete.png) + ![](images/display-complete.png) 10. Enter your status in the text box and press the **Submit** button. - At this point, nothing is blogged. In the next section you add code to display - the statuses back to the user as a blog entry. + At this point, nothing is blogged. In the next section you add code to + display the statuses back to the user as a blog entry. ## Fetch and display statuses Update `Profile.jsx` again. 1. Go back to the `render()` method. -2. Locate the `