diff --git a/src/components/pages/profile/settings.js b/src/components/pages/profile/settings.js index e44fcd8..1c57648 100644 --- a/src/components/pages/profile/settings.js +++ b/src/components/pages/profile/settings.js @@ -13,6 +13,7 @@ import { import AsyncStorage from "@react-native-async-storage/async-storage"; import { withoutHTML } from "src/interface/rendering"; +import * as requests from "src/requests"; import { ScreenWithBackBarJsx } from "src/components/navigation/navigators"; @@ -46,184 +47,235 @@ const SettingsJsx = (props) => { // Use Context to get this stuff eventually profile: TEST_PROFILE, newProfile: TEST_PROFILE, + loaded: false, }); const fields = state.newProfile.fields; + const _handleLogout = async () => { + await requests.postForm( + `https://${state.instance}/oauth/revoke`, + { + client_id: state.appObject.client_id, + client_secret: state.appObject.client_secret, + token: state.token.access_token, + } + ); + + await AsyncStorage.multiRemove([ + "@user_profile", + "@user_notifications", + "@user_instance", + "@user_token", + ]); + + props.navigation.navigate("Authenticate"); + }; + + useEffect(() => { + AsyncStorage + .multiGet([ + "@user_profile", + "@user_instance", + "@user_token", + "@app_object", + ]) + .then(([profilePair, instancePair, tokenPair, appPair]) => + [ + JSON.parse(profilePair[1]), + instancePair[1], + JSON.parse(tokenPair[1]), + JSON.parse(appPair[1]), + ] + ) + .then(([profile, instance, token, appObject]) => { + let newProfile = profile; + newProfile.fields = newProfile.fields == null + ? [] + : newProfile.fields; + + setState({...state, + profile: profile, + newProfile: newProfile, + instance: instance, + appObject: appObject, + token: token, + loaded: true, + }) + }); + }, []); + return ( - - - - - - Change profile photo - - - - - Display name - { - setState({...state, - newProfile: {...state.newProfile, display_name: value} - }); - } - }/> + <> + { state.loaded + ? + + + + + Change profile photo + + + + + Display name + { + setState({...state, + newProfile: {...state.newProfile, display_name: value} + }); + } + }/> - User name - { - setState({...state, - newProfile: {...state.newProfile, username: value} - }); - } - }/> + User name + { + setState({...state, + newProfile: {...state.newProfile, username: value} + }); + } + }/> - Bio - { - setState({...state, - newProfile: {...state.newProfile, note: value} - }); - } - }/> - { - fields.map((field, i) => - - { - let newFields; - if (fields.length == 1) { - newFields = [{ name: "", value: "" }]; - } else { - newFields = state.newProfile.fields; - newFields.splice(i, 1); - } + Bio + { + setState({...state, + newProfile: {...state.newProfile, note: value} + }); + } + }/> + { + fields.map((field, i) => + + { + let newFields; + if (fields.length == 1) { + newFields = [{ name: "", value: "" }]; + } else { + newFields = state.newProfile.fields; + newFields.splice(i, 1); + } - setState({...state, - newProfile: {...state.newProfile, - fields: newFields, - }, - }); - } + setState({...state, + newProfile: {...state.newProfile, + fields: newFields, + }, + }); + } + }> + + + + Name + { + let newFields = fields; + newFields[i] = {...newFields[i], + name: text, + }; + + setState({...state, + newProfile: {...state.newProfile, + fields: newFields, + }, + }); + } + } /> + + + Value + { + let newFields = fields; + newFields[i] = {...newFields[i], + value: text, + }; + + setState({...state, + newProfile: {...state.newProfile, + fields: newFields, + }, + }); + } + } /> + + + ) + } + { + setState({...state, + newProfile: {...state.newProfile, + fields: state.newProfile.fields.concat({ name: "", value: ""}), + }, + }); + } + }> + + + + Save Profile + + + - - - - Name - { - let newFields = fields; - newFields[i] = {...newFields[i], - name: text, - }; - - setState({...state, - newProfile: {...state.newProfile, - fields: newFields, - }, - }); - } - } /> - - - Value - { - let newFields = fields; - newFields[i] = {...newFields[i], - value: text, - }; - - setState({...state, - newProfile: {...state.newProfile, - fields: newFields, - }, - }); - } - } /> - - - ) - } - { - setState({...state, - newProfile: {...state.newProfile, - fields: state.newProfile.fields.concat({ name: "", value: ""}), - }, - }); - } - }> - - - - Save Profile - - { - AsyncStorage.multiRemove( - ["@user_profile", "@user_notifications"] - ).then(() => { - props.navigation.navigate("Authenticate"); - }); - } - }> - - Log out - - - - + Log out + + + + + : <> + } + ); };