working notification

This commit is contained in:
erik-sn committed 2020-10-17 21:40:53 -04:00
1 parent 7d27a6bddf
commit b2466f0e15
12 files changed
+236 -13

No files matched your search

+4
View File
@@ -37,4 +37,8 @@ export const twitterState = {
key: "updateProfileSuccess",
default: null,
}),
notification: atom({
key: 'notification',
default: null,
})
};
@@ -0,0 +1,13 @@
import { useRecoilValue } from "recoil";
import { Tweet } from "../interfaces";
import { twitterState } from "./state";
interface ITwitterNotification {
notification: Tweet | null;
}
export const useTwitterNotification = (): ITwitterNotification => {
const notification = useRecoilValue<Tweet | null>(twitterState.notification);
return { notification };
};
@@ -6,6 +6,8 @@ import { IMAGE_DELIMITER } from "../utils/images";
import { APP_TWITTER } from "../utils/constants";
import { twitterState } from "./state";
const NOTIFICATION_TIMEOUT = 5000;
/**
* Perform all necessary processing/transforms from the raw database
* data to what the frontend expects
@@ -41,6 +43,7 @@ export const useTwitterService = () => {
const setCreateSuccess = useSetRecoilState(
twitterState.createTweetSuccessful
);
const setNotification = useSetRecoilState(twitterState.notification);
const _setProfile = (profile) => {
setProfile(profile);
@@ -55,6 +58,10 @@ export const useTwitterService = () => {
setCreateLoading(false);
};
const _setNotification = (tweet) => {
setNotification(tweet);
}
const _setTweets = (tweets) => {
setTweets(tweets.map(processTweet));
};
@@ -69,4 +76,5 @@ export const useTwitterService = () => {
useNuiEvent(APP_TWITTER, "fetchTweetsFiltered", _setFilteredTweets);
useNuiEvent(APP_TWITTER, "createTweetLoading", setCreateLoading);
useNuiEvent(APP_TWITTER, "createTweetResult", _setCreateSuccess);
useNuiEvent(APP_TWITTER, 'createTweetBroadcast', _setNotification)
};