Restructure repository (#426)

organized repository 

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Co-authored-by: Philip Molares <git@molar.es>
This commit is contained in:
mrdrogdrog 2020-08-16 16:02:26 +02:00 committed by GitHub
parent 66258ca615
commit 0fadc09f2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
254 changed files with 384 additions and 403 deletions

View file

@ -1,6 +1,5 @@
import { RegisterError } from '../components/landing/pages/register/register'
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
import { defaultFetchConfig } from './default'
import { RegisterError } from '../../components/register-page/register-page'
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
export const doInternalLogin = async (username: string, password: string): Promise<void> => {
const response = await fetch(getApiUrl() + '/auth/internal', {

View file

@ -1,5 +1,4 @@
import { expectResponseCode, getApiUrl } from '../../utils/apiUtils'
import { defaultFetchConfig } from '../default'
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
import { Config } from './types'
export const getConfig = async (): Promise<Config> => {

View file

@ -1,10 +0,0 @@
export const defaultFetchConfig: Partial<RequestInit> = {
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer'
}

View file

@ -1,6 +1,6 @@
import { HistoryEntry } from '../components/landing/pages/history/history'
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
import { defaultFetchConfig } from './default'
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
import { HistoryEntry } from '../../components/history-page/history-page'
export const getHistory = async (): Promise<HistoryEntry[]> => {
const response = await fetch(getApiUrl() + '/history')

View file

@ -1,6 +1,5 @@
import { LoginProvider } from '../redux/user/types'
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
import { defaultFetchConfig } from './default'
import { LoginProvider } from '../../redux/user/types'
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
export const getMe = async (): Promise<meResponse> => {
const response = await fetch(getApiUrl() + '/me', {

View file

@ -1,6 +1,5 @@
import { ImageProxyResponse } from '../components/editor/markdown-renderer/replace-components/image/types'
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
import { defaultFetchConfig } from './default'
import { ImageProxyResponse } from '../../components/markdown-renderer/replace-components/image/types'
import { expectResponseCode, getApiUrl, defaultFetchConfig } from '../utils'
export const getProxiedUrl = async (imageUrl: string): Promise<ImageProxyResponse> => {
const response = await fetch(getApiUrl() + '/media/proxy', {

View file

@ -1,5 +1,4 @@
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
import { defaultFetchConfig } from './default'
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
interface LastChange {
userId: string

22
src/api/utils.ts Normal file
View file

@ -0,0 +1,22 @@
import { store } from '../redux'
export const defaultFetchConfig: Partial<RequestInit> = {
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer'
}
export const getApiUrl = (): string => {
return store.getState().apiUrl.apiUrl
}
export const expectResponseCode = (response: Response, code = 200): void => {
if (response.status !== code) {
throw new Error(`response code is not ${code}`)
}
}