<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hayk Adamyan</title>
    <description>The latest articles on DEV Community by Hayk Adamyan (@haykadamyan).</description>
    <link>https://dev.to/haykadamyan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F132504%2F09f1c334-4b44-4937-b01f-ada23604a6cc.jpeg</url>
      <title>DEV Community: Hayk Adamyan</title>
      <link>https://dev.to/haykadamyan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/haykadamyan"/>
    <language>en</language>
    <item>
      <title>How to Build a Location-based Twitter Search App with React and Cosmic JS</title>
      <dc:creator>Hayk Adamyan</dc:creator>
      <pubDate>Wed, 30 Jan 2019 11:58:42 +0000</pubDate>
      <link>https://dev.to/haykadamyan/how-to-build-a-location-based-twitter-search-app-with-react-and-cosmic-js-4inj</link>
      <guid>https://dev.to/haykadamyan/how-to-build-a-location-based-twitter-search-app-with-react-and-cosmic-js-4inj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UM4hkged--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cosmic-s3.imgix.net/15012da0-1ff8-11e9-8b75-9b9c29c68edc-tweets-by-location.png%3Fw%3D1000" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UM4hkged--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cosmic-s3.imgix.net/15012da0-1ff8-11e9-8b75-9b9c29c68edc-tweets-by-location.png%3Fw%3D1000" alt="Background Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Tweets by location
&lt;/h1&gt;

&lt;p&gt;Hi, In this tutorial, we are going to create an application that filters twitter tweets by location using &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; and &lt;a href="https://cosmicjs.com/"&gt;Cosmic JS&lt;/a&gt;. We will be using &lt;a href="https://www.npmjs.com/package/cosmicjs"&gt;Cosmic JS npm package&lt;/a&gt; for the implementation of the basic CRUD system in our application. Let's get started.&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://search-tweets-by-location.cosmicapp1.co/"&gt;View the Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/haykadamyan/tweet-locator"&gt;Download the GitHub repo&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;You will be required to install &lt;a href="https://nodejs.org/en/"&gt;Node JS&lt;/a&gt; and &lt;a href="https://www.npmjs.com/"&gt;NPM&lt;/a&gt; before starting. Make sure you already have them.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;
&lt;h4&gt;
  
  
  Doing everything using the existing git repo
&lt;/h4&gt;

&lt;p&gt;First of all, you have to be sure you have node &amp;gt; 8.x:&lt;br&gt;
As our application uses external APIs, such as &lt;a href="https://cosmicjs.com/"&gt;Cosmic JS&lt;/a&gt;, &lt;a href="https://developers.google.com/gmail/api/"&gt;Gmail API&lt;/a&gt; and &lt;a href="https://developer.twitter.com/en/docs.html"&gt;Twitter API&lt;/a&gt; we have to set the environment variables for these APIs.&lt;br&gt;
Note you will have to create API keys in the services mentioned above to put the "KEYS" in the &lt;code&gt;.env&lt;/code&gt; file. &lt;br&gt;
Here is how your &lt;code&gt;.env&lt;/code&gt; file has to look like.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;After setting up the &lt;code&gt;.env&lt;/code&gt;file we have to run the following commands.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;After the successfull completion of the last command browser window will automatically open, and the &lt;code&gt;package.json&lt;/code&gt; will look like this.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now the app has to be running on &lt;code&gt;http://localhost:3000&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Congratulations!!!
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Source code
&lt;/h1&gt;

&lt;h5&gt;
  
  
  Server.js
&lt;/h5&gt;

&lt;p&gt;Now it's time to understand how the magic works. &lt;br&gt;
Let's take a look at &lt;code&gt;server.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Nothing special in this code, unless we take a look at the line &lt;strong&gt;14&lt;/strong&gt;. Here we setup the endpoint for the twitter API requests, and prepare the standart request body. &lt;br&gt;
More about this at &lt;a href="https://developer.twitter.com/en/docs.html"&gt;Twitter API Documentation&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Pages/index.js
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;pages/index.js&lt;/code&gt; is our home page file, where we have our UI, and the requests to the API's we use.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h6&gt;
  
  
  Important functions
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;onChangeLocation - calls &lt;strong&gt;search&lt;/strong&gt; function when we select a location on the map&lt;/li&gt;
&lt;li&gt;search - Sends request to the Twitter API and receives the tweets in the choosen location&lt;/li&gt;
&lt;li&gt;componentDidMount - Loads the most popular search topics through &lt;a href="https://cosmicjs.com/"&gt;Cosmic JS&lt;/a&gt; API&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Lib/cosmic.js
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;lib/comsic.js&lt;/code&gt;  is the file where our code of relations with Buckets has been hosted.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h6&gt;
  
  
  Important functions
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;  getSearchHistory - returns the history of the searches that were done&lt;/li&gt;
&lt;li&gt;  addHistory - checks if we have that topic searched before, if yes we make the popularity rank of the topic higher in our db, if not we add it there with the popularity rank 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Lib/twitter.js
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;lib/twitter.js&lt;/code&gt;  is the file where our code for &lt;a href="https://developer.twitter.com/en/docs.html"&gt;Twitter API&lt;/a&gt; is hosted.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h6&gt;
  
  
  Important functions
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;searchTweets - sends a search request to the &lt;a href="https://developer.twitter.com/en/docs.html"&gt;Twitter API&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this tutorial we've learned how to build an app that filters twitter tweets by location using &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; and &lt;a href="https://cosmicjs.com/"&gt;Cosmic JS&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>cosmicjs</category>
    </item>
  </channel>
</rss>
