From b0059cd5255428ae0b8c999e6d102fed2939d6be Mon Sep 17 00:00:00 2001 From: Kyle Slugg Date: Thu, 18 May 2023 12:19:12 -0400 Subject: [PATCH 1/4] Now with filtering by tags --- client/src/containers/Sidebar/Sidebar.jsx | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/client/src/containers/Sidebar/Sidebar.jsx b/client/src/containers/Sidebar/Sidebar.jsx index 979cab1..0791e64 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,10 +76,20 @@ 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 */} @@ -100,6 +104,7 @@ const Sidebar = ({ handleLogin }) => { )} @@ -125,6 +130,11 @@ const Sidebar = ({ handleLogin }) => { selectedTags={selectedTags} selectDeselectTag={selectDeselectTag} /> + ); From 9dd2d36110239129f5925bd1cf18fe26913dbc6d Mon Sep 17 00:00:00 2001 From: Kyle Slugg Date: Thu, 18 May 2023 15:19:17 -0400 Subject: [PATCH 2/4] Now with filtering by tags and scrolling list displays --- client/src/containers/Sidebar/Sidebar.jsx | 34 ++++++++++++------- .../containers/Sidebar/Sidebar.module.scss | 22 +++++++++++- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/client/src/containers/Sidebar/Sidebar.jsx b/client/src/containers/Sidebar/Sidebar.jsx index 0791e64..97f8046 100644 --- a/client/src/containers/Sidebar/Sidebar.jsx +++ b/client/src/containers/Sidebar/Sidebar.jsx @@ -91,7 +91,7 @@ const Sidebar = ({ handleLogin }) => { }; const snippetsDisplay = ( - + {/* Animation while app is fetching data from DB */}
{loading && ( @@ -113,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 f29bab6..fe7350b 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: -300px; top: 0; @@ -69,6 +87,8 @@ .cardBody { padding: 8px 16px; + overflow-y: auto; + max-height: 75vh; } } From 57366e037efabc6442943af9ae883bdfcafd0070 Mon Sep 17 00:00:00 2001 From: Kyle Slugg Date: Thu, 18 May 2023 15:30:40 -0400 Subject: [PATCH 3/4] Commiting prior to dev merge --- client/src/scss/_global.scss | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/src/scss/_global.scss b/client/src/scss/_global.scss index da7d9dc..2f114d4 100644 --- a/client/src/scss/_global.scss +++ b/client/src/scss/_global.scss @@ -1,3 +1,18 @@ +*::-webkit-scrollbar { + color: #062a56; +} +*::-webkit-scrollbar-track { + background: transparentize($accent-bkg, 1); +} + +*::-webkit-scrollbar-corner { + background: transparentize($accent-bkg, 1); +} + +*::-webkit-scrollbar-thumb { + background: $accent-bkg; +} + body { background: url(https://wallpaperaccess.com/full/266479.png) no-repeat center center fixed; From 68b508eed1ba3785fbdd50167d60978323ed98e9 Mon Sep 17 00:00:00 2001 From: Kyle Slugg Date: Thu, 18 May 2023 15:42:29 -0400 Subject: [PATCH 4/4] Enhanced scrollbar styling, plus edit protection for all fields when editing turned off --- .../SnippetDisplay/SnippetDisplay.jsx | 77 +++++++++++-------- client/src/scss/_global.scss | 8 +- 2 files changed, 48 insertions(+), 37 deletions(-) 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/scss/_global.scss b/client/src/scss/_global.scss index 2f114d4..67d33e7 100644 --- a/client/src/scss/_global.scss +++ b/client/src/scss/_global.scss @@ -1,16 +1,16 @@ *::-webkit-scrollbar { - color: #062a56; + color: #232024; } *::-webkit-scrollbar-track { - background: transparentize($accent-bkg, 1); + background: transparentize(#232024, 1); } *::-webkit-scrollbar-corner { - background: transparentize($accent-bkg, 1); + background: transparentize(#232024, 1); } *::-webkit-scrollbar-thumb { - background: $accent-bkg; + background: whitesmoke; } body {