Skip to content

Commit

Permalink
Merge pull request #16 from unfoldingWord/13-rename-usetagapi-hooks-t…
Browse files Browse the repository at this point in the history
…o-usetagclient

13 rename usetagapi hooks to usetagclient
  • Loading branch information
abelpz authored Jun 17, 2022
2 parents 97bfca7 + 6f6d46b commit a5c9d9b
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/documentation/AllOrgRepos.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ some of the examples below to play with these extra parameters.

```js
import React, { useEffect, useState } from 'react';
import { useAuthentication, useOrgApi } from 'dcs-react-hooks';
import { useAuthentication, useOrgClient } from 'dcs-react-hooks';
import ReactJson from 'react-json-view';

function Component(){
const { state: { token } } = useAuthentication({});
const [ repos, setRepos] = useState([])

const orgClient = useOrgApi({token});
const orgClient = useOrgClient({token});

// now get all the orgnizations
useEffect(async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/documentation/AllOrgs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ some of the examples below to play with these extra parameters.

```js
import React, { useEffect, useState } from 'react';
import { useAuthentication, useOrgApi } from 'dcs-react-hooks';
import { useAuthentication, useOrgClient } from 'dcs-react-hooks';
import ReactJson from 'react-json-view';

function Component(){
const { state: { token } } = useAuthentication({});
const [ orgs, setOrgs] = useState([])

const orgClient = useOrgApi({token});
const orgClient = useOrgClient({token});

// now get all the orgnizations
useEffect(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { AxiosInstance } from "axios";
* @param {string} config.token - Token needed to make secure requests.
* @param {string} config.basePath - basePath to make the request
*/
export function useOrgApi() {
export function useOrgClient() {
return <></>;
};

useOrgApi.propTypes = {
useOrgClient.propTypes = {
token: PropTypes.string,
basePath: PropTypes.string,
organizationClient: PropTypes.instanceOf(OrganizationApi),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# useOrgApi
# useOrgClient

```js
import React, { useEffect, useState } from 'react';
import { useOrgApi } from 'dcs-react-hooks';
import { useOrgClient } from 'dcs-react-hooks';
import ReactJson from 'react-json-view';

function Component(){
const orgClient = useOrgApi({ basePath: "https://qa.door43.org/api/v1/" });
const orgClient = useOrgClient({ basePath: "https://qa.door43.org/api/v1/" });
console.log("orgClient:", orgClient)
const [org, setOrg] = useState({});
useEffect(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { AxiosInstance } from "axios";
* @param {string} config.token - Token needed to make secure requests.
* @param {string} config.basePath - basePath to make the request
*/
export function useRepoApi() {
export function useRepoClient() {
return <></>;
};

useRepoApi.propTypes = {
useRepoClient.propTypes = {
token: PropTypes.string,
basePath: PropTypes.string,
repositoryClient: PropTypes.instanceOf(RepositoryApi),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# useRepoApi
# useRepoClient

@hook-description

```js
import React, { useEffect, useState } from 'react';
import { useRepoApi } from 'dcs-react-hooks';
import { useRepoClient } from 'dcs-react-hooks';
import ReactJson from 'react-json-view';

function Component(){
const repositoryClient = useRepoApi({ basePath: "https://qa.door43.org/api/v1/" });
const repositoryClient = useRepoClient({ basePath: "https://qa.door43.org/api/v1/" });

console.log(repositoryClient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { AxiosInstance } from "axios";
* @param {string} config.username - The username
* @param {string} config.password - The user password
*/
export function useUserApi() {
export function useUserClient() {
return <></>;
};

useUserApi.propTypes = {
useUserClient.propTypes = {
token: PropTypes.string,
basePath: PropTypes.string,
userClient: PropTypes.instanceOf(UserApi),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

```js
import React, { useEffect, useState } from 'react';
import { useUserApi } from 'dcs-react-hooks';
import { useUserClient } from 'dcs-react-hooks';
import ReactJson from 'react-json-view';

function Component(){
const userClient = useUserApi({basePath: "https://qa.door43.org/api/v1/"});
const userClient = useUserClient({basePath: "https://qa.door43.org/api/v1/"});
console.log(userClient);

const [user, setUser] = useState({});
Expand All @@ -33,15 +33,15 @@ function Component(){

```js
import React, { useEffect, useState } from 'react';
import { useUserApi } from 'dcs-react-hooks';
import { useUserClient } from 'dcs-react-hooks';
import ReactJson from 'react-json-view';

function Component(){
const [user, setUser] = useState({});
const [username, setUsername] = useState();
const [password, setPassword] = useState();

const userClient = useUserApi({basePath: "https://qa.door43.org/api/v1/", username, password});
const userClient = useUserClient({basePath: "https://qa.door43.org/api/v1/", username, password});
console.log(userClient);

useEffect(async () => {
Expand Down
10 changes: 0 additions & 10 deletions src/hooks/api/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/hooks/api/useApiConfig.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/hooks/calls/issues/useRepoIssues.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useState } from "react";
import useSWR from "swr";

import useIssuesApi from "../../api/useIssueApi";
import useIssuesApi from "../../clients/useIssueClient";

function useRepoIssues({
resource,
token,
args = {},
paged = false,
}) {
const issuesClient = useIssuesApi({ token });
const issuesClient = useIssuesClient({ token });
const [isLoading, setIsLoading] = useState(false);

function fetcher(owner, repo, defaultPage) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/issues/useUserIssues.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import PropTypes from "prop-types";
import React, { useState } from "react";
import useSWR from "swr";

import useIssuesApi from "../useIssuesApi";
import useIssuesApi from "../useIssuesClient";

function useUserIssues({
token,
args = {},
}) {
const issuesClient = useIssuesApi({ token });
const issuesClient = useIssuesClient({ token });
const { data, error, mutate } = useSWR(
token && [token, "user/issues"],
() => {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/calls/organization/useAllOrganizations.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import useSwr from 'swr';
import { useOrgApi } from '../../api/useOrgApi';
import { useOrgClient } from '../../clients/useOrgClient';
import { useAuthentication } from '../user/useAuthentication';

export function useAllOrganizations({ organizationClient, options, configuration, axios }) {
const { state: { token } } = useAuthentication({});
const _organizationClient = useOrgApi({organizationClient, token: token?.sha1, ...configuration, axios});

const _organizationClient = useOrgClient({organizationClient, token: token?.sha1, ...configuration, axios});

const fetchOrgs = () => {
const organizations = _organizationClient.orgGetAll().then(({ data }) => data);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/organization/useOrganization.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import useSwr from 'swr';
import { useOrgApi } from '../../api/useOrgApi';
import { useOrgClient } from '../../clients/useOrgClient';
import { useAuthentication } from '../user/useAuthentication';

export function useOrganization({ organizationName, organizationClient, options, configuration, axios }) {
const { state: { token } } = useAuthentication({});

const _organizationClient = useOrgApi({organizationClient, token: token?.sha1, ...configuration, axios});
const _organizationClient = useOrgClient({organizationClient, token: token?.sha1, ...configuration, axios});

const fetchOrg = () => {
const organization = _organizationClient.orgGet(organizationName).then(({ data }) => data);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/repository/useRepository.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import useSwr from 'swr';
import { useRepoApi } from '../../api/useRepoApi';
import { useRepoClient } from '../../clients/useRepoClient';

export function useRepository({ ownerName, repositoryName, repositoryClient, options, configuration, axios }) {

const _repositoryClient = useRepoApi({repositoryClient, ...configuration, axios});
const _repositoryClient = useRepoClient({ repositoryClient, ...configuration, axios });

const fetchRepo = () => {
const repository = _repositoryClient.repoGet(ownerName, repositoryName).then(({ data }) => data);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/user/useAuthentication.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect } from 'react';
import useSWRImmutable from 'swr/immutable'
import { useUserApi } from "../../api/useUserApi";
import { useUserClient } from "../../clients/useUserClient";

export function useAuthentication({tokenName, username, password, userClient, options, configuration, axios}) {
const _userClient = useUserApi({ userClient, username, password, ...configuration, axios});
const _userClient = useUserClient({ userClient, username, password, ...configuration, axios});

//Fetch function to get token and delete old ones
const fetchAuth = async (username) => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/user/useLogin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useState } from "react";
import useSWR from "swr";

import { useUserApi } from "../../api/useUserApi";
import { useUserApi } from "../../clients/useUserClient";

export default function useLogin({tokenId}) {
const [username, setUsername] = useState(undefined);
const [password, setPassword] = useState(undefined);
const userClient = useUserApi({ username, password });
const userClient = useUserClient({ username, password });

const fetchAuth = async (username) => {
const allTokens = await userClient
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/user/useUser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from "react";
import useSWR from "swr";

import useUserApi from "../../api/useUserApi";
import useUserApi from "../../clients/useUserClient";

export default function useUser({ username, password }) {
const userClient = useUserApi({ username, password });
const userClient = useUserClient({ username, password });

const fetchUser = () => {
const user = userClient.userGetCurrent().then(({ data }) => data);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/calls/user/useUserOrganizations.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import useSwr from 'swr';
import { useOrgApi } from '../../api/useOrgApi';
import { useOrgClient } from '../../clients/useOrgClient';
import { useAuthentication } from '../user/useAuthentication';

export function useUserOrganizations({ username, organizationClient, options, configuration, axios }) {
const { state: { token } } = useAuthentication({});

const _organizationClient = useOrgApi({organizationClient, token: token?.sha1, ...configuration, axios});
const _organizationClient = useOrgClient({ organizationClient, token: token?.sha1, ...configuration, axios });

const fetchUserOrg = () => {
let orgList = [];
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/clients/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from "./useAdminClient"
export * from "./useDcsClient"
export * from "./useIssueClient"
export * from "./useMiscellaneousClient"
export * from "./useNotificationClient"
export * from "./useOrgClient"
export * from "./useRepoClient"
export * from "./useSettingsClient"
export * from "./useUserClient"
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AdminApi } from "dcs-js";
import { useApiConfig } from "./useApiConfig";
import { getApiConfig } from "../../helpers/api";

/**
* Uses DCS admin API.
* @param {string} token - Token needed to make secure requests.
*/
export const useAdminApi = ({ token }) => {
const config = useApiConfig({ token });
export const useAdminClient = ({ token }) => {
const config = getApiConfig({ token });
const AdminClient = new AdminApi(config);
return AdminClient;
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useApiConfig } from "./useApiConfig";
import { getApiConfig } from "../../helpers/api";

/**
* Uses DCS issues API.
* @param {string} token - Token needed to make secure requests.
*/
export const useDcsApi = ({ token, Class }) => {
const config = useApiConfig({ token });
export const useDcsClient = ({ token, Class }) => {
const config = getApiConfig({ token });
const client = Class ? new Class(config) : null;
return client;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IssueApi } from "dcs-js";
import { useApiConfig } from "./useApiConfig";
import { getApiConfig } from "../../helpers/api";

/**
* Uses DCS issue API.
* @param {string} token - Token needed to make secure requests.
*/
export const useIssuesApi = ({ token }) => {
const config = useApiConfig({ token });
export const useIssuesClient = ({ token }) => {
const config = getApiConfig({ token });
const issueClient = new IssueApi(config);
return issueClient;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MiscellaneousApi } from "dcs-js";
import { useApiConfig } from "./useApiConfig";
import { getApiConfig } from "../../helpers/api";

/**
* Uses DCS Miscellaneous API.
* @param {string} token - Token needed to make secure requests.
*/
export const useMiscellaneousApi = ({ token }) => {
const config = useApiConfig({ token });
export const useMiscellaneousClient = ({ token }) => {
const config = getApiConfig({ token });
const MiscellaneousClient = new MiscellaneousApi(config);
return MiscellaneousClient;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NotificationApi } from "dcs-js";
import { useApiConfig } from "./useApiConfig";
import { getApiConfig } from "../../helpers/api";

/**
* Uses DCS Notification API.
* @param {string} token - Token needed to make secure requests.
*/
export const useNotificationApi = ({ token }) => {
const config = useApiConfig({ token });
export const useNotificationClient = ({ token }) => {
const config = getApiConfig({ token });
const NotificationClient = new NotificationApi(config);
return NotificationClient;
};
Loading

0 comments on commit a5c9d9b

Please sign in to comment.