mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 18:25:21 -04:00
Add revisions dialog (#485)
* Add mock files Note that revisions-list needs to be called revisions in the reality to be confirm with the API spec, but our mocking solution doesn't allow that... * Add revisions API calls * Fix line endings in mock files * Extend CommonModal to accept size and additionalClasses * Clarify variable name in API request * Add react-diff-viewer as dependency * Add revision chooser modal * Fix type of route params * Added and updated mock files * Added user-icon list per revision * Added translation to alt text of avatars * Updated mock file to remove inconsistencies * Add caching for revisions * Sort mock file revisions-list descending by timestamp * Pre-select first/newest revision on first modal open * Regenerated yarn.lock file from scratch * Applied requested changes in variable names and line lengths * User UserAvatar component instead of manually set image * Move revision-modal-list-entry to own component * Removed unnecessary return statements
This commit is contained in:
parent
0fecda027c
commit
d597438c42
23 changed files with 455 additions and 29 deletions
39
src/components/editor/document-bar/revisions/utils.ts
Normal file
39
src/components/editor/document-bar/revisions/utils.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { Revision } from '../../../../api/revisions'
|
||||
import { getUserById } from '../../../../api/users'
|
||||
import { UserResponse } from '../../../../api/users/types'
|
||||
|
||||
const userResponseCache = new Map<string, UserResponse>()
|
||||
|
||||
export const downloadRevision = (noteId: string, revision: Revision | null): void => {
|
||||
if (!revision) {
|
||||
return
|
||||
}
|
||||
const encoded = Buffer.from(revision.content).toString('base64')
|
||||
const wrapper = document.createElement('a')
|
||||
wrapper.download = `${noteId}-${revision.timestamp}.md`
|
||||
wrapper.href = `data:text/markdown;charset=utf-8;base64,${encoded}`
|
||||
document.body.appendChild(wrapper)
|
||||
wrapper.click()
|
||||
document.body.removeChild(wrapper)
|
||||
}
|
||||
|
||||
export const getUserDataForRevision = (authors: string[]): UserResponse[] => {
|
||||
const users: UserResponse[] = []
|
||||
authors.forEach((author, index) => {
|
||||
if (index > 9) {
|
||||
return
|
||||
}
|
||||
const cacheEntry = userResponseCache.get(author)
|
||||
if (cacheEntry) {
|
||||
users.push(cacheEntry)
|
||||
return
|
||||
}
|
||||
getUserById(author)
|
||||
.then(userData => {
|
||||
users.push(userData)
|
||||
userResponseCache.set(author, userData)
|
||||
})
|
||||
.catch((error) => console.error(error))
|
||||
})
|
||||
return users
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue