@@ -17,7 +17,13 @@ import LoadingContext from "../../utils/LoadingContext";
1717import Modal from "../../components/Modal" ;
1818import { WikiFields } from "./new" ;
1919
20- const Wiki = ( { page, token, userRole, slug } ) => {
20+ const sortSlug = ( a , b ) => {
21+ if ( a . slug > b . slug ) return 1 ;
22+ if ( a . slug < b . slug ) return - 1 ;
23+ return 0 ;
24+ } ;
25+
26+ const Wiki = ( { page, allPages, token, userRole, slug } ) => {
2127 const [ editing , setEditing ] = useState ( false ) ;
2228 const [ showDeleteModal , setShowDeleteModal ] = useState ( false ) ;
2329
@@ -161,24 +167,57 @@ const Wiki = ({ page, token, userRole, slug }) => {
161167 </ Text >
162168 </ Box >
163169 { ! editing ? (
164- < MarkdownBody >
165- < ReactMarkdown
166- remarkPlugins = { [ remarkGfm ] }
167- components = { {
168- a ( { href, ...props } ) {
169- return href . startsWith ( "http" ) ? (
170- < a href = { href } target = "_blank" { ...props } />
171- ) : (
172- < Link href = { href } passHref >
173- < a { ...props } />
174- </ Link >
175- ) ;
176- } ,
177- } }
170+ < Box
171+ display = "grid"
172+ gridTemplateColumns = { [ "1fr" , "200px auto" ] }
173+ gridGap = { 5 }
174+ >
175+ < Box
176+ bg = "sidebar"
177+ border = "1px solid"
178+ borderColor = "border"
179+ borderRadius = { 1 }
180+ p = { 3 }
178181 >
179- { page . body }
180- </ ReactMarkdown >
181- </ MarkdownBody >
182+ < Text
183+ fontWeight = { 600 }
184+ fontSize = { 1 }
185+ mb = { 3 }
186+ _css = { { textTransform : "uppercase" } }
187+ >
188+ Pages
189+ </ Text >
190+ { allPages . sort ( sortSlug ) . map ( ( p ) => (
191+ < Link
192+ key = { `page-${ p . slug } ` }
193+ href = { `/wiki/${ p . slug } ` }
194+ passHref
195+ >
196+ < Text as = "a" display = "block" >
197+ { p . title }
198+ </ Text >
199+ </ Link >
200+ ) ) }
201+ </ Box >
202+ < MarkdownBody >
203+ < ReactMarkdown
204+ remarkPlugins = { [ remarkGfm ] }
205+ components = { {
206+ a ( { href, ...props } ) {
207+ return href . startsWith ( "http" ) ? (
208+ < a href = { href } target = "_blank" { ...props } />
209+ ) : (
210+ < Link href = { href } passHref >
211+ < a { ...props } />
212+ </ Link >
213+ ) ;
214+ } ,
215+ } }
216+ >
217+ { page . body }
218+ </ ReactMarkdown >
219+ </ MarkdownBody >
220+ </ Box >
182221 ) : (
183222 < form onSubmit = { handleEdit } >
184223 < WikiFields values = { page } />
@@ -246,8 +285,10 @@ export const getServerSideProps = withAuthServerSideProps(
246285 ) {
247286 throw "banned" ;
248287 }
249- const page = await wikiRes . json ( ) ;
250- return { props : { page, token, userRole : role , slug : parsedSlug } } ;
288+ const { page, allPages } = await wikiRes . json ( ) ;
289+ return {
290+ props : { page, allPages, token, userRole : role , slug : parsedSlug } ,
291+ } ;
251292 } catch ( e ) {
252293 if ( e === "banned" ) throw "banned" ;
253294 return { props : { token, userRole : role , slug : parsedSlug } } ;
0 commit comments