Skip to content

Commit

Permalink
golos_news
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Oct 26, 2023
1 parent ffd1c13 commit b02b19e
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 72 deletions.
19 changes: 2 additions & 17 deletions app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -381,8 +368,6 @@ class App extends React.Component {
const noHeader = isApp
const noFooter = isApp || location.pathname.startsWith('/submit')

const reminder = this.showAppReminder() ? <AppReminder /> : null

return (
<div
className={
Expand All @@ -405,7 +390,7 @@ class App extends React.Component {
<ChainFailure />
{children}
{noFooter ? null : <Footer />}
{reminder}
<NewsPopups />
<ScrollButton />
</div>
<Dialogs />
Expand Down
2 changes: 1 addition & 1 deletion app/components/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
179 changes: 179 additions & 0 deletions app/components/elements/NewsPopups.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
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
}
try {
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: []
})
}
}
} catch (err) {
console.error('NewsPopups', err)
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 = <span className='NewsPopups callout primary' onClick={this.showModal}>
<CloseButton
onClick={(e) => {
e.stopPropagation()
this.hideMe()
}}
/>
{tt('app_reminder.text')}
</span>
}

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(<a key={ne.hashlink} href={ne.url} onClick={e => this.openNew(e, ne.hashlink, ne.url)} target='_blank' rel='noopener noreferrer nofollow'>
<span style={{ bottom: bottom + 'px' }} className='NewsPopups callout primary'>
<CloseButton
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
this.hideMe(ne.hashlink)
}}
/>
{title}
</span>
</a>)
--newCount
}
}

return <div>
{appReminder}
{newItems}
</div>
}
}

export default connect(
state => {
return {}
},
dispatch => ({
showModal: () => {
dispatch(user.actions.showAppDownload())
}
})
)(NewsPopups)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.AppReminder {
.NewsPopups {
@include themify($themes) {
background-color: themed('modalReminder') !important;
}
Expand Down
53 changes: 0 additions & 53 deletions app/components/elements/app/AppReminder.jsx

This file was deleted.

3 changes: 3 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
3 changes: 3 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b02b19e

Please sign in to comment.