mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 03:57:06 -04:00
Add prettier for codestyle and re-format everything (#1294)
This commit is contained in:
parent
8b78154075
commit
0aae1f70d2
319 changed files with 4809 additions and 3936 deletions
|
@ -15,7 +15,7 @@ import { GroupMode, PermissionGroupEntry } from './permission-group-entry'
|
|||
import { PermissionList } from './permission-list'
|
||||
|
||||
export interface PermissionsModalProps {
|
||||
show: boolean,
|
||||
show: boolean
|
||||
onHide: () => void
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ interface NotePermissions {
|
|||
sharedTo: {
|
||||
username: string
|
||||
canEdit: boolean
|
||||
}[],
|
||||
}[]
|
||||
sharedToGroup: {
|
||||
id: string
|
||||
canEdit: boolean
|
||||
|
@ -43,20 +43,26 @@ export const EVERYONE_LOGGED_IN_GROUP_ID = '2'
|
|||
|
||||
const permissionsApiResponse: NotePermissions = {
|
||||
owner: 'dermolly',
|
||||
sharedTo: [{
|
||||
username: 'emcrx',
|
||||
canEdit: true
|
||||
}, {
|
||||
username: 'mrdrogdrog',
|
||||
canEdit: false
|
||||
}],
|
||||
sharedToGroup: [{
|
||||
id: EVERYONE_GROUP_ID,
|
||||
canEdit: true
|
||||
}, {
|
||||
id: EVERYONE_LOGGED_IN_GROUP_ID,
|
||||
canEdit: false
|
||||
}]
|
||||
sharedTo: [
|
||||
{
|
||||
username: 'emcrx',
|
||||
canEdit: true
|
||||
},
|
||||
{
|
||||
username: 'mrdrogdrog',
|
||||
canEdit: false
|
||||
}
|
||||
],
|
||||
sharedToGroup: [
|
||||
{
|
||||
id: EVERYONE_GROUP_ID,
|
||||
canEdit: true
|
||||
},
|
||||
{
|
||||
id: EVERYONE_LOGGED_IN_GROUP_ID,
|
||||
canEdit: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export const PermissionModal: React.FC<PermissionsModalProps> = ({ show, onHide }) => {
|
||||
|
@ -70,7 +76,7 @@ export const PermissionModal: React.FC<PermissionsModalProps> = ({ show, onHide
|
|||
useEffect(() => {
|
||||
// set owner
|
||||
getUserById(permissionsApiResponse.owner)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
setOwner({
|
||||
name: response.name,
|
||||
photo: response.photo
|
||||
|
@ -78,20 +84,24 @@ export const PermissionModal: React.FC<PermissionsModalProps> = ({ show, onHide
|
|||
})
|
||||
.catch(() => setError(true))
|
||||
// set user List
|
||||
permissionsApiResponse.sharedTo.forEach(shareUser => {
|
||||
permissionsApiResponse.sharedTo.forEach((shareUser) => {
|
||||
getUserById(shareUser.username)
|
||||
.then(response => {
|
||||
setUserList(list => list.concat([{
|
||||
id: response.id,
|
||||
name: response.name,
|
||||
photo: response.photo,
|
||||
canEdit: shareUser.canEdit
|
||||
}]))
|
||||
.then((response) => {
|
||||
setUserList((list) =>
|
||||
list.concat([
|
||||
{
|
||||
id: response.id,
|
||||
name: response.name,
|
||||
photo: response.photo,
|
||||
canEdit: shareUser.canEdit
|
||||
}
|
||||
])
|
||||
)
|
||||
})
|
||||
.catch(() => setError(true))
|
||||
})
|
||||
// set group List
|
||||
permissionsApiResponse.sharedToGroup.forEach(sharedGroup => {
|
||||
permissionsApiResponse.sharedToGroup.forEach((sharedGroup) => {
|
||||
if (sharedGroup.id === EVERYONE_GROUP_ID) {
|
||||
setAllUserPermissions(sharedGroup.canEdit ? GroupMode.EDIT : GroupMode.VIEW)
|
||||
} else if (sharedGroup.id === EVERYONE_LOGGED_IN_GROUP_ID) {
|
||||
|
@ -101,70 +111,74 @@ export const PermissionModal: React.FC<PermissionsModalProps> = ({ show, onHide
|
|||
}, [])
|
||||
|
||||
const changeUserMode = (userId: Principal['id'], canEdit: Principal['canEdit']) => {
|
||||
setUserList(list =>
|
||||
list
|
||||
.map(user => {
|
||||
if (user.id === userId) {
|
||||
user.canEdit = canEdit
|
||||
}
|
||||
return user
|
||||
}))
|
||||
setUserList((list) =>
|
||||
list.map((user) => {
|
||||
if (user.id === userId) {
|
||||
user.canEdit = canEdit
|
||||
}
|
||||
return user
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const removeUser = (userId: Principal['id']) => {
|
||||
setUserList(list => list.filter(user => user.id !== userId))
|
||||
setUserList((list) => list.filter((user) => user.id !== userId))
|
||||
}
|
||||
|
||||
const addUser = (name: Principal['name']) => {
|
||||
setUserList(list => list.concat({
|
||||
id: name,
|
||||
photo: '/img/avatar.png',
|
||||
name: name,
|
||||
canEdit: false
|
||||
}))
|
||||
setUserList((list) =>
|
||||
list.concat({
|
||||
id: name,
|
||||
photo: '/img/avatar.png',
|
||||
name: name,
|
||||
canEdit: false
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<CommonModal
|
||||
show={ show }
|
||||
onHide={ onHide }
|
||||
closeButton={ true }
|
||||
titleI18nKey={ 'editor.modal.permissions.title' }>
|
||||
<CommonModal show={show} onHide={onHide} closeButton={true} titleI18nKey={'editor.modal.permissions.title'}>
|
||||
<Modal.Body>
|
||||
<h5 className={ 'mb-3' }><Trans i18nKey={ 'editor.modal.permissions.owner' }/></h5>
|
||||
<ShowIf condition={ error }>
|
||||
<h5 className={'mb-3'}>
|
||||
<Trans i18nKey={'editor.modal.permissions.owner'} />
|
||||
</h5>
|
||||
<ShowIf condition={error}>
|
||||
<Alert variant='danger'>
|
||||
<Trans i18nKey='editor.modal.permissions.error'/>
|
||||
<Trans i18nKey='editor.modal.permissions.error' />
|
||||
</Alert>
|
||||
</ShowIf>
|
||||
<ul className={ 'list-group' }>
|
||||
<li className={ 'list-group-item d-flex flex-row align-items-center' }>
|
||||
<UserAvatar name={ owner?.name ?? '' } photo={ owner?.photo ?? '' }/>
|
||||
<ul className={'list-group'}>
|
||||
<li className={'list-group-item d-flex flex-row align-items-center'}>
|
||||
<UserAvatar name={owner?.name ?? ''} photo={owner?.photo ?? ''} />
|
||||
</li>
|
||||
</ul>
|
||||
<h5 className={ 'my-3' }><Trans i18nKey={ 'editor.modal.permissions.sharedWithUsers' }/></h5>
|
||||
<h5 className={'my-3'}>
|
||||
<Trans i18nKey={'editor.modal.permissions.sharedWithUsers'} />
|
||||
</h5>
|
||||
<PermissionList
|
||||
list={ userList }
|
||||
identifier={ entry => (<UserAvatar name={ entry.name } photo={ entry.photo }/>) }
|
||||
changeEditMode={ changeUserMode }
|
||||
removeEntry={ removeUser }
|
||||
createEntry={ addUser }
|
||||
editI18nKey={ 'editor.modal.permissions.editUser' }
|
||||
viewI18nKey={ 'editor.modal.permissions.viewOnlyUser' }
|
||||
removeI18nKey={ 'editor.modal.permissions.removeUser' }
|
||||
addI18nKey={ 'editor.modal.permissions.addUser' }
|
||||
list={userList}
|
||||
identifier={(entry) => <UserAvatar name={entry.name} photo={entry.photo} />}
|
||||
changeEditMode={changeUserMode}
|
||||
removeEntry={removeUser}
|
||||
createEntry={addUser}
|
||||
editI18nKey={'editor.modal.permissions.editUser'}
|
||||
viewI18nKey={'editor.modal.permissions.viewOnlyUser'}
|
||||
removeI18nKey={'editor.modal.permissions.removeUser'}
|
||||
addI18nKey={'editor.modal.permissions.addUser'}
|
||||
/>
|
||||
<h5 className={ 'my-3' }><Trans i18nKey={ 'editor.modal.permissions.sharedWithGroups' }/></h5>
|
||||
<ul className={ 'list-group' }>
|
||||
<h5 className={'my-3'}>
|
||||
<Trans i18nKey={'editor.modal.permissions.sharedWithGroups'} />
|
||||
</h5>
|
||||
<ul className={'list-group'}>
|
||||
<PermissionGroupEntry
|
||||
title={ 'editor.modal.permissions.allUser' }
|
||||
editMode={ allUserPermissions }
|
||||
onChangeEditMode={ setAllUserPermissions }
|
||||
title={'editor.modal.permissions.allUser'}
|
||||
editMode={allUserPermissions}
|
||||
onChangeEditMode={setAllUserPermissions}
|
||||
/>
|
||||
<PermissionGroupEntry
|
||||
title={ 'editor.modal.permissions.allLoggedInUser' }
|
||||
editMode={ allLoggedInUserPermissions }
|
||||
onChangeEditMode={ setAllLoggedInUserPermissions }
|
||||
title={'editor.modal.permissions.allLoggedInUser'}
|
||||
editMode={allLoggedInUserPermissions}
|
||||
onChangeEditMode={setAllLoggedInUserPermissions}
|
||||
/>
|
||||
</ul>
|
||||
</Modal.Body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue