Giter Site home page Giter Site logo

stellashen / my-galaxy Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 530 KB

:milky_way: :stars: GitHub stars manager using React, Redux, GraphQL, Apollo Client, Rails. A simplistic tool to help you increase efficiency of running your galaxy.

Home Page: https://my-galaxy.herokuapp.com

JavaScript 41.17% HTML 8.62% Ruby 40.25% CoffeeScript 0.53% CSS 9.43%

my-galaxy's Introduction

My Galaxy - GitHub Stars Manager

Live Site

My Galaxy is a web application that aims to help you manage your GitHub stars:

  • View repositories you have starred,
  • search for new repositories,
  • star/unstar repositories,
  • and open README in the right viewer

Table of Contents

Technologies

  • Rails 5: A server-side web application framework written in Ruby
  • React: A JavaScript library for building user interfaces
  • Redux: A JavaScript library for managing application state.
  • GitHub GraphQL API: This is an OAuth app calling GitHub's GraphQL API
  • Apollo Client: use GraphQL to build client applications
  • Radium: Inline styling library

Screenshots

Before login:

Login with Github:

After login:

  1. "My Starred Repos" page: view your stars

  1. "Explore" page: search and star/unstar repositories

How To Use

First, you need to have a GitHub account.

Go to Live Site and click "Sign In with Github" button, you will be redirected to authorize My Galaxy to access your user info, public repository and gists. Enter your credentials and authorize. - Hooray you are in!

Then you can:

  1. View your starred repositories.

  2. Search for new repositories.

  3. Star/unstar repositories.

  4. Click a repository to view its README directly on the right side. This way, you can browse through all your repos on one page, so you don't need to open 30 new tabs any more.

MVP List

  1. Host on Heroku and Create OAuth App

  2. Authentication

  3. Get starred repositories

  • run query to get current user's starred repositories
  • display starred repositories
  • implement cursor-based pagination
  1. Unstar repositories
  • run mutation to unstar a starred repository
  • unstarred repository will disappear from page
  1. Search for and star new repositories
  • search by keyword
  • run mutation to star/unstar a repository
  1. Open README in the right viewer
  • click a repository to view its README.md in the right viewer

Technical Details

1 GitHub OAuth

Refered to this article: How to Create a React App with Ruby on Rails

I created two apps for local development and production.

development

For local development, set the callback url to http://localhost:3000/auth/github/callback

In the terminal, run rails secret to generate a new secret key.

Create /config/local_env.yml file and add it to .gitignore. Store local environment variables:

GITHUB_CLIENT_ID: 'replace with dev app id'
GITHUB_CLIENT_SECRET: 'dev app secret'
SECRET_KEY_BASE: 'new secret key'

In config/secrets.yml, add github_client_id and github_client_secret:

development:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  github_client_id: <%= ENV["GITHUB_CLIENT_ID"] %>
  github_client_secret: <%= ENV["GITHUB_CLIENT_SECRET"] %>
production

For production, set to https://my-galaxy.herokuapp.com/auth/github/callback

In config/secrets.yml, add github_client_id and github_client_secret:

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  github_client_id: <%= ENV["GITHUB_CLIENT_ID"] %>
  github_client_secret: <%= ENV["GITHUB_CLIENT_SECRET"] %>

After registering an app with home url https://my-galaxy.herokuapp.com/, get id and secret from its settings page.

In terminal, run:

heroku config:add GITHUB_CLIENT_ID='replace with production app id' GITHUB_CLIENT_SECRET='production app secret'

2 GraphQL query and mutation

To get starred repositories:

const GET_STARS = gql`
  query Stars($afterCursor: String) {
    viewer {
      starredRepositories(
        first: 50
        after: $afterCursor
        orderBy: { field: STARRED_AT, direction: DESC }
      ) {
        totalCount
        pageInfo {
          endCursor
          hasNextPage
        }
        edges {
          cursor
          starredAt
          node {
            id
            name
            owner {
              id
              login
            }
            description
            url
            primaryLanguage {
              id
              name
              color
            }
            stargazers {
              totalCount
            }
            forkCount
            viewerHasStarred
            repositoryTopics(first: 20) {
              edges {
                node {
                  topic {
                    id
                    name
                  }
                }
              }
            }

          }
        }
      }
    }
  }
`;

To unstar a starred repository:

const UNSTAR_REPOSITORY = gql`
  mutation($id: ID!) {
    removeStar(input: { starrableId: $id }) {
      starrable {
        id
        viewerHasStarred
      }
    }
  }
`;

To search among all repos on GitHub:

const SEARCH_REPOS = gql`
  query Search($keyword: String!, $afterCursor: String) {
    search(query: $keyword, type: REPOSITORY, first: 50, after: $afterCursor) {
      repositoryCount
      pageInfo {
        endCursor
        hasNextPage
      }
      edges {
        cursor
        node {
          ... on Repository {
            id
            name
            owner {
              id
              login
            }
            descriptionHTML
            url
            updatedAt
            primaryLanguage {
              id
              name
              color
            }
            stargazers {
              totalCount
            }
            forkCount
            viewerHasStarred
            repositoryTopics(first: 20) {
              edges {
                node {
                  topic {
                    id
                    name
                  }
                }
              }
            }
          }
        }
      }
    }
  }
`;

Images Source

Zoltan Tasi https://unsplash.com/photos/n8HAQ26GnMc

Muchmoji https://giphy.com/stickers/space-travel-39pqRFi5Gw0MpGug0w

References

A complete React with Apollo and GraphQL Tutorial

Pagination | Apollo Client

react-apollo-client-pagination-example

How to search with Github GraphQL

Regex Cheat Sheet

my-galaxy's People

Contributors

stellashen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.