Skip to content

Commit

Permalink
Display session scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vas9ka committed Jul 16, 2024
1 parent f37f23e commit db300ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
7 changes: 1 addition & 6 deletions src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,7 @@ function ScopeContents(props: TabsProps, session: Session): JSX.Element {
props.onSave()
}

return (
<ScopeEditor
updateScopes={updateScopes}
session={session} // Ensure session is passed as a prop
/>
)
return <ScopeEditor updateScopes={updateScopes} session={session} />
}

export default ScopeContents
28 changes: 15 additions & 13 deletions src/fragmentarium/ui/fragment/ScopeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { Session } from 'auth/Session'
import React, { useState } from 'react'

import applicationScopes from 'auth/applicationScopes.json'
interface ScopeEditorProps {
updateScopes: (scopes: string) => void
session: Session
}

const ScopeEditor: React.FC<ScopeEditorProps> = ({ updateScopes, session }) => {
const [scopes, setScopes] = useState({
readWords: session.isAllowedToReadWords(),
writeWords: session.isAllowedToWriteWords(),
readFragments: session.isAllowedToReadFragments(),
transliterateFragments: session.isAllowedToTransliterateFragments(),
lemmatizeFragments: session.isAllowedToLemmatizeFragments(),
annotateFragments: session.isAllowedToAnnotateFragments(),
readBibliography: session.isAllowedToReadBibliography(),
writeBibliography: session.isAllowedToWriteBibliography(),
readTexts: session.isAllowedToReadTexts(),
writeTexts: session.isAllowedToWriteTexts(),
accessBeta: session.hasBetaAccess(),
const fragmentScopeRegex = /^read[A-Z][a-zA-Z]*Fragments$/
const fragmentScopes = Object.fromEntries(
Object.entries(applicationScopes).filter(([key, value]) =>
fragmentScopeRegex.test(key)
)
)

const [scopes, setScopes] = useState(() => {
const initialScopes: { [key: string]: boolean } = {}
Object.keys(fragmentScopes).forEach((scope) => {
initialScopes[scope] = true
// initialScopes[scope] = session.has(scope)
})
return initialScopes
})

const handleCheckboxChange = (scope: string) => {
Expand Down

0 comments on commit db300ad

Please sign in to comment.