mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 18:16:00 +00:00
custom markdown pages - basic concept
This commit is contained in:
41
packages/web/src/tabs/MarkdownViewTab.js
Normal file
41
packages/web/src/tabs/MarkdownViewTab.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import React from 'react';
|
||||
import axios from '../utility/axios';
|
||||
import LoadingInfo from '../widgets/LoadingInfo';
|
||||
import Markdown from 'markdown-to-jsx';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
padding: 10px;
|
||||
overflow: auto;
|
||||
flex: 1;
|
||||
`;
|
||||
|
||||
export default function MarkdownViewTab({ file }) {
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const [text, setText] = React.useState(null);
|
||||
|
||||
const handleLoad = async () => {
|
||||
setIsLoading(true);
|
||||
const resp = await axios.post('files/load', { folder: 'markdown', file, format: 'text' });
|
||||
setText(resp.data);
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
handleLoad();
|
||||
}, []);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<LoadingInfo message="Loading markdown page" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<Markdown>{text || ''}</Markdown>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user