diff options
| author | Ivan Chen <ivan@thetaggid.com> | 2021-01-12 12:38:46 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-12 12:38:46 -0500 |
| commit | 6892c63b899b46fedc9d99b8274a17e9043fe361 (patch) | |
| tree | 454d836c5848b4d9b2e082ae19e4e64679ccd49d /src/services | |
| parent | d955c6bc31be3b2e3e289a8dec8b5970251d4090 (diff) | |
[TMA-527/506/523] Custom Moment Categories (#174)
* changed logic to allow ≥ 1 categories
* now using array of strings for moment categories
* updated error strings
* formatting and check for picker cancellation
* initial UI done
* cleaned up logic, added custom icon
* renamed onboarding stack to match main stack
* removed unused import
* deterministic color picker
* custom category defaults to selected instead of added
* removed function in route
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/MomentCategoryService.ts | 43 |
1 files changed, 6 insertions, 37 deletions
diff --git a/src/services/MomentCategoryService.ts b/src/services/MomentCategoryService.ts index 8bdb70d2..32c721ae 100644 --- a/src/services/MomentCategoryService.ts +++ b/src/services/MomentCategoryService.ts @@ -1,12 +1,11 @@ import {Alert} from 'react-native'; -import {MomentCategoryType} from './../types/types'; import {MOMENT_CATEGORY_ENDPOINT} from '../constants'; export const loadMomentCategories: ( userId: string, token: string, -) => Promise<MomentCategoryType[]> = async (userId, token) => { - let categories: MomentCategoryType[] = []; +) => Promise<string[]> = async (userId, token) => { + let categories: string[] = []; try { const response = await fetch(MOMENT_CATEGORY_ENDPOINT + `${userId}/`, { method: 'GET', @@ -17,7 +16,7 @@ export const loadMomentCategories: ( const status = response.status; if (status === 200) { const data = await response.json(); - categories = data['categories']; + categories = data.categories; } else { console.log('Could not load categories!'); return []; @@ -30,7 +29,7 @@ export const loadMomentCategories: ( }; export const postMomentCategories: ( - categories: Array<MomentCategoryType>, + categories: string[], token: string, ) => Promise<boolean> = async (categories, token) => { let success = false; @@ -47,38 +46,8 @@ export const postMomentCategories: ( if (status === 200) { success = true; } else { - Alert.alert('There was a problem creating categories!'); - console.log('Could not post categories!'); - } - } catch (err) { - console.log(err); - return success; - } - return success; -}; - -export const deleteMomentCategories: ( - categories: Array<MomentCategoryType>, - userId: string, - token: string, -) => Promise<boolean> = async (categories, userId, token) => { - let success = false; - try { - const response = await fetch(MOMENT_CATEGORY_ENDPOINT + `${userId}/`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - Authorization: 'Token ' + token, - }, - body: JSON.stringify({categories}), - }); - const status = response.status; - if (status === 200) { - Alert.alert(`The category was successfully deleted!`); - success = true; - } else { - Alert.alert('There was a problem while deleteing category!'); - console.log('Could not delete category!'); + Alert.alert('There was a problem updating categories!'); + console.log('Unable to update categories'); } } catch (err) { console.log(err); |
