Merge pull request #20 from pawelmalak/raw-snippets

Added support for raw snippets
This commit is contained in:
pawelmalak
2021-10-05 14:25:20 +02:00
committed by GitHub
5 changed files with 59 additions and 14 deletions

View File

@@ -1,3 +1,6 @@
### v1.3.1 (2021-10-05)
- Added support for raw snippets ([#15](https://github.com/pawelmalak/snippet-box/issues/15))
### v1.3 (2021-09-30) ### v1.3 (2021-09-30)
- Added dark mode ([#7](https://github.com/pawelmalak/snippet-box/issues/7)) - Added dark mode ([#7](https://github.com/pawelmalak/snippet-box/issues/7))
- Added syntax highlighting ([#14](https://github.com/pawelmalak/snippet-box/issues/14)) - Added syntax highlighting ([#14](https://github.com/pawelmalak/snippet-box/issues/14))

View File

@@ -31,9 +31,9 @@ export const SnippetDetails = (props: Props): JSX.Element => {
const creationDate = dateParser(createdAt); const creationDate = dateParser(createdAt);
const updateDate = dateParser(updatedAt); const updateDate = dateParser(updatedAt);
const copyHandler = () => { // const copyHandler = () => {
copy(code); // copy(code);
}; // };
return ( return (
<Card> <Card>
@@ -74,6 +74,14 @@ export const SnippetDetails = (props: Props): JSX.Element => {
{/* ACTIONS */} {/* ACTIONS */}
<div className='d-grid g-2' style={{ rowGap: '10px' }}> <div className='d-grid g-2' style={{ rowGap: '10px' }}>
<Button
text='Delete'
color='danger'
small
outline
handler={() => deleteSnippet(id)}
/>
<Button <Button
text='Edit' text='Edit'
color='secondary' color='secondary'
@@ -87,18 +95,24 @@ export const SnippetDetails = (props: Props): JSX.Element => {
}); });
}} }}
/> />
<Button <Button
text='Delete' text='Copy raw url'
color='danger' color='secondary'
small small
outline outline
handler={() => deleteSnippet(id)} handler={() => {
const { protocol, host } = window.location;
const rawUrl = `${protocol}//${host}/api/snippets/raw/${id}`;
copy(rawUrl);
}}
/> />
<Button <Button
text='Copy code' text='Copy code'
color='secondary' color='secondary'
small small
handler={copyHandler} handler={() => copy(code)}
/> />
</div> </div>
</Card> </Card>

View File

@@ -10,16 +10,16 @@ $gray-700: #495057;
$gray-800: #343a40; $gray-800: #343a40;
$gray-900: #212529; $gray-900: #212529;
$black: #000; $black: #000;
$blue: #3459e6; $blue: #375a7f;
$indigo: #6610f2; $indigo: #6610f2;
$purple: #6f42c1; $purple: #6f42c1;
$pink: #d63384; $pink: #e83e8c;
$red: #da292e; $red: #e74c3c;
$orange: #f8765f; $orange: #fd7e14;
$yellow: #f4bd61; $yellow: #f39c12;
$green: #2fb380; $green: #00bc8c;
$teal: #20c997; $teal: #20c997;
$cyan: #287bb5; $cyan: #3498db;
$primary: $blue; $primary: $blue;
$secondary: $white; $secondary: $white;
$success: $green; $success: $green;

View File

@@ -209,3 +209,28 @@ export const countTags = asyncWrapper(
}); });
} }
); );
/**
* @description Get raw snippet code
* @route /api/snippets/raw/:id
* @request GET
*/
export const getRawCode = asyncWrapper(
async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const snippet = await SnippetModel.findOne({
where: { id: req.params.id },
raw: true
});
if (!snippet) {
return next(
new ErrorResponse(
404,
`Snippet with id of ${req.params.id} was not found`
)
);
}
res.status(200).send(snippet.code);
}
);

View File

@@ -4,6 +4,7 @@ import {
createSnippet, createSnippet,
deleteSnippet, deleteSnippet,
getAllSnippets, getAllSnippets,
getRawCode,
getSnippet, getSnippet,
updateSnippet updateSnippet
} from '../controllers/snippets'; } from '../controllers/snippets';
@@ -23,3 +24,5 @@ snippetRouter
.delete(deleteSnippet); .delete(deleteSnippet);
snippetRouter.route('/statistics/count').get(countTags); snippetRouter.route('/statistics/count').get(countTags);
snippetRouter.route('/raw/:id').get(getRawCode);