Skip to content

Commit

Permalink
#144 Fix notification api uri
Browse files Browse the repository at this point in the history
  • Loading branch information
syi0808 committed May 19, 2022
1 parent 2be78c9 commit 8a9d368
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
46 changes: 22 additions & 24 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,36 @@ export default function App() {
setIsLogin(accessToken !== null);
}, []);

const appPermission = useCallback(async () => {
setTimeout(async () => {
await requestTrackingPermissionsAsync();
const { status } = await Notifications.requestPermissionsAsync();
if (status === "granted") {
const token = (await Notifications.getExpoPushTokenAsync()).data;
postExpoToken(token);
localStorage.setItem("isSendedToken", true);
}
}, 500);
}, []);
const appPermission = useCallback(() => setTimeout(requestTrackingPermissionsAsync, 500), []);

useEffect(() => {
check();
appPermission();
(
async () => {
const isSendedToken = (await localStorage.getItem("isSendedToken")) ?? false;
const { status } = await Notifications.getPermissionsAsync();
if (status === "granted" && !isSendedToken) {
const token = (await Notifications.getExpoPushTokenAsync()).data;
postExpoToken(token);
localStorage.setItem("isSendedToken", true);
}
}
)();
}, []);

if (!fontsLoaded) {
return <AppLoading />;
const postToken = async () => {
const token = (await Notifications.getExpoPushTokenAsync()).data;
postExpoToken(token);
localStorage.setItem("isSendedToken", true);
}

useEffect(() => {
if(isLogin) {
(
async () => {
const [isSendedToken, { status }] = await Promise.all([localStorage.getItem("isSendedToken"), Notifications.getPermissionsAsync()]);
if (status === "granted" && !isSendedToken) postToken();
else {
const { status } = await Notifications.requestPermissionsAsync();
if (status === "granted") postToken();
}
}
)();
}
}, [isLogin]);

if (!fontsLoaded) return <AppLoading />;

return (
<GestureHandlerRootView style={{ flex: 1 }}>
<isLoginContext.Provider value={isLogin}>
Expand Down
3 changes: 2 additions & 1 deletion src/utils/api/notification/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { instance } from "utils/axios"

export const postExpoToken = (token: string) => {
return instance.patch("/expo/token", {
console.log(123, token);
return instance.patch("/user/expo/token", {
token,
});
}

0 comments on commit 8a9d368

Please sign in to comment.