From 4ad4414e0885564e1df48872c22f2e76651c0c19 Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 27 May 2022 11:38:01 -0400 Subject: [PATCH] Convert about action to TypeScript --- .../{about-test.js => about.test.ts} | 0 app/soapbox/actions/about.js | 19 ------------ app/soapbox/actions/about.ts | 29 +++++++++++++++++++ 3 files changed, 29 insertions(+), 19 deletions(-) rename app/soapbox/actions/__tests__/{about-test.js => about.test.ts} (100%) delete mode 100644 app/soapbox/actions/about.js create mode 100644 app/soapbox/actions/about.ts diff --git a/app/soapbox/actions/__tests__/about-test.js b/app/soapbox/actions/__tests__/about.test.ts similarity index 100% rename from app/soapbox/actions/__tests__/about-test.js rename to app/soapbox/actions/__tests__/about.test.ts diff --git a/app/soapbox/actions/about.js b/app/soapbox/actions/about.js deleted file mode 100644 index 86be6beb4..000000000 --- a/app/soapbox/actions/about.js +++ /dev/null @@ -1,19 +0,0 @@ -import { staticClient } from '../api'; - -export const FETCH_ABOUT_PAGE_REQUEST = 'FETCH_ABOUT_PAGE_REQUEST'; -export const FETCH_ABOUT_PAGE_SUCCESS = 'FETCH_ABOUT_PAGE_SUCCESS'; -export const FETCH_ABOUT_PAGE_FAIL = 'FETCH_ABOUT_PAGE_FAIL'; - -export function fetchAboutPage(slug = 'index', locale) { - return (dispatch, getState) => { - dispatch({ type: FETCH_ABOUT_PAGE_REQUEST, slug, locale }); - const filename = `${slug}${locale ? `.${locale}` : ''}.html`; - return staticClient.get(`/instance/about/${filename}`).then(({ data: html }) => { - dispatch({ type: FETCH_ABOUT_PAGE_SUCCESS, slug, locale, html }); - return html; - }).catch(error => { - dispatch({ type: FETCH_ABOUT_PAGE_FAIL, slug, locale, error }); - throw error; - }); - }; -} diff --git a/app/soapbox/actions/about.ts b/app/soapbox/actions/about.ts new file mode 100644 index 000000000..37713c401 --- /dev/null +++ b/app/soapbox/actions/about.ts @@ -0,0 +1,29 @@ +import { AnyAction } from 'redux'; + +import { staticClient } from '../api'; + +const FETCH_ABOUT_PAGE_REQUEST = 'FETCH_ABOUT_PAGE_REQUEST'; +const FETCH_ABOUT_PAGE_SUCCESS = 'FETCH_ABOUT_PAGE_SUCCESS'; +const FETCH_ABOUT_PAGE_FAIL = 'FETCH_ABOUT_PAGE_FAIL'; + +const fetchAboutPage = (slug = 'index', locale?: string) => (dispatch: React.Dispatch, getState: any) => { + dispatch({ type: FETCH_ABOUT_PAGE_REQUEST, slug, locale }); + + const filename = `${slug}${locale ? `.${locale}` : ''}.html`; + return staticClient.get(`/instance/about/${filename}`) + .then(({ data: html }) => { + dispatch({ type: FETCH_ABOUT_PAGE_SUCCESS, slug, locale, html }); + return html; + }) + .catch(error => { + dispatch({ type: FETCH_ABOUT_PAGE_FAIL, slug, locale, error }); + throw error; + }); +}; + +export { + fetchAboutPage, + FETCH_ABOUT_PAGE_REQUEST, + FETCH_ABOUT_PAGE_SUCCESS, + FETCH_ABOUT_PAGE_FAIL, +};