From 1c086a365cd4d5bfb7e611aaf76ce98d28d2efdc Mon Sep 17 00:00:00 2001 From: 1aerostorm Date: Thu, 26 Oct 2023 01:35:17 +0000 Subject: [PATCH] golos_news --- app/components/App.jsx | 19 +- app/components/all.scss | 2 +- app/components/elements/NewsPopups.jsx | 172 ++++++++++++++++++ .../{app/AppReminder.scss => NewsPopups.scss} | 2 +- app/components/elements/app/AppReminder.jsx | 53 ------ config/default.json | 3 + server/index.js | 3 + 7 files changed, 182 insertions(+), 72 deletions(-) create mode 100644 app/components/elements/NewsPopups.jsx rename app/components/elements/{app/AppReminder.scss => NewsPopups.scss} (95%) delete mode 100644 app/components/elements/app/AppReminder.jsx diff --git a/app/components/App.jsx b/app/components/App.jsx index 4ed4c9c46..1d217e0d3 100644 --- a/app/components/App.jsx +++ b/app/components/App.jsx @@ -12,7 +12,7 @@ import { createGlobalStyle } from 'styled-components' import AppPropTypes from 'app/utils/AppPropTypes'; import Header from 'app/components/modules/Header'; import Footer from 'app/components/modules/Footer'; -import AppReminder from 'app/components/elements/app/AppReminder' +import NewsPopups from 'app/components/elements/NewsPopups' import URLLoader from 'app/components/elements/app/URLLoader'; import TooltipManager from 'app/components/elements/common/TooltipManager'; import user from 'app/redux/User'; @@ -33,8 +33,6 @@ import { APP_ICON, VEST_TICKER, } from 'app/client_config'; import session from 'app/utils/session' import { loadGrayHideSettings } from 'app/utils/ContentAccess' -const APP_REMINDER_INTERVAL = 30*24*60*60*1000 - const GlobalStyle = createGlobalStyle` body { fill: currentColor; @@ -100,17 +98,6 @@ class App extends React.Component { } } - showAppReminder = () => { - if (process.env.IS_APP || typeof(localStorage) === 'undefined' - || location.pathname.startsWith('/submit')) { - return false - } - const now = Date.now() - let reminded = localStorage.getItem('app_reminder') || 0 - reminded = parseInt(reminded) - return !reminded || (now - reminded > APP_REMINDER_INTERVAL) - } - constructor(props) { super(props) if (process.env.BROWSER) { @@ -381,8 +368,6 @@ class App extends React.Component { const noHeader = isApp const noFooter = isApp || location.pathname.startsWith('/submit') - const reminder = this.showAppReminder() ? : null - return (
{children} {noFooter ? null :
} - {reminder} +
diff --git a/app/components/all.scss b/app/components/all.scss index d03054e88..aa90959f3 100644 --- a/app/components/all.scss +++ b/app/components/all.scss @@ -39,7 +39,7 @@ @import "./elements/VerticalMenu"; @import "./elements/VotesAndComments"; @import "./elements/Voting"; -@import "./elements/app/AppReminder"; +@import "./elements/NewsPopups"; @import "./elements/common/YoutubePlayer/YoutubePlayer"; @import "./elements/common/TelegramPlayer/TelegramPlayer"; @import "./elements/common/Button/index"; diff --git a/app/components/elements/NewsPopups.jsx b/app/components/elements/NewsPopups.jsx new file mode 100644 index 000000000..d548ffb54 --- /dev/null +++ b/app/components/elements/NewsPopups.jsx @@ -0,0 +1,172 @@ +import React from 'react' +import tt from 'counterpart' +import { connect } from 'react-redux' +import { api } from 'golos-lib-js' + +import CloseButton from 'react-foundation-components/lib/global/close-button' + +import user from 'app/redux/User' + +const APP_REMINDER_INTERVAL = 30*24*60*60*1000 + +class NewsPopups extends React.Component { + state = { + hidden: false, + hiddenNews: [] + } + + checkNews = async () => { + if (typeof(localStorage) === 'undefined') { + this.setState({ news: [] }) + return + } + let news_read = localStorage.getItem('news_read') || '' + news_read = news_read.split(',') + if ($STM_Config.golos_news && $STM_Config.golos_news.account) { + const acc = $STM_Config.golos_news.account + const entries = await api.getBlogEntriesAsync(acc, 0, 5, ['fm-'], {}) + const news_to_load = [] + for (const post of entries) { + const { author, hashlink } = post + if (news_read.includes(hashlink)) { + continue + } + news_to_load.push({ + author, + hashlink + }) + } + if (news_to_load.length) { + const news = await api.getContentPreviewsAsync(news_to_load) + this.setState({ + news + }) + } else { + this.setState({ + news: [] + }) + } + } + } + + componentDidMount() { + this.checkNews() + } + + hideMe = (i) => { + if (i) { + let { hiddenNews } = this.state + hiddenNews = [...hiddenNews] + hiddenNews.push(i) + this.setState({ + hiddenNews + }) + let news_read = localStorage.getItem('news_read') || '' + news_read = news_read.split(',') + news_read.push(i) + localStorage.setItem('news_read', news_read.join(',')) + return + } + const now = Date.now() + localStorage.setItem('app_reminder', now) + this.setState({ + hidden: true + }) + } + + openNew = (e, i, url) => { + e.preventDefault() + this.hideMe(i) + window.open(url, '_blank') + } + + showModal = (e) => { + e.preventDefault() + this.props.showModal() + this.hideMe() + } + + showAppReminder = () => { + if (process.env.IS_APP || typeof(localStorage) === 'undefined' + || location.pathname.startsWith('/submit')) { + return false + } + const now = Date.now() + let reminded = localStorage.getItem('app_reminder') || 0 + reminded = parseInt(reminded) + return !reminded || (now - reminded > APP_REMINDER_INTERVAL) + } + + render() { + const { news,hiddenNews } = this.state + + let appReminder = null + if (news && this.showAppReminder() && !this.state.hidden) { + appReminder = + { + e.stopPropagation() + this.hideMe() + }} + /> + {tt('app_reminder.text')} + + } + + let newItems = [] + if (news) { + let newCount = 0 + for (const ne of news) { + if (hiddenNews.includes(ne.hashlink)) { + continue + } + newCount++ + } + newCount -= 1 + for (const ne of news) { + if (hiddenNews.includes(ne.hashlink)) { + continue + } + let title = ne.title + if (title.length > 100) { + title = title.substring(0, 100) + '...' + } + let bottom = newCount * 65 + if (appReminder) { + bottom += 65 + } else { + bottom += 2 + } + newItems.push( this.openNew(e, ne.hashlink, ne.url)} target='_blank' rel='noopener noreferrer nofollow'> + + { + e.stopPropagation() + e.preventDefault() + this.hideMe(ne.hashlink) + }} + /> + {title} + + ) + --newCount + } + } + + return
+ {appReminder} + {newItems} +
+ } +} + +export default connect( + state => { + return {} + }, + dispatch => ({ + showModal: () => { + dispatch(user.actions.showAppDownload()) + } + }) +)(NewsPopups) diff --git a/app/components/elements/app/AppReminder.scss b/app/components/elements/NewsPopups.scss similarity index 95% rename from app/components/elements/app/AppReminder.scss rename to app/components/elements/NewsPopups.scss index 227071e5b..fe5c9b22a 100644 --- a/app/components/elements/app/AppReminder.scss +++ b/app/components/elements/NewsPopups.scss @@ -1,4 +1,4 @@ -.AppReminder { +.NewsPopups { @include themify($themes) { background-color: themed('modalReminder') !important; } diff --git a/app/components/elements/app/AppReminder.jsx b/app/components/elements/app/AppReminder.jsx deleted file mode 100644 index 7043fc288..000000000 --- a/app/components/elements/app/AppReminder.jsx +++ /dev/null @@ -1,53 +0,0 @@ -import React from 'react' -import tt from 'counterpart' -import { connect } from 'react-redux' - -import CloseButton from 'react-foundation-components/lib/global/close-button' - -import user from 'app/redux/User' - -class AppReminder extends React.Component { - state = { - hidden: false - } - - hideMe = () => { - const now = Date.now() - localStorage.setItem('app_reminder', now) - this.setState({ - hidden: true - }) - } - - showModal = (e) => { - e.preventDefault() - this.props.showModal() - this.hideMe() - } - - render() { - if (this.state.hidden) { - return null - } - return - { - e.stopPropagation() - this.hideMe() - }} - /> - {tt('app_reminder.text')} - - } -} - -export default connect( - state => { - return {} - }, - dispatch => ({ - showModal: () => { - dispatch(user.actions.showAppDownload()) - } - }) -)(AppReminder) diff --git a/config/default.json b/config/default.json index 3d0bc1949..cd6cab3be 100644 --- a/config/default.json +++ b/config/default.json @@ -58,6 +58,9 @@ "apidex_service": { "host": "https://api-dex.golos.app" }, + "golos_news": { + "account": "progolos" + }, "forums": { "white_list": ["fm-golostalk", "fm-prizmtalk", "fm-graphenetalks"], "fm-golostalk": {"domain": "golostalk.com"}, diff --git a/server/index.js b/server/index.js index 8ad28a7e7..c325c4a3e 100755 --- a/server/index.js +++ b/server/index.js @@ -46,6 +46,9 @@ global.$STM_Config = { wallet_service: config.get('wallet_service'), messenger_service: config.get('messenger_service'), apidex_service: config.get('apidex_service'), + golos_news: config.has('golos_news') ? config.get('golos_news') : { + account: 'progolos' + }, forums: config.get('forums'), blocked_users, blocked_posts,