Skip to content

Commit

Permalink
ElasticSearch post versions
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm authored and Lex-Ai committed May 13, 2022
1 parent 9e52d44 commit 1304362
Show file tree
Hide file tree
Showing 13 changed files with 414 additions and 21 deletions.
1 change: 1 addition & 0 deletions app/components/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@import "./elements/ScrollButton";
@import "./elements/SignupProgressBar";
@import "./elements/TagList";
@import "./elements/TimeVersions";
@import "./elements/UserNames";
@import "./elements/Userpic";
@import "./elements/VerticalMenu";
Expand Down
7 changes: 3 additions & 4 deletions app/components/cards/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import CommentFormLoader from 'app/components/modules/CommentForm/loader';
import MarkdownViewer from 'app/components/cards/MarkdownViewer';
import Author from 'app/components/elements/Author';
import Voting from 'app/components/elements/Voting';
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper';
import TimeVersions from 'app/components/elements/TimeVersions';
import Userpic from 'app/components/elements/Userpic';

import { LIQUID_TICKER, CONFETTI_CONFIG } from 'app/client_config';
Expand Down Expand Up @@ -285,9 +285,8 @@ class CommentImpl extends PureComponent {
to={this._getCommentLink(comment)}
className="PlainLink"
>
<TimeAgoWrapper
date={comment.created}
className="updated"
<TimeVersions
content={comment}
/>
</Link>
{this.state.collapsed || hideBody ? (
Expand Down
10 changes: 4 additions & 6 deletions app/components/cards/PostFull.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { immutableAccessor, objAccessor } from 'app/utils/Accessors';
import { isPostVisited, visitPost } from 'app/utils/helpers';
import { serverApiRecordEvent } from 'app/utils/ServerApiClient';
import Icon from 'app/components/elements/Icon';
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper';
import TimeVersions from 'app/components/elements/TimeVersions';
import Voting from 'app/components/elements/Voting';
import Reblog from 'app/components/elements/Reblog';
import MarkdownViewer from 'app/components/cards/MarkdownViewer';
Expand All @@ -27,11 +27,12 @@ import Confetti from 'react-dom-confetti';
import PostSummaryThumb from 'app/components/elements/PostSummaryThumb';
import { SEO_TITLE, LIQUID_TICKER, CONFETTI_CONFIG, CHANGE_IMAGE_PROXY_TO_STEEMIT_TIME } from 'app/client_config';


function TimeAuthorCategory({ content, authorRepLog10, showTags }) {
return (
<span className="PostFull__time_author_category vcard">
<Icon name="clock" className="space-right" />
<TimeAgoWrapper date={content.created} className="updated" />
<TimeVersions content={content} />
{' '}
<Author author={content.author} authorRepLog10={authorRepLog10} donateUrl={content.url} />
{showTags && (
Expand All @@ -47,10 +48,7 @@ function TimeAuthorCategory({ content, authorRepLog10, showTags }) {
function TimeAuthorCategoryLarge({ content, authorRepLog10 }) {
return (
<span className="PostFull__time_author_category_large vcard">
<TimeAgoWrapper
date={content.created}
className="updated float-right"
/>
<TimeVersions content={content} className='float-right' />
<Userpic account={content.author} reputation={authorRepLog10} />
<div className="right-side">
<Author
Expand Down
114 changes: 114 additions & 0 deletions app/components/elements/TimeVersions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React from 'react'
import tt from 'counterpart'
import { connect } from 'react-redux'

import g from 'app/redux/GlobalReducer'
import DropdownMenu from 'app/components/elements/DropdownMenu'
import LoadingIndicator from 'app/components/elements/LoadingIndicator'
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper'
import { getVersion } from 'app/utils/SearchClient'

const makeURL = (link) => {
let hash = link.split('#')[1]
link = hash ? ('/' + hash) : link
return link
}

class TimeVersions extends React.Component {
onClick = (e) => {
const { content } = this.props
const { num_changes, versions } = content
if (num_changes && (!versions || !versions.items || versions.items.length < num_changes)) {
this.props.fetchVersions(content)
}
}

changeVersion = async (ver) => {
const { content } = this.props
this.props.showVersion(content, ver)
}

render() {
const { content, className } = this.props
let rev
let menuItems = []
const versions = content.versions || {}
let changes = content.num_changes
if (changes) {
const latest = changes + 1
const curr = versions.current || latest
rev = ' (' + tt('time_versions_jsx.rev') + ' ' + curr + ')'
if (curr !== latest) {
rev = <b style={{ color: 'red' }}>{rev}</b>
}
}
if (versions.loading || !versions.items) {
menuItems.push({
value: <span>
<LoadingIndicator type='circle' />
</span>
})
} else {
const formatTime = (time) => {
let str = new Date(time).toLocaleString([], {
day: '2-digit', month: '2-digit', year: 'numeric',
hour: 'numeric', minute: '2-digit',
hour12: false
})
return str.split(',').join('')
}
menuItems = versions.items.reverse().map(item => {
const onClick = (e) => {
let link = content.url
link = makeURL(link)
if (!window.location.pathname.endsWith(link)) {
e.preventDefault()
this.changeVersion(item.v)
}
}
let link = content.url
link = makeURL(link)
if (!item.latest) {
link += '?version=' + item.v
}
return {
key: item.v,
value: <span className='val'>{formatTime(item.time)}</span>,
link,
data: <span className='data'>
{tt('time_versions_jsx.version_NUM', { NUM: item.v })}
</span>,
onClick
}
})
}
let el = <TimeAgoWrapper
date={content.created}
/>
if (rev) {
el = <DropdownMenu items={menuItems} el='div' className='TimeVersions'>
{el}
{rev}
</DropdownMenu>
}
return <span className={'updated ' + className} onClick={this.onClick}>
{el}
</span>
}
}

export default connect(
(state, props) => {
return props
},
dispatch => ({
fetchVersions: (content) => {
const { author, permlink, last_update, num_changes } = content
dispatch(g.actions.fetchVersions({ author, permlink, lastUpdate: last_update, numChanges: num_changes }))
},
showVersion: (content, v) => {
const { author, permlink } = content
dispatch(g.actions.showVersion({ author, permlink, v }))
}
})
)(TimeVersions)
13 changes: 13 additions & 0 deletions app/components/elements/TimeVersions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.TimeVersions {
a {
font-weight: normal;
color: inherit;
}
li > a > span:not(.val) {
position: absolute;
right: 15px;
}
.VerticalMenu {
min-width: 250px;
}
}
4 changes: 4 additions & 0 deletions app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@
"too_low_amount": "Too low amount.",
"you_will_receive": "You will receive "
},
"time_versions_jsx": {
"rev": "rev.",
"version_NUM": "(rev. %(NUM)s)"
},
"tips_js": {
"tip_balance_hint": "Balance that you use to reward users and that you use to earn rewards for yourself. Tokens from it can also be sent to increase the Golos Power.",
"claim_balance_hint": "Balance of your share of the emission of Golos blockchain tokens, which you can use to top up your TIP balance or increase the Golos Power.",
Expand Down
4 changes: 4 additions & 0 deletions app/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@
"not_desc": "Обмен идет дольше обычного. Возможно, он пройдет за несколько дней. Если этого не произойдет или если вы не можете ждать, то можно ",
"price_warning": "Эта цена выше текущей (менее выгодна для вас), чем рыночная. Продолжить обмен?"
},
"time_versions_jsx": {
"rev": "ред.",
"version_NUM": "(версия %(NUM)s)"
},
"tips_js": {
"tip_balance_hint": "Для вознаграждений пользователей, и на который получаете вознаграждения сами. Токены с него можно также отправить на увеличение Силы Голоса.",
"claim_balance_hint": "Ваша доля от эмиссии токенов блокчейна, которую вы можете получить для увеличения Силы Голоса, пополнения TIP-баланса...",
Expand Down
6 changes: 5 additions & 1 deletion app/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import GlobalReducer from './GlobalReducer';
import constants from './constants';
import { reveseTag, ONLYAPP_TAG } from 'app/utils/tags';
import { PUBLIC_API, CATEGORIES, IGNORE_TAGS, SELECT_TAGS_KEY, DEBT_TOKEN_SHORT, LIQUID_TICKER } from 'app/client_config';
import { SearchRequest, searchData } from 'app/utils/SearchClient'
import { SearchRequest, searchData, stateSetVersion } from 'app/utils/SearchClient'

export function* fetchDataWatches () {
yield fork(watchLocationChange);
Expand Down Expand Up @@ -279,6 +279,10 @@ export function* fetchState(location_change_action) {
console.time('getContent');
const curl = `${account}/${permlink}`
state.content[curl] = yield call([api, api.getContentAsync], account, permlink, constants.DEFAULT_VOTE_LIMIT)
const search = window.location.search
if (search) {
yield stateSetVersion(state.content[curl], search)
}
accounts.add(account)
console.timeEnd('getContent');

Expand Down
24 changes: 21 additions & 3 deletions app/redux/GlobalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ export default createModule({
);
}
}
return state.mergeDeep(payload);
let res = state.mergeDeep(payload);
let con = res.get('content').withMutations(con => {
con.forEach((cc, key) => {
if (!payload.hasIn(['content', key, 'versions'])) {
con.deleteIn([key, 'versions'])
}
})
})
res = res.set('content', con)
return res
},
},
{
Expand Down Expand Up @@ -444,9 +453,10 @@ export default createModule({
},
{
action: 'UPDATE',
reducer: (state, { payload: { key, notSet = Map(), updater } }) =>
reducer: (state, { payload: { key, notSet = Map(), updater } }) => {
// key = Array.isArray(key) ? key : [key] // TODO enable and test
state.updateIn(key, notSet, updater),
return state.updateIn(key, notSet, updater)
}
},
{
action: 'SET_META_DATA',
Expand Down Expand Up @@ -501,5 +511,13 @@ export default createModule({
fromJS(vesting_delegations)
),
},
{
action: 'FETCH_VERSIONS',
reducer: state => state, // saga
},
{
action: 'SHOW_VERSION',
reducer: state => state, // saga
},
],
});
2 changes: 2 additions & 0 deletions app/redux/RootSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { sharedWatches } from 'app/redux/SagaShared';
import { userWatches } from 'app/redux/UserSaga';
import { authWatches } from 'app/redux/AuthSaga';
import { transactionWatches } from 'app/redux/TransactionSaga';
import { versionsWatches } from 'app/redux/VersionsSaga'
import PollDataSaga from 'app/redux/PollDataSaga';


Expand All @@ -16,4 +17,5 @@ export default function* rootSaga() {
yield fork(authWatches)
yield fork(transactionWatches)
yield fork(marketWatches)
yield fork(versionsWatches)
}
Loading

0 comments on commit 1304362

Please sign in to comment.