Skip to content

Commit

Permalink
Merge pull request #725 from EcrituresNumeriques/fix/681
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot committed Jan 12, 2023
2 parents 13a5c96 + 760d44d commit 5ba7b1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
21 changes: 5 additions & 16 deletions front/src/components/Write/Versions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,11 @@ import styles from './versions.module.scss'
import menuStyles from './menu.module.scss'
import buttonStyles from '../button.module.scss'

import { generateArticleExportId } from '../../helpers/identifier'

import Modal from '../Modal'
import Export from '../Export'
import Button from '../Button'
import CreateVersion from './CreateVersion'

const date = new Intl.DateTimeFormat(['en', 'fr'], {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: 'numeric',
minute: 'numeric',
timeZone: 'UTC',
timeZoneName: 'short',
})

const dateFormat = date.format.bind(date)
import formatTimeAgo from '../../helpers/formatTimeAgo.js'

export default function Versions ({ article, selectedVersion, compareTo, readOnly }) {
const articleVersions = useSelector(state => state.articleVersions, shallowEqual)
Expand Down Expand Up @@ -89,10 +76,12 @@ export default function Versions ({ article, selectedVersion, compareTo, readOnl
<p>
{v.owner && (
<span>
by <strong>{v.owner.displayName}</strong>{' '}
by <strong>{v.owner.displayName}</strong>{', '}
</span>
)}
{<span>on <time dateTime={v.updatedAt}>{dateFormat(v.updatedAt)}</time></span>}
<span>
<time dateTime={v.updatedAt}>{formatTimeAgo(v.updatedAt)}</time>
</span>
</p>
<ul className={styles.actions}>
{v._id !== compareTo && (
Expand Down
2 changes: 1 addition & 1 deletion graphql/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ articleSchema.methods.unshareWith = async function shareWith(user) {

articleSchema.methods.createNewVersion = async function createNewVersion ({ mode, message, user }) {
const { bib, yaml, md } = this.workingVersion
const mostRecentVersion = this.version.at(0)
const mostRecentVersion = this.versions.at(0)

const { revision, version } = mode === 'MAJOR'
? computeMajorVersion(mostRecentVersion)
Expand Down
12 changes: 10 additions & 2 deletions graphql/resolvers/userResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,21 @@ module.exports = {

User: {
async articles(user, { limit }) {
await user.populate({ path: 'articles', options: { limit } }).execPopulate()
await user.populate({
path: 'articles',
options: { limit },
populate: { path: 'owner tags' }
}).execPopulate()

return user.articles
},

async article (user, { id: _id }) {
await user.populate({ path: 'articles', match: { _id }}).execPopulate()
await user.populate({
path: 'articles',
match: { _id },
populate: { path: 'owner tags' }
}).execPopulate()

return user.articles[0]
}
Expand Down

0 comments on commit 5ba7b1d

Please sign in to comment.