Skip to content

Commit

Permalink
feat: view remote markdown, sticky title with button and save check
Browse files Browse the repository at this point in the history
  • Loading branch information
dmijatovic committed Feb 3, 2022
1 parent 1b022ed commit b00df83
Show file tree
Hide file tree
Showing 27 changed files with 716 additions and 255 deletions.
3 changes: 2 additions & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Based on the features in the legacy application and the current requirements we

- intall dependencies `yarn install`
- create env.local and env.production.local file. Use env.local.example as template.
- run `yarn dev` to start application in development mode
- run all app modules `docker-compose up`
- open another terminal and run `yarn dev` to start application in development mode

### Environment variables

Expand Down
7 changes: 3 additions & 4 deletions frontend/auth/ProtectedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {useState,useEffect} from 'react'
import {useAuth} from '.'

import PageErrorMessage from '../components/layout/PageErrorMessage'
import ContentInTheMiddle from '../components/layout/ContentInTheMiddle'
import ContentLoader from '../components/layout/ContentLoader'
import {isMaintainerOfSoftware} from '../utils/editSoftware'
import logger from '../utils/logger'
Expand Down Expand Up @@ -43,7 +42,7 @@ export default function ProtectedContent({children, slug}: { children: any, slug
} else if (session?.status) {
setStatus(session.status)
}
() => { abort = true }
return () => { abort = true }
}, [slug, session.token, session?.user?.account, session.status])

// return nothing
Expand All @@ -65,7 +64,7 @@ export default function ProtectedContent({children, slug}: { children: any, slug
if (status !== 'authenticated') {
return (
<PageErrorMessage
statusCode={401}
status={401}
message='UNAUTHORIZED'
/>
)
Expand All @@ -74,7 +73,7 @@ export default function ProtectedContent({children, slug}: { children: any, slug
// authenticated but not maintainer = 403
return (
<PageErrorMessage
statusCode={403}
status={403}
message='FORBIDDEN'
/>
)
Expand Down
12 changes: 5 additions & 7 deletions frontend/components/form/MarkdownInputWithPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useState, useRef, useEffect} from 'react'
import Tabs from '@mui/material/Tabs'
import Tab from '@mui/material/Tab'

import ReactMarkdown from 'react-markdown'
import ReactMarkdownWithSettings from '../layout/ReactMarkdownWithSettings'

export default function MarkdownInputWithPreview({markdown,register,disabled=true,autofocus=false}:
{ markdown:string, register: any, disabled?:boolean,autofocus?:boolean }) {
Expand Down Expand Up @@ -87,12 +87,10 @@ export default function MarkdownInputWithPreview({markdown,register,disabled=tru
hidden={tab!==1}
>
<div>
<ReactMarkdown
className="prose py-4 px-8"
linkTarget="_blank"
>
{markdown}
</ReactMarkdown>
<ReactMarkdownWithSettings
className='py-4 px-8'
markdown={markdown}
/>
</div>
</div>
</article>
Expand Down
86 changes: 0 additions & 86 deletions frontend/components/form/RemoteMarkdown.tsx

This file was deleted.

101 changes: 101 additions & 0 deletions frontend/components/form/RemoteMarkdownPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {useState,useEffect} from 'react'
import TextFieldWithCounter from './TextFieldWithCounter'
import ReactMarkdownWithSettings from '../layout/ReactMarkdownWithSettings'
import PageErrorMessage from '../layout/PageErrorMessage'
import {getRemoteMarkdown} from '../../utils/getSoftware'

type RemoteMarkdownPreviewType = {
register: any,
errors: any,
url: string,
label: string,
help: string
}

export default function RemoteMarkdownPreview({register, errors, url, label, help}: RemoteMarkdownPreviewType) {
// const [markdown, setMarkdown] = useState('')
// const [error, setError] = useState<{ statusCode: number, message: string }>()
const [state, setState] = useState<{
markdown: string | null,
error: {
status: number | null,
message: string | null
}
}>({
markdown: null,
error: {
status:null,
message: null
}
})

useEffect(() => {
let abort = false
if (typeof errors == 'undefined' && url?.length > 9) {
// debugger
getRemoteMarkdown(url)
.then(markdown => {
// on abort exit
if (abort) return
// markdown is string
if (typeof markdown === 'string') {
setState({
markdown,
error: {
status: null,
message: null
}
})
} else {
// create error
setState({
markdown: null,
error: {
...markdown
}
})
}
})
} else {
// debugger
setState({
markdown: null,
error: {
status: 400,
message: 'Invalid information'
}
})
}
return ()=>{abort=true}
},[url, errors])

return (
<div>
<TextFieldWithCounter
options={{
// autofocus: formData?.description_type === 'link',
// disabled,
error: errors !== undefined,
label,
helperTextMessage: errors?.message ?? help,
helperTextCnt:`${url?.length || 0}/200`
}}
register={register}
/>
<h2 className="py-4 text-sm font-medium text-primary tracking-[0.125rem] uppercase">PREVIEW</h2>
<div className="border rounded-sm min-h-[33rem] flex">
{state.error?.status ?
<PageErrorMessage
status={state.error?.status ?? undefined}
message={state.error?.message ?? 'Server error'}
/>
:
<ReactMarkdownWithSettings
className='py-4 px-8'
markdown={state?.markdown ?? ''}
/>
}
</div>
</div>
)
}
6 changes: 3 additions & 3 deletions frontend/components/layout/PageErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ContentInTheMiddle from './ContentInTheMiddle'

export default function ContentErrorMessage({statusCode = 500, message = 'Failed to process you request'}: {
statusCode:number, message:string
export default function PageErrorMessage({status = 500, message = 'Failed to process you request'}: {
message:string, status?:number
}) {
return (
<ContentInTheMiddle>
<section className="flex justify-center items-center text-secondary">
<h1 className="border-r-2 px-4 font-medium">{statusCode}</h1>
<h1 className="border-r-2 px-4 font-medium">{status}</h1>
<p className="px-4 tracking-wider">{message}</p>
</section>
</ContentInTheMiddle>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/layout/PageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const PageTitleStyled = styled('section')(({theme})=>({
padding: '1rem 0rem 1rem 0rem',
alignItems: 'center',
// borderBottom: `1px solid ${theme.palette.divider}`,
// backgroundColor: theme.palette.background.paper,
backgroundColor: theme.palette.background.paper,
zIndex: 9,
'@media (max-width: 640px)':{
flexDirection:'column',
Expand Down
13 changes: 13 additions & 0 deletions frontend/components/layout/ReactMarkdownWithSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ReactMarkdown from 'react-markdown'

export default function ReactMarkdownWithSettings({markdown, className}:{markdown:string, className?:string}) {
return (
<ReactMarkdown
className={`prose ${className}`}
linkTarget="_blank"
skipHtml={true}
>
{markdown ?? ''}
</ReactMarkdown>
)
}
8 changes: 8 additions & 0 deletions frontend/components/layout/StickyHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function StickyHeader({children,className}:{children:any,className?:string}) {
return (
<section className={`sticky top-0 z-10 ${className}`}>
{children}
</section>
)
}
6 changes: 5 additions & 1 deletion frontend/components/software/AboutSourceCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export default function AboutSourceCode({repository=[]}:{repository: string[]})
} else {
return (
<a key={pos} href={item} title="Repository" target="_blank" rel="noreferrer">
<FolderOpenIcon />
<FolderOpenIcon sx={{
width: '3rem',
height: '3rem',
color: 'secondary'
}} />
</a>
)
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/components/software/AboutStatement.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import ReactMarkdown from 'react-markdown'
import ReactMarkdownWithSettings from '../layout/ReactMarkdownWithSettings'


export default function AboutStatement({brand_name = '', description = ''}:
Expand All @@ -16,9 +16,9 @@ export default function AboutStatement({brand_name = '', description = ''}:
>
What {brand_name} can do for you
</h2>
<ReactMarkdown className="prose">
{description}
</ReactMarkdown>
<ReactMarkdownWithSettings
markdown={description}
/>
</>
)
}
18 changes: 13 additions & 5 deletions frontend/components/software/edit/EditSoftwareNav.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {useContext} from 'react'
import List from '@mui/material/List'
import ListItemButton from '@mui/material/ListItemButton'
import ListItemIcon from '@mui/material/ListItemIcon'
import ListItemText from '@mui/material/ListItemText'

import {editSoftwareMenu, EditSoftwarePage} from '../../../components/software/edit/editSoftwareSteps'
import {editSoftwareMenu} from '../../../components/software/edit/editSoftwareSteps'
import editSoftwareContext from './editSoftwareContext'

export default function EditSoftwareNav({onChangeStep}:
{ onChangeStep: Function }) {
const {pageState} = useContext(editSoftwareContext)

export default function EditSoftwareNav({step, setStep}:
{ step: EditSoftwarePage, setStep: Function }) {
return (
<nav>
<List sx={{
Expand All @@ -16,8 +20,12 @@ export default function EditSoftwareNav({step, setStep}:
return (
<ListItemButton
key={`step-${pos}`}
selected={item.label===step.label}
onClick={()=>setStep(editSoftwareMenu[pos])}
selected={item.label === pageState?.step?.label ?? ''}
onClick={() => {
onChangeStep({
nextStep: editSoftwareMenu[pos]
})
}}
>
<ListItemIcon>
{item.icon}
Expand Down
Loading

0 comments on commit b00df83

Please sign in to comment.