Polished apis

This commit is contained in:
toledo 2023-04-08 16:24:15 +08:00
parent 11a22403da
commit 958e62d733
4 changed files with 88 additions and 163 deletions

175
package-lock.json generated
View file

@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@expo/webpack-config": "^18.0.1", "@expo/webpack-config": "^18.0.1",
"@react-native-async-storage/async-storage": "^1.18.1",
"@react-navigation/drawer": "^6.6.2", "@react-navigation/drawer": "^6.6.2",
"@react-navigation/native": "^6.1.6", "@react-navigation/native": "^6.1.6",
"@reduxjs/toolkit": "^1.9.3", "@reduxjs/toolkit": "^1.9.3",
@ -2815,13 +2816,13 @@
"integrity": "sha512-TI+l71+5aSKnShYclFa14Kum+hQMZ86b95SH6tQUG3qZEmLTarvWpKwqtTwQKqvlJSJrpFiSFu3eCuZokY6zWA==" "integrity": "sha512-TI+l71+5aSKnShYclFa14Kum+hQMZ86b95SH6tQUG3qZEmLTarvWpKwqtTwQKqvlJSJrpFiSFu3eCuZokY6zWA=="
}, },
"node_modules/@expo/webpack-config": { "node_modules/@expo/webpack-config": {
"version": "18.0.1", "version": "18.0.3",
"resolved": "https://registry.npmjs.org/@expo/webpack-config/-/webpack-config-18.0.1.tgz", "resolved": "https://registry.npmjs.org/@expo/webpack-config/-/webpack-config-18.0.3.tgz",
"integrity": "sha512-0C+wjmmQ0usySdhtzeRp0yYuf9zkUZ/kNgA6AHQ9N7eG4JIr0DM1c87g119smxcJTbd8N+//mv5znPxSJqBqmg==", "integrity": "sha512-/1sg+hDtvSQCEWDP6J+3yM3+SGcUiUinX/JarBTsH8MudvzeUmZgsI8IxRFYGfUPYUkwJ5e57eHQzadj0taeHQ==",
"dependencies": { "dependencies": {
"@babel/core": "^7.16.0", "@babel/core": "^7.20.2",
"@expo/config": "6.0.20", "@expo/config": "6.0.20",
"babel-loader": "^8.2.3", "babel-loader": "^8.3.0",
"chalk": "^4.0.0", "chalk": "^4.0.0",
"clean-webpack-plugin": "^4.0.0", "clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^10.2.0", "copy-webpack-plugin": "^10.2.0",
@ -3737,6 +3738,17 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/@react-native-async-storage/async-storage": {
"version": "1.18.1",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.18.1.tgz",
"integrity": "sha512-70aFW8fVCKl+oA1AKPFDpE6s4t9pulj2QeLX+MabEmzfT3urd/3cckv45WJvtocdoIH/oXA3Y+YcCRJCcNa8mA==",
"dependencies": {
"merge-options": "^3.0.4"
},
"peerDependencies": {
"react-native": "^0.0.0-0 || 0.60 - 0.72 || 1000.0.0"
}
},
"node_modules/@react-native-community/cli": { "node_modules/@react-native-community/cli": {
"version": "10.2.2", "version": "10.2.2",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz",
@ -6052,9 +6064,9 @@
"integrity": "sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ==" "integrity": "sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ=="
}, },
"node_modules/babel-preset-expo": { "node_modules/babel-preset-expo": {
"version": "9.3.0", "version": "9.3.2",
"resolved": "https://registry.npmjs.org/babel-preset-expo/-/babel-preset-expo-9.3.0.tgz", "resolved": "https://registry.npmjs.org/babel-preset-expo/-/babel-preset-expo-9.3.2.tgz",
"integrity": "sha512-cIz+5TVBkcZgtfpTyFPo1peswr2dvQj2VIwdj5vY37/zESsYBHfaZ+u/A11yb1WnuZHcYD/ZoSLNwmWr20jp4Q==", "integrity": "sha512-BjyvjwjJG0MaaDBLP/esbXRrAItM76po9L9zfnLxeqgFsHCIPmD+6ir45coDLGAXwR8m9It3G1yqYM9JPyemsQ==",
"dependencies": { "dependencies": {
"@babel/plugin-proposal-decorators": "^7.12.9", "@babel/plugin-proposal-decorators": "^7.12.9",
"@babel/plugin-proposal-object-rest-spread": "^7.12.13", "@babel/plugin-proposal-object-rest-spread": "^7.12.13",
@ -6062,7 +6074,7 @@
"@babel/preset-env": "^7.20.0", "@babel/preset-env": "^7.20.0",
"babel-plugin-module-resolver": "^4.1.0", "babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-react-native-web": "~0.18.10", "babel-plugin-react-native-web": "~0.18.10",
"metro-react-native-babel-preset": "0.73.7" "metro-react-native-babel-preset": "0.73.9"
} }
}, },
"node_modules/babel-preset-fbjs": { "node_modules/babel-preset-fbjs": {
@ -8460,25 +8472,25 @@
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
}, },
"node_modules/expo": { "node_modules/expo": {
"version": "48.0.5", "version": "48.0.10",
"resolved": "https://registry.npmjs.org/expo/-/expo-48.0.5.tgz", "resolved": "https://registry.npmjs.org/expo/-/expo-48.0.10.tgz",
"integrity": "sha512-4sd0y8DX2GXbVWBS+UTKqcm60KeZxh7+EvGUi9jbJJAJkbCyt3smu4L0WGCaq/8+ki44H9G/pjM0B7VcZZjAiQ==", "integrity": "sha512-8YXG6um3ld36nu/ONEC0NNkMatdj4k/HwR7OUd3dKUt3PJSkZHsCeLXIu8za7WSWpgPAU/xAj35noPFEFnjO1w==",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.20.0", "@babel/runtime": "^7.20.0",
"@expo/cli": "0.6.2", "@expo/cli": "0.6.2",
"@expo/config": "8.0.2", "@expo/config": "8.0.2",
"@expo/config-plugins": "6.0.1", "@expo/config-plugins": "6.0.1",
"@expo/vector-icons": "^13.0.0", "@expo/vector-icons": "^13.0.0",
"babel-preset-expo": "~9.3.0", "babel-preset-expo": "~9.3.2",
"cross-spawn": "^6.0.5", "cross-spawn": "^6.0.5",
"expo-application": "~5.1.1", "expo-application": "~5.1.1",
"expo-asset": "~8.9.0", "expo-asset": "~8.9.1",
"expo-constants": "~14.2.1", "expo-constants": "~14.2.1",
"expo-file-system": "~15.2.2", "expo-file-system": "~15.2.2",
"expo-font": "~11.1.1", "expo-font": "~11.1.1",
"expo-keep-awake": "~12.0.1", "expo-keep-awake": "~12.0.1",
"expo-modules-autolinking": "1.1.2", "expo-modules-autolinking": "1.1.2",
"expo-modules-core": "1.2.4", "expo-modules-core": "1.2.6",
"fbemitter": "^3.0.0", "fbemitter": "^3.0.0",
"getenv": "^1.0.0", "getenv": "^1.0.0",
"invariant": "^2.2.4", "invariant": "^2.2.4",
@ -8500,9 +8512,9 @@
} }
}, },
"node_modules/expo-asset": { "node_modules/expo-asset": {
"version": "8.9.0", "version": "8.9.1",
"resolved": "https://registry.npmjs.org/expo-asset/-/expo-asset-8.9.0.tgz", "resolved": "https://registry.npmjs.org/expo-asset/-/expo-asset-8.9.1.tgz",
"integrity": "sha512-zenkZrYcsJAcTVl478mCarVmaOE9r2GbTlVvKZaXL8UJIL4rnspk63xUSJLAGMArZIdHzsGFQMXlQG3pgEfzrg==", "integrity": "sha512-ugavxA7Scn96TBdeTYQA6xtHktnk0o/0xk7nFkxJKoH/t2cZDFSB05X0BI2/LDZY4iE6xTPOYw4C4mmourWfuA==",
"dependencies": { "dependencies": {
"blueimp-md5": "^2.10.0", "blueimp-md5": "^2.10.0",
"expo-constants": "~14.2.0", "expo-constants": "~14.2.0",
@ -8668,9 +8680,9 @@
} }
}, },
"node_modules/expo-modules-core": { "node_modules/expo-modules-core": {
"version": "1.2.4", "version": "1.2.6",
"resolved": "https://registry.npmjs.org/expo-modules-core/-/expo-modules-core-1.2.4.tgz", "resolved": "https://registry.npmjs.org/expo-modules-core/-/expo-modules-core-1.2.6.tgz",
"integrity": "sha512-AV0NCTy9O8xQqpKgX6gvsDzV1ogpCzYpGxqM85Vw1xHsOF51s7Avu7NdNjBPUZOVuDderUXAvd97dWrtefSKcA==", "integrity": "sha512-vyleKepkP8F6L+D55B/E4FbZ8x9pdy3yw/mdbGBkDkrmo2gmeMjOM1mKLSszOkLIqet05O7Wy8m0FZHZTo0VBg==",
"dependencies": { "dependencies": {
"compare-versions": "^3.4.0", "compare-versions": "^3.4.0",
"invariant": "^2.2.4" "invariant": "^2.2.4"
@ -11710,6 +11722,25 @@
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w=="
}, },
"node_modules/merge-options": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz",
"integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==",
"dependencies": {
"is-plain-obj": "^2.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/merge-options/node_modules/is-plain-obj": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz",
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==",
"engines": {
"node": ">=8"
}
},
"node_modules/merge-stream": { "node_modules/merge-stream": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
@ -12117,9 +12148,9 @@
} }
}, },
"node_modules/metro-react-native-babel-preset": { "node_modules/metro-react-native-babel-preset": {
"version": "0.73.7", "version": "0.73.9",
"resolved": "https://registry.npmjs.org/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.73.7.tgz", "resolved": "https://registry.npmjs.org/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.73.9.tgz",
"integrity": "sha512-RKcmRZREjJCzHKP+JhC9QTCohkeb3xa/DtqHU14U5KWzJHdC0mMrkTZYNXhV0cryxsaVKVEw5873KhbZyZHMVw==", "integrity": "sha512-AoD7v132iYDV4K78yN2OLgTPwtAKn0XlD2pOhzyBxiI8PeXzozhbKyPV7zUOJUPETj+pcEVfuYj5ZN/8+bhbCw==",
"dependencies": { "dependencies": {
"@babel/core": "^7.20.0", "@babel/core": "^7.20.0",
"@babel/plugin-proposal-async-generator-functions": "^7.0.0", "@babel/plugin-proposal-async-generator-functions": "^7.0.0",
@ -12181,54 +12212,6 @@
"@babel/core": "*" "@babel/core": "*"
} }
}, },
"node_modules/metro-react-native-babel-transformer/node_modules/metro-react-native-babel-preset": {
"version": "0.73.9",
"resolved": "https://registry.npmjs.org/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.73.9.tgz",
"integrity": "sha512-AoD7v132iYDV4K78yN2OLgTPwtAKn0XlD2pOhzyBxiI8PeXzozhbKyPV7zUOJUPETj+pcEVfuYj5ZN/8+bhbCw==",
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/plugin-proposal-async-generator-functions": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-catch-binding": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-export-default-from": "^7.0.0",
"@babel/plugin-syntax-flow": "^7.18.0",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-syntax-optional-chaining": "^7.0.0",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-async-to-generator": "^7.0.0",
"@babel/plugin-transform-block-scoping": "^7.0.0",
"@babel/plugin-transform-classes": "^7.0.0",
"@babel/plugin-transform-computed-properties": "^7.0.0",
"@babel/plugin-transform-destructuring": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/plugin-transform-function-name": "^7.0.0",
"@babel/plugin-transform-literals": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-named-capturing-groups-regex": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.0.0",
"@babel/plugin-transform-react-display-name": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/plugin-transform-shorthand-properties": "^7.0.0",
"@babel/plugin-transform-spread": "^7.0.0",
"@babel/plugin-transform-sticky-regex": "^7.0.0",
"@babel/plugin-transform-template-literals": "^7.0.0",
"@babel/plugin-transform-typescript": "^7.5.0",
"@babel/plugin-transform-unicode-regex": "^7.0.0",
"@babel/template": "^7.0.0",
"react-refresh": "^0.4.0"
},
"peerDependencies": {
"@babel/core": "*"
}
},
"node_modules/metro-resolver": { "node_modules/metro-resolver": {
"version": "0.73.9", "version": "0.73.9",
"resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.73.9.tgz", "resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.73.9.tgz",
@ -12407,54 +12390,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/metro/node_modules/metro-react-native-babel-preset": {
"version": "0.73.9",
"resolved": "https://registry.npmjs.org/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.73.9.tgz",
"integrity": "sha512-AoD7v132iYDV4K78yN2OLgTPwtAKn0XlD2pOhzyBxiI8PeXzozhbKyPV7zUOJUPETj+pcEVfuYj5ZN/8+bhbCw==",
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/plugin-proposal-async-generator-functions": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-catch-binding": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-export-default-from": "^7.0.0",
"@babel/plugin-syntax-flow": "^7.18.0",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-syntax-optional-chaining": "^7.0.0",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-async-to-generator": "^7.0.0",
"@babel/plugin-transform-block-scoping": "^7.0.0",
"@babel/plugin-transform-classes": "^7.0.0",
"@babel/plugin-transform-computed-properties": "^7.0.0",
"@babel/plugin-transform-destructuring": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/plugin-transform-function-name": "^7.0.0",
"@babel/plugin-transform-literals": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-named-capturing-groups-regex": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.0.0",
"@babel/plugin-transform-react-display-name": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/plugin-transform-shorthand-properties": "^7.0.0",
"@babel/plugin-transform-spread": "^7.0.0",
"@babel/plugin-transform-sticky-regex": "^7.0.0",
"@babel/plugin-transform-template-literals": "^7.0.0",
"@babel/plugin-transform-typescript": "^7.5.0",
"@babel/plugin-transform-unicode-regex": "^7.0.0",
"@babel/template": "^7.0.0",
"react-refresh": "^0.4.0"
},
"peerDependencies": {
"@babel/core": "*"
}
},
"node_modules/metro/node_modules/ms": { "node_modules/metro/node_modules/ms": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

View file

@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"@expo/webpack-config": "^18.0.1", "@expo/webpack-config": "^18.0.1",
"@react-native-async-storage/async-storage": "^1.18.1",
"@react-navigation/drawer": "^6.6.2", "@react-navigation/drawer": "^6.6.2",
"@react-navigation/native": "^6.1.6", "@react-navigation/native": "^6.1.6",
"@reduxjs/toolkit": "^1.9.3", "@reduxjs/toolkit": "^1.9.3",

View file

@ -1,4 +1,5 @@
import axios from "axios"; import axios from "axios";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { import {
ActivationParams, ActivationParams,
UpdateNoteParams, UpdateNoteParams,
@ -13,10 +14,10 @@ const instance = axios.create({
baseURL: "https://keannu126.pythonanywhere.com", baseURL: "https://keannu126.pythonanywhere.com",
}); });
export function GetNotes() { export async function GetNotes() {
const token = JSON.parse(localStorage.getItem("token") || "{}"); const token = JSON.parse(await AsyncStorage.getItem("token") || "{}");
return instance return instance
.get("api/v1/notes/", { .get("/api/v1/notes/", {
headers: { headers: {
Authorization: "Token " + token, Authorization: "Token " + token,
}, },
@ -26,10 +27,16 @@ export function GetNotes() {
}); });
} }
export function GetNote(id: number) { export function GetPublicNotes() {
const token = JSON.parse(localStorage.getItem("token") || "{}"); return instance.get("/api/v1/public_notes/").then((response) => {
return response.data;
});
}
export async function GetNote(id: number) {
const token = JSON.parse(await AsyncStorage.getItem("token") || "{}");
return instance return instance
.get("api/v1/notes/" + id + "/", { .get("/api/v1/notes/" + id + "/", {
headers: { headers: {
Authorization: "Token " + token, Authorization: "Token " + token,
}, },
@ -39,10 +46,10 @@ export function GetNote(id: number) {
}); });
} }
export function UpdateNote(note: UpdateNoteParams) { export async function UpdateNote(note: UpdateNoteParams) {
const token = JSON.parse(localStorage.getItem("token") || "{}"); const token = JSON.parse(await AsyncStorage.getItem("token") || "{}");
return instance return instance
.patch("api/v1/notes/" + note.id + "/", note, { .patch("/api/v1/notes/" + note.id + "/", note, {
headers: { headers: {
Authorization: "Token " + token, Authorization: "Token " + token,
}, },
@ -51,15 +58,14 @@ export function UpdateNote(note: UpdateNoteParams) {
return response.data; return response.data;
}) })
.catch((error) => { .catch((error) => {
console.log("Error updating note", error);
return error; return error;
}); });
} }
export function AddNote(note: AddNoteParams) { export async function AddNote(note: AddNoteParams) {
const token = JSON.parse(localStorage.getItem("token") || "{}"); const token = JSON.parse(await AsyncStorage.getItem("token") || "{}");
return instance return instance
.post("api/v1/notes/", note, { .post("/api/v1/notes/", note, {
headers: { headers: {
Authorization: "Token " + token, Authorization: "Token " + token,
}, },
@ -68,21 +74,19 @@ export function AddNote(note: AddNoteParams) {
return response.data; return response.data;
}) })
.catch((error) => { .catch((error) => {
console.log("Error adding note", error);
return error; return error;
}); });
} }
export function DeleteNote(id: number) { export async function DeleteNote(id: number) {
const token = JSON.parse(localStorage.getItem("token") || "{}"); const token = JSON.parse(await AsyncStorage.getItem("token") || "{}");
return instance return instance
.delete("api/v1/notes/" + id + "/", { .delete("/api/v1/notes/" + id + "/", {
headers: { headers: {
Authorization: "Token " + token, Authorization: "Token " + token,
}, },
}) })
.catch((error) => { .catch((error) => {
console.log("Error deleting note", error);
return error; return error;
}); });
} }
@ -91,26 +95,20 @@ export function DeleteNote(id: number) {
export function UserRegister(register: RegistrationParams) { export function UserRegister(register: RegistrationParams) {
return instance return instance
.post("api/v1/accounts/users/", register) .post("/api/v1/accounts/users/", register)
.then(async (response) => { .then(async (response) => {
console.log(response.data);
return true; return true;
}) })
.catch((error) => { .catch((error) => {
console.log("Registration failed: " + error);
return false; return false;
}); });
} }
export function UserLogin(user: LoginParams) { export function UserLogin(user: LoginParams) {
return instance return instance
.post("api/v1/accounts/token/login/", user) .post("/api/v1/accounts/token/login/", user)
.then(async (response) => { .then(async (response) => {
localStorage.setItem("token", JSON.stringify(response.data.auth_token)); AsyncStorage.setItem("token", JSON.stringify(response.data.auth_token));
console.log(
"Login Success! Stored Token: ",
JSON.parse(localStorage.getItem("token") || "{}")
);
return true; return true;
}) })
.catch((error) => { .catch((error) => {
@ -119,29 +117,26 @@ export function UserLogin(user: LoginParams) {
}); });
} }
export function UserInfo() { export async function UserInfo() {
const token = JSON.parse(localStorage.getItem("token") || "{}"); const token = JSON.parse(await AsyncStorage.getItem("token") || "{}");
return instance return instance
.get("api/v1/accounts/users/me/", { .get("/api/v1/accounts/users/me/", {
headers: { headers: {
Authorization: "Token " + token, Authorization: "Token " + token,
}, },
}) })
.then((response) => { .then((response) => {
console.log(response.data);
return response.data; return response.data;
}); });
} }
export function UserActivate(activation: ActivationParams) { export function UserActivate(activation: ActivationParams) {
return instance return instance
.post("api/v1/accounts/users/activation/", activation) .post("/api/v1/accounts/users/activation/", activation)
.then(async (response) => { .then(async (response) => {
console.log("Activation Success");
return true; return true;
}) })
.catch((error) => { .catch((error) => {
console.log("Activation failed: " + error);
return false; return false;
}); });
} }

View file

@ -2,15 +2,9 @@ import { configureStore } from "@reduxjs/toolkit";
import LoginReducer from "../Slices/LoginSlice/LoginSlice"; import LoginReducer from "../Slices/LoginSlice/LoginSlice";
import LoggedInUserReucer from "../Slices/LoggedInUserSlice/LoggedInUserSlice"; import LoggedInUserReucer from "../Slices/LoggedInUserSlice/LoggedInUserSlice";
const store = configureStore({ export default configureStore({
reducer: { reducer: {
logged_in: LoginReducer, Login: LoginReducer,
logged_in_user: LoggedInUserReucer, LoggedInUser: LoggedInUserReucer,
}, },
}); });
export default store;
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;