npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coursework-helper-ui

v1.1.0

Published

A UI & hooks library for CodeYourFuture coursework helper

Downloads

5

Readme

Collection of utils for coursework-helper

The repository contains a collection of utils for interacting with coursework-helper backend.

Usage

npm

npm install coursework-helper-ui

yarn

yarn add coursework-helper-ui

Components

RedirectWithTimeout

Redirects to the specified path after the specified timeout.

import {RedirectWithTimeout} from 'coursework-helper-ui';

const MyComponent = () => {
  return (
    <div>
      {/* Redirect to "/dashboard" after 5 seconds */}
      <RedirectWithTimeout to="/dashboard" timeoutSeconds={5} />
    </div>
  );
};

SignInButton

Sign in button for Github OAuth. The button uses useAuthentication hook internally.

import { SignInButton } from 'coursework-helper-ui';

const MyComponent = () => {
  // Replace 'YOUR_CLIENT_ID' and 'YOUR_API_URL' with your actual values
  const clientId = 'YOUR_CLIENT_ID';
  const apiUrl = 'YOUR_API_URL';

  // Optionally, you can define additional scopes for GitHub OAuth
  const scopes = ['user', 'public_repo'];

  return (
    <div>
      {/* Render the sign-in button with custom class names */}
      <SignInButton
        clientId={clientId}
        apiUrl={apiUrl}
        scopes={['user', 'read:org']}
        classNames={{
          signInButton: 'custom-sign-in-btn',
          signOutButton: 'custom-sign-out-btn',
        }}
      />
    </div>
  );
};

Hooks

useAuthentication

The useAuthentication hook is a custom React hook that facilitates handling authentication for your application. It allows you to manage the user's authentication state, store authentication tokens in local storage, and perform the authentication process with an API.

This hook must also be present on /auth page of your application. It will handle the authentication process and redirect the user back to the application.

import { useAuthentication } from 'coursework-helper-ui';

const MyComponent = () => {
  const apiURL = 'YOUR_API_URL';
  const { token, loading, error, isAuthenticated, signOut, redirectPath } = useAuthentication(apiURL);

  return (
    <div>
      {loading ? <div>Loading...</div> : null}

      {isAuthenticated ? (
        <>
          <div>Welcome, User!</div>
          <button onClick={signOut}>Sign Out</button>
        </>
      ) : (
        <div>Please sign in</div>
      )}

      {error && <div>Error: {error}</div>}
    </div>
  );
};

useCloneMutation

The useCloneMutation hook is a custom React hook that facilitates cloning issues from GitHub. It allows you to manage the cloning state and perform the cloning process with an API. It

import { useCloneMutation } from 'coursework-helper-ui';

const CloneButton = () => {
  const apiURL = 'YOUR_API_URL';
  const accessToken = 'YOUR_ACCESS_TOKEN';
  const module = 'YOUR_MODULE_NAME'; // this is github repo name
  const sprint = 'YOUR_SPRINT_NAME'; // Optional: Omit if not required
  const issueNumber = 1234; // Optional: Omit if not required

  const { loading, error, success, clone } = useCloneMutation(apiURL, accessToken, module, sprint, issueNumber);

  return (
    <div>
      <button onClick={clone} disabled={loading}>
        {loading ? 'Cloning...' : 'Clone Issue'}
      </button>

      {error && <div>Error: {error}</div>}

      {success && <div>{success.total} issues cloned!</div>}
    </div>
  );
};

useIssues

The useIssues hook is a custom React hook that facilitates fetching issues from GitHub. It allows you to manage the issues state and perform the fetching process with an API. It

import { useIssues } from 'coursework-helper-ui';

const YourComponent = () => {
  const apiURL = ''; // Replace with your API base URL
  const module = 'your-repo-name'; // Replace with the name of your module/repository

  const { data, loading, error, reFetch } = useIssues(apiURL, module);

  // Your component logic using the fetched data, loading, and error states
};

Functions

cloneIssue

This function is used to clone GitHub issues from a specified module/repository using the GitHub API. It allows cloning a specific issue or cloning all issues related to a sprint, if the sprint parameter is provided.

import { cloneIssue } from 'coursework-helper-ui';

const apiURL = "https://api.example.com";
const token = "YOUR_GITHUB_API_TOKEN";
const module = "example-module";
const issueNumber = 42;
const sprintName = "Sprint 1";

cloneIssue(apiURL, token, module, sprintName, issueNumber)
  .then((data) => {
    console.log("Successfully cloned issue:", data);
  })
  .catch((error) => {
    console.error("Error cloning issue:", error.message);
  });