@@ -152,40 +146,38 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
if (editButtonState === false) {
return (
-
-
+
+
{' '}
- Title: {snippetTitle}
+ Title: {snippetTitle}
-
+
{' '}
Language: {snippetLanguage}
-
+
{' '}
Comments: {snippetComments}
-
+
{/*
{renderTags()}
*/}
{\n console.log(\'Hello World!)\n}'}
options={{
- readOnly: true
+ readOnly: true,
}}
- onChange={(e) => (snippetStoredCode = e)}
- >
+ onChange={(e) => (snippetStoredCode = e)}>
setCopied(true)}
- >
-
+ onCopy={() => setCopied(true)}>
+
@@ -194,31 +186,29 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
};
return (
- <>
+
{checkEdit()}
- >
+
);
};
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(
);
- }
-
- 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!
+
-
+
+ {/*----- 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 ? (
-
-
-
-
-
- ) : (
-
-
-
-
-
- );
+ const currButton = (
+
+
+
+
+
+ );
toggleButtons.push(currButton);
});
}
return (
- <>
+
onChangeValue(e)}
- >
+ onChange={(e) => {
+ onChangeValue(e);
+ }}>
{toggleButtons}
- >
+
);
}
diff --git a/server/server.js b/server/server.js
index 528aa96..9f77e1b 100644
--- a/server/server.js
+++ b/server/server.js
@@ -1,4 +1,3 @@
-const path = require('path');
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');