-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: view remote markdown, sticky title with button and save check
- Loading branch information
1 parent
1b022ed
commit b00df83
Showing
27 changed files
with
716 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.