mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Working database interactions and NUI callbacks
This commit is contained in:
1 parent
1e900baab9
commit
ba0f122938
19 files changed
+372
-127
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import { atom } from "recoil";
|
||||
|
||||
export const twitterState = {
|
||||
tweets: atom({
|
||||
key: "tweets",
|
||||
default: [],
|
||||
}),
|
||||
createTweetLoading: atom({
|
||||
key: "createTweetLoading",
|
||||
default: false,
|
||||
}),
|
||||
createTweetSuccess: atom({
|
||||
key: "createTweetSuccess",
|
||||
default: null,
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { useRecoilValue } from "recoil";
|
||||
|
||||
import { twitterState } from "./state";
|
||||
|
||||
export const useTweetStatus = () => {
|
||||
const isLoading = useRecoilValue(twitterState.createTweetLoading);
|
||||
const isSuccessful = useRecoilValue(twitterState.createTweetSuccess);
|
||||
return { isLoading, isSuccessful };
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { useRecoilValue, useSetRecoilState } from "recoil";
|
||||
import { twitterState } from "./state";
|
||||
|
||||
export const useTweets = () => {
|
||||
const tweets = useRecoilValue(twitterState.tweets);
|
||||
return { tweets };
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useNuiEvent } from "../../../os/nui-events/hooks/useNuiEvent";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
|
||||
import types from "../types";
|
||||
import { twitterState } from "./state";
|
||||
import { useTweets } from "./useTweets";
|
||||
|
||||
export const useTwitterService = () => {
|
||||
const setTweets = useSetRecoilState(twitterState.tweets);
|
||||
const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
|
||||
const setCreateSuccess = useSetRecoilState(twitterState.createTweetSuccess);
|
||||
|
||||
const _setCreateSuccess = (isSuccessful) => {
|
||||
setCreateSuccess(isSuccessful === 1); // numeric 1 is returned by MySQL on successful query
|
||||
setCreateLoading(false); // on any result we should set loading to false
|
||||
};
|
||||
|
||||
useNuiEvent(types.APP_TWITTER, "fetchTweets", setTweets);
|
||||
useNuiEvent(types.APP_TWITTER, "createTweetLoading", setCreateLoading);
|
||||
useNuiEvent(types.APP_TWITTER, "createTweetResult", _setCreateSuccess);
|
||||
|
||||
return useTweets();
|
||||
};
|
||||
Reference in new issue
Block a user