fix: ehm in realtà le pagine utente non funzionavano per niente
This commit is contained in:
@@ -10,7 +10,7 @@ import { MarkdownEditor } from '../components/MarkdownEditor'
|
||||
import { Select } from '../components/Select'
|
||||
import { Solution } from '../components/Solution'
|
||||
import { useListResource } from '../hooks'
|
||||
import { useCurrentUser } from '../hooks/useCurrentUser'
|
||||
import { useLoggedInUser } from '../hooks/useCurrentUser'
|
||||
|
||||
const CreateProblem = ({}) => {
|
||||
const [source, setSource] = useState('')
|
||||
@@ -55,7 +55,7 @@ const CreateProblem = ({}) => {
|
||||
type SortOrder = 'latest' | 'oldest'
|
||||
|
||||
export const AdminPage = ({}) => {
|
||||
const [user, ready] = useCurrentUser()
|
||||
const [user, ready] = useLoggedInUser()
|
||||
if (!ready) {
|
||||
return <></>
|
||||
}
|
||||
@@ -134,7 +134,7 @@ export const AdminPage = ({}) => {
|
||||
<>
|
||||
<hr />
|
||||
<div class="subtitle">Controlli speciali solo per Admin</div>
|
||||
|
||||
|
||||
{/* TODO: make this work */}
|
||||
<div class="scrollable">
|
||||
<div class="users-table" style={{ '--cols': 4 }}>
|
||||
@@ -145,7 +145,9 @@ export const AdminPage = ({}) => {
|
||||
|
||||
{users.map(user => (
|
||||
<>
|
||||
<div class="cell mono">{user.id}</div>
|
||||
<div class="cell">
|
||||
<a href={prependBaseUrl(`/u/${user.id}`)}>@{user.id}</a>
|
||||
</div>
|
||||
<div class="cell">{user.fullName}</div>
|
||||
<div class="cell">{user.role}</div>
|
||||
<div class="cell last-col">
|
||||
|
||||
@@ -8,7 +8,7 @@ import { MarkdownEditor } from '../components/MarkdownEditor'
|
||||
import { Problem } from '../components/Problem'
|
||||
import { Solution } from '../components/Solution'
|
||||
import { MetadataContext, useListResource, useResource, ServerContext, DatabaseContext, useServerAsyncCallback } from '../hooks'
|
||||
import { useCurrentUser } from '../hooks/useCurrentUser'
|
||||
import { useLoggedInUser } from '../hooks/useCurrentUser'
|
||||
|
||||
type RouteProps = {
|
||||
id: string
|
||||
@@ -27,7 +27,7 @@ export const ProblemPage = ({ id }: RouteProps) => {
|
||||
})
|
||||
}
|
||||
|
||||
const [user] = useCurrentUser()
|
||||
const [user] = useLoggedInUser()
|
||||
|
||||
const [source, setSource] = useState('')
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import { prependBaseUrl } from '../../shared/utils'
|
||||
import { Header } from '../components/Header'
|
||||
import { Solution } from '../components/Solution'
|
||||
import { useResource } from '../hooks'
|
||||
import { useCurrentUser, useUserFunctions } from '../hooks/useCurrentUser'
|
||||
import { useLoggedInUser, useUserFunctions } from '../hooks/useCurrentUser'
|
||||
|
||||
export const ProfilePage = ({}) => {
|
||||
const [user, ready] = useCurrentUser()
|
||||
const [user, ready] = useLoggedInUser()
|
||||
if (!ready) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
import { isAdministrator, Solution as SolutionModel, SolutionStat } from '../../shared/model'
|
||||
import { route } from 'preact-router'
|
||||
import { isAdministrator, Solution as SolutionModel, SolutionStat, SolutionStatMap, User } from '../../shared/model'
|
||||
import { sortByStringKey } from '../../shared/utils'
|
||||
import { prependBaseUrl } from '../../shared/utils'
|
||||
import { Header } from '../components/Header'
|
||||
import { Solution } from '../components/Solution'
|
||||
import { useResource } from '../hooks'
|
||||
import { useCurrentUser } from '../hooks/useCurrentUser'
|
||||
import { useLoggedInUser } from '../hooks/useCurrentUser'
|
||||
|
||||
type RouteProps = {
|
||||
uid: string
|
||||
}
|
||||
|
||||
export const UserPage = ({ uid }: RouteProps) => {
|
||||
const [user, ready] = useCurrentUser()
|
||||
if (!ready) {
|
||||
return <></>
|
||||
}
|
||||
// ottengo l'utente loggato, se è un admin le soluzioni devono mostrare i controlli speciali per admin
|
||||
const [currentUser] = useLoggedInUser()
|
||||
|
||||
const [stats] = useResource<null | Record<string, SolutionStat | undefined>>(`/api/stats`, null)
|
||||
// ottengo le info sull'utente di questa pagina
|
||||
const [user] = useResource<null | User>(`/api/user/${uid}`, null, user => {
|
||||
if (!user) {
|
||||
route(prependBaseUrl(`/error?message=${encodeURIComponent(`Non c'è ancora nessun utente con username "${uid}"`)}`), true)
|
||||
}
|
||||
})
|
||||
|
||||
// ottengo gli stat per l'utente di questa pagina
|
||||
const [stats] = useResource<null | SolutionStatMap>(`/api/stats`, null)
|
||||
if (!stats) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
const userStats = stats[uid]
|
||||
|
||||
// ottengo le soluzioni pubbliche dell'utente di questa pagina
|
||||
const [solutions, refreshSolutions] = useResource<SolutionModel[]>(`/api/solutions?user=${uid}&public`, [])
|
||||
const sortedSolutions = sortByStringKey(solutions, s => s.createdAt, false)
|
||||
|
||||
@@ -48,7 +56,7 @@ export const UserPage = ({ uid }: RouteProps) => {
|
||||
<Solution
|
||||
refreshSolution={refreshSolutions}
|
||||
{...solution}
|
||||
adminControls={user !== null && isAdministrator(user.role)}
|
||||
adminControls={currentUser !== null && isAdministrator(currentUser.role)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user