From 1d4faa4bf9e2f3bc559e2f2413c593c62879139b Mon Sep 17 00:00:00 2001 From: erik-sn Date: Sat, 3 Oct 2020 10:59:52 -0400 Subject: [PATCH] moved twitter skeleton to TweetList --- .../src/apps/twitter/components/TwitterApp.js | 20 +++---------------- .../apps/twitter/components/TwitterSearch.js | 2 +- .../twitter/components/profile/Profile.js | 2 +- .../twitter/components/tweet/TweetList.js | 20 +++++++++++++++++-- resources/server/sv_twitter.lua | 3 ++- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/phone/src/apps/twitter/components/TwitterApp.js b/phone/src/apps/twitter/components/TwitterApp.js index e3c9aee..bc1daa8 100644 --- a/phone/src/apps/twitter/components/TwitterApp.js +++ b/phone/src/apps/twitter/components/TwitterApp.js @@ -37,15 +37,13 @@ const PAGE_COMPONENT_MAPPING = { 1: , 2: , }; -const MINIMUM_LOAD_TIME = 500; -const TWEETS_REFRESH_RATE = 50000000; // TODO move this to twitter config +const TWEETS_REFRESH_RATE = 15000; // TODO move this to twitter config export const TwitterApp = () => { const classes = useStyles(); const { modalVisible, setModalVisible } = useModal(); - const [minimumLoadPassed, setMimimumLoadPassed] = useState(false); const [activePage, setActivePage] = useState(0); - const { profile } = useProfile(); + useEffect(() => { Nui.send("phone:getOrCreateTwitterProfile", {}); Nui.send("phone:fetchTweets", {}); @@ -63,21 +61,9 @@ export const TwitterApp = () => { return () => window.clearTimeout(timeout); }, []); - useEffect(() => { - const timeout = window.setTimeout(() => { - setMimimumLoadPassed(true); - }, MINIMUM_LOAD_TIME); - return () => window.clearTimeout(timeout); - }); - const openModal = () => setModalVisible(true); const handlePageChange = (e, page) => setActivePage(page); - - // we add a minimum (but short) load time here so that - // there isn't a quick flash of loading and immediately - // another flash to the tweets screen. - const hasLoaded = profile && minimumLoadPassed; - const showTweetButton = hasLoaded && activePage === 0; + const showTweetButton = activePage === 0; return ( diff --git a/phone/src/apps/twitter/components/TwitterSearch.js b/phone/src/apps/twitter/components/TwitterSearch.js index 68c9f9d..8e033bf 100644 --- a/phone/src/apps/twitter/components/TwitterSearch.js +++ b/phone/src/apps/twitter/components/TwitterSearch.js @@ -49,7 +49,7 @@ function TwitterSearch() { inputRef={(input) => input && input.focus()} /> - + {tweets && tweets.length > 0 && } diff --git a/phone/src/apps/twitter/components/profile/Profile.js b/phone/src/apps/twitter/components/profile/Profile.js index ec45e8d..b8b6ecd 100644 --- a/phone/src/apps/twitter/components/profile/Profile.js +++ b/phone/src/apps/twitter/components/profile/Profile.js @@ -6,7 +6,7 @@ import Nui from "../../../../os/nui-events/utils/Nui"; import { useProfile } from "../../hooks/useProfile"; import Avatar from "../Avatar"; import ProfileField from "./ProfileField"; -import ProfileUpdateButton from "./ProfileUpdateButton"; +import ProfileUpdateButton from "../buttons/ProfileUpdateButton"; const useStyles = makeStyles((theme) => ({ root: { diff --git a/phone/src/apps/twitter/components/tweet/TweetList.js b/phone/src/apps/twitter/components/tweet/TweetList.js index b3b2130..9b1e119 100644 --- a/phone/src/apps/twitter/components/tweet/TweetList.js +++ b/phone/src/apps/twitter/components/tweet/TweetList.js @@ -1,11 +1,27 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import { List } from "../../../../ui/components/List"; import Tweet from "./Tweet"; import TweetSkeletonList from "./TweetSkeletonList"; +const MINIMUM_LOAD_TIME = 700; + export function TweetList({ tweets }) { - if (!tweets) return ; + const [minimumLoadPassed, setMimimumLoadPassed] = useState(false); + + useEffect(() => { + const timeout = window.setTimeout(() => { + setMimimumLoadPassed(true); + }, MINIMUM_LOAD_TIME); + return () => window.clearTimeout(timeout); + }); + + // we add a minimum (but short) load time here so that + // there isn't a quick flash of loading and immediately + // another flash to the tweets screen. + const hasLoaded = tweets && minimumLoadPassed; + + if (!hasLoaded) return ; return ( {tweets.map((tweet) => ( diff --git a/resources/server/sv_twitter.lua b/resources/server/sv_twitter.lua index 98b886c..88b9c3b 100644 --- a/resources/server/sv_twitter.lua +++ b/resources/server/sv_twitter.lua @@ -169,7 +169,8 @@ end) function updateTwitterProfile(identifier, data, cb) MySQL.Async.transaction({[[ UPDATE npwd_twitter_profiles - SET avatar_url = @avatar_url, profile_name = @profile_name, bio = @bio, location = @location, job = @job WHERE identifier = @identifier + SET avatar_url = @avatar_url, profile_name = @profile_name, bio = @bio, location = @location, job = @job + WHERE identifier = @identifier ]]}, { identifier = identifier,