diff --git a/client/src/components/SnippetDisplay/SnippetDisplay.jsx b/client/src/components/SnippetDisplay/SnippetDisplay.jsx index c15fc78..5c98f9b 100644 --- a/client/src/components/SnippetDisplay/SnippetDisplay.jsx +++ b/client/src/components/SnippetDisplay/SnippetDisplay.jsx @@ -20,7 +20,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { language: '', comments: '', storedCode: '', - tags: [], + tags: [] }; const [copied, setCopied] = useState(false); @@ -40,7 +40,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { const deleteSnippet = (snippetId) => { fetch('/snippets?' + new URLSearchParams({ snippetId }), { - method: 'DELETE', + method: 'DELETE' }) .then((response) => { if (response.ok) { @@ -52,7 +52,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { return { log: `SnippetDisiplay.deleteSnippet: Error: ${err}`, status: err.status, - message: 'There was an error deleting snippet.', + message: 'There was an error deleting snippet.' }; }); }; @@ -61,7 +61,7 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { fetch(`/snippets?${new URLSearchParams({ snippetId })}`, { method: 'PUT', headers: { 'Content-type': 'application/json' }, - body: JSON.stringify(currentDisplay), + body: JSON.stringify(currentDisplay) }) .then((response) => { //Are we using this response anywhere? IF not, delete this. @@ -76,63 +76,69 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { return { log: `SnippetDisplay.editSnippet: Error: ${err}`, status: err.status, - message: 'There was an error editing code snippet.', + message: 'There was an error editing code snippet.' }; }); }; const displayContent = (
-
+
-
- Title: +
+ Title: { if (editButtonState) { setCurrentDisplay({ ...currentDisplay, - title: e.target.value, + title: e.target.value }); } - }}> + }} + >
-
- Language: +
+ Language: { if (editButtonState) { setCurrentDisplay({ ...currentDisplay, - language: e.target.value, + language: e.target.value }); } - }}> + }} + >
-
- Comments: +
+ Comments: { if (editButtonState) { setCurrentDisplay({ ...currentDisplay, - comments: e.target.value, + comments: e.target.value }); } - }}> + }} + >
{ if (editButtonState) { setCurrentDisplay({ ...currentDisplay, tags: e }); @@ -145,15 +151,17 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => {
{\n console.log(\'Hello World!)\n}'} onChange={(e) => { setCurrentDisplay({ ...currentDisplay, storedCode: e }); - }}> + }} + >
@@ -206,6 +217,6 @@ const SnippetDisplay = ({ selectedSnippet, getSnippet }) => { SnippetDisplay.propTypes = { selectedSnippet: PropTypes.object, - getSnippet: PropTypes.func, + getSnippet: PropTypes.func }; export default SnippetDisplay; diff --git a/client/src/containers/Sidebar/Sidebar.jsx b/client/src/containers/Sidebar/Sidebar.jsx index 979cab1..97f8046 100644 --- a/client/src/containers/Sidebar/Sidebar.jsx +++ b/client/src/containers/Sidebar/Sidebar.jsx @@ -24,6 +24,7 @@ const Sidebar = ({ handleLogin }) => { //Tags and selected tags const [userTags, setUserTags] = useState([]); const [selectedTags, setSelectedTags] = useState([]); + const [filteredSnippets, setFilteredSnippets] = useState([]); const [openModal, setOpenModal] = useState(false); const [collapse, setCollapse] = useState(false); @@ -33,6 +34,10 @@ const Sidebar = ({ handleLogin }) => { useEffect(() => { getUserData(); }, []); + + useEffect(() => { + filterSnippetsByTags(); + }, [snippets, selectedTags]); //Get all snippets stored under user's account const getUserData = () => { @@ -50,17 +55,6 @@ const Sidebar = ({ handleLogin }) => { ); }; - // // renderTags function - // const renderTabs = () => { - // const tabs = []; - - // for (let i = 0; i < snippets.length; i++) { - // tabs.push(); - // } - - // return tabs; - // }; - // 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); @@ -82,12 +76,22 @@ const Sidebar = ({ handleLogin }) => { }; const toggleDisplayType = (event) => { - console.log(event.target.value); setDisplayType(event.target.value); }; + const filterSnippetsByTags = () => { + const snippetSubset = snippets.filter((sn) => { + for (let i = 0; i < [...sn.tags, sn.lanuage].length; i++) { + if (selectedTags.includes([...sn.tags, sn.lanuage][i])) return true; + } + return false; + }); + + setFilteredSnippets(snippetSubset); + }; + const snippetsDisplay = ( - + {/* Animation while app is fetching data from DB */}
{loading && ( @@ -100,6 +104,7 @@ const Sidebar = ({ handleLogin }) => {
)} @@ -108,9 +113,9 @@ const Sidebar = ({ handleLogin }) => { ); const tagsDisplay = ( - + {/* Animation while app is fetching data from DB */} -
+
{loading && (
{ >
)} - +
+
+ +
+
+
+ +
+
); diff --git a/client/src/containers/Sidebar/Sidebar.module.scss b/client/src/containers/Sidebar/Sidebar.module.scss index d0c1f22..555bb9d 100644 --- a/client/src/containers/Sidebar/Sidebar.module.scss +++ b/client/src/containers/Sidebar/Sidebar.module.scss @@ -9,6 +9,19 @@ // border-color: black; // } +.tagsSnippetsDisplayHolder { + display: flex; + flex-direction: column; + overflow: hidden; + max-height: 75vh; +} + +.tagsSnippetsDisplayBox { + padding: 8px 16px; + overflow-y: auto; + max-height: 50%; +} + .displayTypeSelector { display: flex; justify-content: space-around; @@ -34,9 +47,14 @@ border: none !important; } +.cardBodyContent { + //height: min-content; + overflow: hidden; +} .sidebar { width: 300px; - height: inherit; + //height: inherit; + //max-height: 75vh; position: absolute; left: -250px; top: 0; @@ -69,6 +87,8 @@ .cardBody { padding: 8px 16px; + overflow-y: auto; + max-height: 75vh; } } diff --git a/client/src/scss/_global.scss b/client/src/scss/_global.scss index da7d9dc..67d33e7 100644 --- a/client/src/scss/_global.scss +++ b/client/src/scss/_global.scss @@ -1,3 +1,18 @@ +*::-webkit-scrollbar { + color: #232024; +} +*::-webkit-scrollbar-track { + background: transparentize(#232024, 1); +} + +*::-webkit-scrollbar-corner { + background: transparentize(#232024, 1); +} + +*::-webkit-scrollbar-thumb { + background: whitesmoke; +} + body { background: url(https://wallpaperaccess.com/full/266479.png) no-repeat center center fixed;