+
diff --git a/client/src/components/AddSnippet/SaveModal.jsx b/client/src/components/AddSnippet/SaveModal.jsx
index d5c8e25..43a8625 100644
--- a/client/src/components/AddSnippet/SaveModal.jsx
+++ b/client/src/components/AddSnippet/SaveModal.jsx
@@ -1,13 +1,7 @@
-import React, { useState} from 'react';
-import Modal from 'react-bootstrap/Modal';
+import React from 'react';
function SaveModal() {
-
- return (
-
- You have successfully saved a snippet!
-
- )
+ return
You have successfully saved a snippet!
;
}
export default SaveModal;
diff --git a/client/src/components/SnippetDisplay/SnippetDisplay.jsx b/client/src/components/SnippetDisplay/SnippetDisplay.jsx
index 2bba1ca..548ff6f 100644
--- a/client/src/components/SnippetDisplay/SnippetDisplay.jsx
+++ b/client/src/components/SnippetDisplay/SnippetDisplay.jsx
@@ -1,30 +1,34 @@
import React, { useState } from 'react';
-// import Snippet from
+
+// importing child components
+import TagInput from '../../components/ui/TagInput/TagInput';
+
+// importing external functionality
import { CopyToClipboard } from 'react-copy-to-clipboard';
import CodeMirror from '@uiw/react-codemirror';
import styles from './SnippetDisplay.module.scss';
import { langs } from '@uiw/codemirror-extensions-langs';
-import TagInput from '../../components/ui/TagInput/TagInput';
-import {Card, Button} from 'react-bootstrap';
+
+// importing utils
+import { Card, Button } from 'react-bootstrap';
+
const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
- // indSnippet = this.props
- // create delete method using fetch request
let snippetTitle = selectedSnippet.title ? selectedSnippet.title : '';
- let snippetLanguage = selectedSnippet.language ? selectedSnippet.language : '';
- let snippetComments = selectedSnippet.comments ? selectedSnippet.comments : '';
- let snippetStoredCode = selectedSnippet.storedCode ? selectedSnippet.storedCode : '';
+ let snippetLanguage = selectedSnippet.language
+ ? selectedSnippet.language
+ : '';
+ let snippetComments = selectedSnippet.comments
+ ? selectedSnippet.comments
+ : '';
+ let snippetStoredCode = selectedSnippet.storedCode
+ ? selectedSnippet.storedCode
+ : '';
let snippetTagList = selectedSnippet.tags ? selectedSnippet.tags : [];
- // create a state variable for each passed down state and the its setState function
- // const [title, setTitle] = useState(snippetTitle);
- // const [language, setLanguage] = useState(snippetLanguage);
- // const [comments, setComments] = useState(snippetComments);
- // const [storedCode, setStoredCode] = useState(snippetStoredCode);
- // const [tagList, setTags] = useState(snippetTagList);
const [editButtonState, setEditButtonState] = useState(false);
const deleteSnippet = (id) => {
- fetch (`http://localhost:3000/snippets?id=${id}`, {
+ fetch(`/snippets?id=${id}`, {
method: 'DELETE',
})
.then((response) => {
@@ -33,13 +37,13 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
}
})
.catch((err) => {
- return ({
+ return {
log: `SnippetDisiplay.deleteSnippet: Error: ${err}`,
status: err.status || 500,
- message: 'There was an error deleting snippet.'
- })
- })
- }
+ message: 'There was an error deleting snippet.',
+ };
+ });
+ };
const editSnippet = (id) => {
// const [oldState, setOldState] = React.useState([]);
@@ -50,55 +54,49 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
comments: snippetComments,
storedCode: snippetStoredCode,
tags: snippetTagList,
- language: snippetLanguage
+ language: snippetLanguage,
};
// within fetch request (post)
// body: JSON.stringify(created object)
- fetch (`/snippets?id=${id}`, {
+ fetch(`/snippets?id=${id}`, {
method: 'PUT',
- body: JSON.stringify(updatedSnippet)
+ body: JSON.stringify(updatedSnippet),
})
.then((response) => {
response.json();
getSnippet();
})
.catch((err) => {
- return ({
+ return {
log: `SnippetDisplay.editSnippet: Error: ${err}`,
status: err.status || 500,
- message: 'There was an error editing code snippet.'
- });
+ message: 'There was an error editing code snippet.',
+ };
});
};
- // copy code state
+ // copy code state
const [copied, setCopied] = useState(false);
-
const checkEdit = () => {
if (editButtonState === true) {
- return(
+ return (
);
}
@@ -148,12 +144,20 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
if (editButtonState === false) {
return (
-
-
-
Title: {snippetTitle}
-
Language: {snippetLanguage}
-
Comments: {snippetComments}
-
+
+
+ {' '}
+ Title: {snippetTitle}
+
+
+ {' '}
+ Language: {snippetLanguage}
+
+
+ {' '}
+ Comments: {snippetComments}
+
+
{/*
{renderTags()}
*/}
@@ -167,43 +171,42 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
options={{
readOnly: true,
}}
- onChange={(e) => snippetStoredCode = (e)}
- >
+ onChange={(e) => (snippetStoredCode = e)}>
setCopied(true)}
- >
+ onCopy={() => setCopied(true)}>
Copy Code Snippet
-
);
}
};
-
+
return (
- <>
-
- {checkEdit()}
-
-
- {deleteSnippet(selectedSnippet.id)}}>
- Delete Snippet
-
- {
- // editSnippet(selectedSnippet.id);
- setEditButtonState(true);
- }}>
- Edit Snippet
-
-
+
+
+ {checkEdit()}
+
+
+ {
+ deleteSnippet(selectedSnippet.id);
+ }}>
+ Delete Snippet
+
+ {
+ // editSnippet(selectedSnippet.id);
+ setEditButtonState(true);
+ }}>
+ Edit Snippet
+
+
- >
+
);
};
diff --git a/client/src/components/ui/TagInput/TagInput.jsx b/client/src/components/ui/TagInput/TagInput.jsx
index 44f4a78..67a5a6a 100644
--- a/client/src/components/ui/TagInput/TagInput.jsx
+++ b/client/src/components/ui/TagInput/TagInput.jsx
@@ -1,9 +1,14 @@
-import React, { useEffect } from 'react';
-import { TAGS } from '../../../data/data';
-import styles from './TagInput.module.scss';
+import React, { useState, useEffect } from 'react';
+
+// importing utils
import { WithContext as ReactTags } from 'react-tag-input';
import PropTypes from 'prop-types';
+// importing data
+import { TAGS } from '../../../data/data';
+
+// importing styles
+
const suggestions = TAGS.map((tag) => {
return {
id: tag,
@@ -19,8 +24,7 @@ const KeyCodes = {
const delimiters = [KeyCodes.comma, KeyCodes.enter];
const TagInput = (props) => {
-
- const [tags, setTags] = React.useState([]);
+ const [tags, setTags] = useState([]);
const handleDelete = (i) => {
setTags(tags.filter((tag, index) => index !== i));
diff --git a/client/src/components/ui/TagInput/TagInput.module.scss b/client/src/components/ui/TagInput/TagInput.module.scss
deleted file mode 100644
index e69de29..0000000
diff --git a/client/src/containers/MainContainer/MainContainer.jsx b/client/src/containers/MainContainer/MainContainer.jsx
index 2954daf..73950ba 100644
--- a/client/src/containers/MainContainer/MainContainer.jsx
+++ b/client/src/containers/MainContainer/MainContainer.jsx
@@ -1,14 +1,17 @@
import React from 'react';
+
+// importing child components
import Sidebar from '../Sidebar/Sidebar.jsx';
-import styles from './MainContainer.module.scss';
+// importing styles
+import styles from './MainContainer.module.scss';
-const MainContainer = () =>{
- return (
+const MainContainer = () => {
+ return (
- );
-}
+ );
+};
-export default MainContainer;
\ No newline at end of file
+export default MainContainer;
diff --git a/client/src/containers/Sidebar/Sidebar.jsx b/client/src/containers/Sidebar/Sidebar.jsx
index 7177f59..29125c7 100644
--- a/client/src/containers/Sidebar/Sidebar.jsx
+++ b/client/src/containers/Sidebar/Sidebar.jsx
@@ -1,15 +1,23 @@
import React, { useState, useEffect } from 'react';
+
+// importing child components
import SnippetDisplay from '../../components/SnippetDisplay/SnippetDisplay.jsx';
import AddSnippet from '../../components/AddSnippet/AddSnippet.jsx';
-import styles from './Sidebar.module.scss';
import SnippetsRadioList from './SnippetsRadioList/SnippetsRadioList.jsx';
+
+// importing utils
import { Card, Spinner } from 'react-bootstrap';
+
+// importing styles
+import styles from './Sidebar.module.scss';
+
+// importing assets
import arrow from '../../assets/arrow.png';
import img from '../../assets/star nose mole.jpeg';
const Sidebar = () => {
const [snippets, setSnippets] = useState([]);
- const [selectedSnippet, setSelectedSnippet] = useState({});
+ const [selectedSnippet, setSelectedSnippet] = useState();
const [openModal, setOpenModal] = useState(false);
const [collapse, setCollapse] = useState(false);
const [loading, setLoading] = useState(true);
@@ -17,49 +25,43 @@ const Sidebar = () => {
// getSnippet func
const getSnippet = () => {
setLoading(true);
- fetch('http://localhost:3000/snippets')
+ fetch('/snippets')
.then((res) => res.json())
.then((res) => {
- console.log('res', res);
-
// moved setSnippets to outside of for loop so we arent re-rendering each time a snippet is added to state
const newSnippetArray = [];
- for (const snippet of res.snippets) newSnippetArray.push(snippet);
+
+ for (const snippet of res.snippets) {
+ newSnippetArray.push(snippet);
+ }
setSnippets(newSnippetArray);
setLoading(false);
})
.catch((error) => console.log('Get request failed', error));
};
-
- // renderTags function
- const renderTabs = () => {
- const tabs = [];
-
- for (let i = 0; i < snippets.length; i++) {
- tabs.push({snippets[i].title} );
- }
-
- return tabs;
- };
+
+ useEffect(() => getSnippet(), []);
// wrapper to send to our snippets radio list for updating selected snippet. probably not 100% needed, but want to be able to console log from Sidebar
const setSelectedSnippetWrapper = (e) => {
setSelectedSnippet(e);
};
- // get data from backend at first page load
- useEffect(() => getSnippet(), []);
const toggleSidebar = () => {
setCollapse(() => !collapse);
};
return (
- <>
+
+ {/*----- SIDE BAR -----*/}
Code Snippets
+
+ {/* Changes the collapse state, which will render/unrender the sidebar*/}
+
{
/>
+
+ {/* Renders the list of snippets fetched from DB */}
+
+ {/* Animation while app is fetching data from DB */}
- {/* render our snippet list, pass down snippets and function to update selectedSnippet */}
{loading && (
-
+
)}
{
/>
-
- Click me to add a new snippet!
+
+
+ Click me to add a new snippet!
+
{
setOpenModal(true);
- }}
- >
-
+ }}>
+
-
+
+ {/*----- ADD SNIPPET MODAL -----*/}
+
{openModal && }
+
+ {/*----- SNIPPET DISPLAY -----*/}
+
- {snippets && (
+ }`}>
+ {selectedSnippet && (
)}
- >
+
);
};
diff --git a/client/src/containers/Sidebar/SnippetsRadioList/SnippetsRadioList.jsx b/client/src/containers/Sidebar/SnippetsRadioList/SnippetsRadioList.jsx
index 5fae115..6a9a805 100644
--- a/client/src/containers/Sidebar/SnippetsRadioList/SnippetsRadioList.jsx
+++ b/client/src/containers/Sidebar/SnippetsRadioList/SnippetsRadioList.jsx
@@ -1,6 +1,10 @@
+import React, { Fragment } from 'react';
+
+// importing utils
import PropTypes from 'prop-types';
+
+// importing styles
import styles from './SnippetsRadioList.module.scss';
-import { Fragment } from 'react';
function SnippetsRadioList(props) {
// call passed in function on changed button, should find a way to do this without having to iterate through snippet array. store the snippet on the input itself somehow?
@@ -16,59 +20,40 @@ function SnippetsRadioList(props) {
if (props.snippets) {
props.snippets.forEach((el, i) => {
- const currButton =
- i === 0 ? (
-
-
-
-
-
{el.title}
- {el.language}
-
- {el.storedCode}
-
-
-
- ) : (
-
-
-
-
-
{el.title}
- {el.language}
-
- {el.storedCode}
-
-
-
- );
+ const currButton = (
+
+
+
+
+
{el.title}
+ {el.language}
+
+ {el.storedCode}
+
+
+
+ );
toggleButtons.push(currButton);
});
}
return (
- <>
+
onChangeValue(e)}
- >
+ onChange={(e) => {
+ onChangeValue(e);
+ }}>
{toggleButtons}
- >
+
);
}
diff --git a/server/server.js b/server/server.js
index 855cf32..36651a4 100644
--- a/server/server.js
+++ b/server/server.js
@@ -1,4 +1,3 @@
-const path = require('path');
const express = require('express');
const app = express();
const mongoose = require('mongoose');