From 1fbd4ed3b34eb5a0c1899e6886fbadbb1b895b33 Mon Sep 17 00:00:00 2001 From: tsun900 Date: Thu, 17 Oct 2024 16:03:33 -0400 Subject: [PATCH 01/11] mutiselect fix --- src/components/dashboard/AddProvider.tsx | 16 ++++++------ src/components/template/index.tsx | 31 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/components/dashboard/AddProvider.tsx b/src/components/dashboard/AddProvider.tsx index 46183d3..605b92d 100644 --- a/src/components/dashboard/AddProvider.tsx +++ b/src/components/dashboard/AddProvider.tsx @@ -31,7 +31,7 @@ let steps = [ "Hours", "Tag", "Text", - // 'Toggle', disabled due to lack of use + // 'Toggle', disabled due to lack of use, this is designed for singleselect filters, feature however, is not implemented // 'Actions' "Content", ]; @@ -45,7 +45,7 @@ function AddProvider(props) { const [isLoading, setIsLoading] = useState(true); const [filters, setFilters] = useState(null); const [descriptions, setDescriptions] = useState(null); - const [categories, setCategories] = useState(null); + const [single, setSingle] = useState(null); const [error, setError] = useState(""); // async function fetchData() { @@ -109,7 +109,7 @@ function AddProvider(props) { const f = await collections .where("team", "==", props.team.name) .where("active", "==", true) - .where("select_type", "==", 2) + .where("select_type", "==", 1) .get() .then((querySnapshot) => { const idToData = {}; @@ -141,7 +141,7 @@ function AddProvider(props) { const c = await collections .where("team", "==", props.team.name) .where("active", "==", true) - .where("select_type", "==", 1) + .where("select_type", "==", 2) .get() .then((querySnapshot) => { const idToData = {}; @@ -156,7 +156,7 @@ function AddProvider(props) { }); setFilters(f); setDescriptions(d); - setCategories(c); + setSingle(c); } fetchData().then(() => setIsLoading(false)); }, []); @@ -173,14 +173,14 @@ function AddProvider(props) { delIndex !== -1 && steps.splice(delIndex, 1); } - if (categories && !Object.keys(categories).length) { + if (single && !Object.keys(single).length) { const delIndex = steps.indexOf("Toggle"); delIndex !== -1 && steps.splice(delIndex, 1); } } updateSteps(); - }, [filters, descriptions, categories]); + }, [filters, descriptions, single]); // function updateSteps() { // if (filters && !Object.keys(filters).length) { @@ -476,7 +476,7 @@ function AddProvider(props) { }} filters={filters} descriptions={descriptions} - categories={categories} + single={single} /> diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 04c4189..70a6e66 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -73,7 +73,9 @@ export default compose( async function fetchData() { const saved = localStorage.getItem("saved"); const arr = []; + const arr2 = []; const collections = firestore.collection("categories"); + const collections2 = firestore.collection("providers"); // Note: this is a temperary workaround so the page does appears fine, however, further fix is neccessary to actually resolve the issue if (team.name === "") { await collections @@ -106,6 +108,35 @@ export default compose( arr.sort((a, b) => a.priority - b.priority); setCategories(arr); setDefaultCategories(arr); + if (team.name === "") { + await collections2 + .where("team", "==", saved) + .get() + .then((querySnapshot) => { + querySnapshot.forEach((doc) => { + const data = doc.data(); + if (!data.id) { + data.id = doc.id; + } + arr2.push(data); + }); + }); + } else { + localStorage.setItem("saved", team.name); + await collections2 + .where("team", "==", team.name) + .get() + .then((querySnapshot) => { + querySnapshot.forEach((doc) => { + const data = doc.data(); + if (!data.id) { + data.id = doc.id; + } + arr2.push(data); + }); + }); + } + console.log(arr2) setIsLoading(false); } fetchData(); From 7604ca9f8754684a500b08f60e7242d96eba8d8f Mon Sep 17 00:00:00 2001 From: tsun900 Date: Thu, 17 Oct 2024 16:09:44 -0400 Subject: [PATCH 02/11] delete provider bug --- src/components/dashboard/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/dashboard/index.tsx b/src/components/dashboard/index.tsx index b0f0026..942fe5a 100644 --- a/src/components/dashboard/index.tsx +++ b/src/components/dashboard/index.tsx @@ -60,8 +60,9 @@ function Dashboard({ firestore, team, selectItem }) { setCategories(c); } } - fetchData().then(() => setIsLoading(false)); - }, [team]); + fetchData() + setIsLoading(false); + }, [team, isLoading]); if (isLoading) { return ( From 8db52a9fb27a2335154697ab9a233f82279eced9 Mon Sep 17 00:00:00 2001 From: tsun900 Date: Thu, 17 Oct 2024 16:43:45 -0400 Subject: [PATCH 03/11] working on provider cat --- src/components/template/index.tsx | 58 +++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 70a6e66..8032d73 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -35,11 +35,11 @@ export default compose( connect(mapStateToProps, {}), )(({ team, firestore }) => { const [categories, setCategories] = useState([]); + const [providers, setProviders] = useState([]); const [message, setMessage] = useState(null); const [newCatName, setNewCatName] = useState("Please edit name of new category"); const [isLoading, setIsLoading] = useState(true); const [showModal, setShowModal] = useState(false); - const [, setDefaultCategories] = useState([]); const [usePrimary, setUsePrimary] = useState(false); const staticData = { id: "Preview", @@ -107,7 +107,6 @@ export default compose( } arr.sort((a, b) => a.priority - b.priority); setCategories(arr); - setDefaultCategories(arr); if (team.name === "") { await collections2 .where("team", "==", saved) @@ -136,7 +135,7 @@ export default compose( }); }); } - console.log(arr2) + setProviders(arr2) setIsLoading(false); } fetchData(); @@ -242,7 +241,6 @@ export default compose( const point = categories[index]; index = 0 for (let i of point.options) { - console.log(i) if(i.value === name) { break; } @@ -295,7 +293,6 @@ export default compose( (x) => x.value.toLowerCase() === name.toLowerCase(), ) === -1 ) { - console.log(item) await point.options.push({ color: colors, value: name, @@ -401,7 +398,6 @@ export default compose( id: newCatName, isPrimary: usePrimary, }); - console.log(categories) setNewCatName("Please edit name of new category"); setIsLoading(false); @@ -466,6 +462,56 @@ export default compose( } catch { alert("Unable to load categories"); } + + try { + const collections = firestore.collection("providers"); + await collections + .where("team", "==", team.name) + .get() + .then(async (querySnapshot) => { + promiseWithTimeout( + 10000, + providers.forEach((cat) => { + firestore.set( + { collection: "providers", doc: cat.id }, + cat, + ); + }), + ).then( + (complete) => { + // code that executes after the timeout has completed. + promiseWithTimeout( + 10000, + querySnapshot.forEach((doc) => { + if ( + providers.findIndex( + (x) => x.id === doc.id, + ) === -1 + ) + doc.ref.delete(); + }), + ).then( + (complete) => { + setShowModal(false); + setIsLoading(false); + }, + () => { + alert( + "Unable to delete removed categories in Providers", + ); + }, + ); + }, + () => { + // code that takes care of the canceled promise. + // Note that .then rather than .done should be used in this case. + alert("Unable to save Providers"); + }, + ); + }); + } catch { + alert("Unable to load Providers"); + } } if (isLoading) { From 514352b2e96bc890c0feb713cf92b8a08ab26950 Mon Sep 17 00:00:00 2001 From: tsun90 <52758623+tsun900@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:40:03 -0400 Subject: [PATCH 04/11] name error fixed --- src/components/map/index.tsx | 2 +- src/components/template/index.tsx | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/map/index.tsx b/src/components/map/index.tsx index 363de0b..e9456d8 100644 --- a/src/components/map/index.tsx +++ b/src/components/map/index.tsx @@ -740,7 +740,7 @@ const Map = (props) => { ( [aKey, aValue]: any[], [bKey, bValue]: any[] - ) => aValue.name.localeCompare(bValue.name) + ) => aValue.priority - bValue.priority ) .map(([key, value]: any[]) => renderMoreDropdown(value.name, key) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 8032d73..04c6b65 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -18,6 +18,8 @@ import { TempTutorialTwo } from "./TempTutorialTwo"; import { ToggleSlider } from "react-toggle-slider"; import { BsPlus } from "react-icons/bs"; import { Card } from "react-bootstrap"; +import { uuid } from "uuidv4"; +const { v4: uuidv4 } = require("uuid"); function reorder(list: T[], startIndex: number, endIndex: number) { const result = Array.from(list); @@ -223,7 +225,6 @@ export default compose( const items = categories; const point = items[index]; point.name = e.target.value; - point.id = e.target.value; setCategories(items); saveChanges(); @@ -363,6 +364,10 @@ export default compose( index++; } await categories.splice(index, 1); + + categories.forEach((item: any, index) => { + item.priority = index; + }); setIsLoading(false); saveChanges(); @@ -378,6 +383,9 @@ export default compose( index++; } await categories.splice(index, 1); + categories.forEach((item: any, index) => { + item.priority = index; + }); setIsLoading(false); saveChanges(); @@ -395,11 +403,12 @@ export default compose( options: [], active: true, team: team.name, - id: newCatName, + id: uuidv4(), isPrimary: usePrimary, + priority: categories.length }); - setNewCatName("Please edit name of new category"); + console.log(categories) setIsLoading(false); saveChanges(); @@ -579,6 +588,10 @@ export default compose( {categories .filter( (item, value) => item.isPrimary) + .sort( + ([aKey, aValue]: any[], [bKey, bValue]: any[]) => + aValue.priority - bValue.priority + ) .map((item, index) => (

( {categories .filter( (item, value) => !item.isPrimary) + // .sort( + // ([aKey, aValue]: any[], [bKey, bValue]: any[]) => + // aValue.priority - bValue.priority + // ) .map((item, index) => ( Date: Sun, 20 Oct 2024 21:22:29 -0400 Subject: [PATCH 05/11] remove filter in provider --- src/components/template/index.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 04c6b65..91c37a3 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -307,6 +307,7 @@ export default compose( async function removeOption(i, item) { setIsLoading(true); let index = 0; + let index2 = 0; for (let i of categories) { if(i.name === item.name) { break; @@ -314,6 +315,17 @@ export default compose( index++; } const point = categories[index]; + providers.forEach((val) => { + if (item.id in val) { + for (let curr of val[item.id as keyof typeof val]) { + if (point.options[i].value == curr) { + break; + } + index2++; + }; + val[item.id as keyof typeof val].splice(index2, 1); + } + }); await point.options.splice(i, 1); setIsLoading(false); @@ -363,6 +375,11 @@ export default compose( } index++; } + providers.forEach((val) => { + if (item.id in val) { + delete val[item.id as keyof typeof val]; + } + }); await categories.splice(index, 1); categories.forEach((item: any, index) => { From 8f6efa08f65855145d2a36942b97d64bd710e871 Mon Sep 17 00:00:00 2001 From: tsun90 <52758623+tsun900@users.noreply.github.com> Date: Sun, 20 Oct 2024 22:05:56 -0400 Subject: [PATCH 06/11] timer before update the name --- src/components/template/index.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 91c37a3..80a2f7c 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useRef } from "react"; import InputGroup from "react-bootstrap/InputGroup"; import FormControl from "react-bootstrap/FormControl"; import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"; @@ -36,6 +36,7 @@ export default compose( withFirestore, connect(mapStateToProps, {}), )(({ team, firestore }) => { + let timerInterval: NodeJS.Timeout | null = null; const [categories, setCategories] = useState([]); const [providers, setProviders] = useState([]); const [message, setMessage] = useState(null); @@ -68,6 +69,7 @@ export default compose( team: team.name, website: ["https://www.mapscout.io"], }; + const inputRef = useRef(null); const [dummy, setDummy] = useState(staticData); @@ -214,6 +216,25 @@ export default compose( saveChanges(); } + function countdownTimer(seconds: number): void { + let remainingTime = seconds; + + if (timerInterval) { + clearInterval(timerInterval); + } + + timerInterval = setInterval(() => { + if (remainingTime > 0) { + console.log(`Time left: ${remainingTime} seconds`); + remainingTime--; + } else { + console.log("Time's up!"); + clearInterval(timerInterval!); + saveChanges(); + } + }, 1000); + } + async function rename(e, item) { let index = 0; for (let i of categories) { @@ -226,8 +247,7 @@ export default compose( const point = items[index]; point.name = e.target.value; setCategories(items); - - saveChanges(); + countdownTimer(3); } async function changeColor(color, name, item) { From a063dc8b9622d4429afe2ebf0f1b2e0d541527b1 Mon Sep 17 00:00:00 2001 From: tsun90 <52758623+tsun900@users.noreply.github.com> Date: Tue, 22 Oct 2024 19:11:11 -0400 Subject: [PATCH 07/11] Remove redundant --- src/components/template/index.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 80a2f7c..4a9cba0 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -102,9 +102,6 @@ export default compose( .then((querySnapshot) => { querySnapshot.forEach((doc) => { const data = doc.data(); - if (!data.id) { - data.id = doc.id; - } arr.push(data); }); }); @@ -118,9 +115,6 @@ export default compose( .then((querySnapshot) => { querySnapshot.forEach((doc) => { const data = doc.data(); - if (!data.id) { - data.id = doc.id; - } arr2.push(data); }); }); @@ -519,7 +513,7 @@ export default compose( 10000, providers.forEach((cat) => { firestore.set( - { collection: "providers", doc: cat.id }, + { collection: "providers", doc: cat.facilityName }, cat, ); }), @@ -531,7 +525,7 @@ export default compose( querySnapshot.forEach((doc) => { if ( providers.findIndex( - (x) => x.id === doc.id, + (x) => x.facilityName === doc.facilityName, ) === -1 ) doc.ref.delete(); From cb214ec0fe067d223d4f18cc63b83aaeb58917fc Mon Sep 17 00:00:00 2001 From: tsun90 <52758623+tsun900@users.noreply.github.com> Date: Tue, 22 Oct 2024 19:32:22 -0400 Subject: [PATCH 08/11] remove redundant code that may cause error --- src/components/template/index.tsx | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 4a9cba0..f8c88c3 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -519,28 +519,8 @@ export default compose( }), ).then( (complete) => { - // code that executes after the timeout has completed. - promiseWithTimeout( - 10000, - querySnapshot.forEach((doc) => { - if ( - providers.findIndex( - (x) => x.facilityName === doc.facilityName, - ) === -1 - ) - doc.ref.delete(); - }), - ).then( - (complete) => { - setShowModal(false); - setIsLoading(false); - }, - () => { - alert( - "Unable to delete removed categories in Providers", - ); - }, - ); + setShowModal(false); + setIsLoading(false); }, () => { // code that takes care of the canceled promise. From 2bdfb916c6e6a82fc629f37f93470cf8b799fba0 Mon Sep 17 00:00:00 2001 From: Athanasios Taprantzis Date: Wed, 23 Oct 2024 05:07:47 -0400 Subject: [PATCH 09/11] Fix new category order --- src/components/template/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index f8c88c3..ecc9d6c 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -428,7 +428,7 @@ export default compose( if (usePrimary) { type = 2 } - await categories.unshift({ + await categories.push({ name: newCatName, select_type: type, options: [], From e0fd7b36ec544c9e6a35b9c25e87a2df5b98d915 Mon Sep 17 00:00:00 2001 From: Athanasios Taprantzis Date: Wed, 23 Oct 2024 06:26:02 -0400 Subject: [PATCH 10/11] Fixed filters and updated firebase schema! --- src/components/dashboard/RowForm.tsx | 19 +++++++++++-------- src/components/map/index.tsx | 8 ++++---- src/components/template/index.tsx | 20 ++++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/components/dashboard/RowForm.tsx b/src/components/dashboard/RowForm.tsx index c279b47..49a3116 100644 --- a/src/components/dashboard/RowForm.tsx +++ b/src/components/dashboard/RowForm.tsx @@ -48,6 +48,7 @@ const RowForm = (props) => { image: "modalimage.png", imageURL: null, content: {}, + filters: {}, }; const [item, setItem] = useState( @@ -56,10 +57,6 @@ const RowForm = (props) => { const [showModal, setShowModal] = useState(false); useEffect(() => { - const itemFields = Object.keys(props.filters); - itemFields.forEach((field) => { - defaultItem[field] = []; - }); setItem(props.item.facilityName ? props.item : defaultItem); }, []); @@ -376,11 +373,14 @@ const RowForm = (props) => { {name} { const newItem = { ...item, - [key]: selected, + ['filters']: { + ...item['filters'], + [key]: selected, + } }; setItem(newItem); props.setItem(newItem); @@ -400,11 +400,14 @@ const RowForm = (props) => { {name} { const newItem = { ...item, - [key]: e.target.value, + ['filters']: { + ...item['filters'], + [key]: e.target.value + } }; setItem(newItem); props.setItem(newItem); diff --git a/src/components/map/index.tsx b/src/components/map/index.tsx index e9456d8..5f76c98 100644 --- a/src/components/map/index.tsx +++ b/src/components/map/index.tsx @@ -146,8 +146,8 @@ const Map = (props) => { setTempProviders(temp); Object.keys(filtersState).forEach((filterName) => { temp = temp.filter((provider) => - provider[filterName] - ? provider[filterName].some((r) => + provider['filters'][filterName] + ? provider['filters'][filterName].some((r) => filtersState[filterName].includes(r) ) || filtersState[filterName].length === 0 : true @@ -702,7 +702,7 @@ const Map = (props) => { .filter( ([key, value]: any[]) => Number.isInteger(value.priority) && - value.priority < FILTER_CUTOFF + value.priority <= FILTER_CUTOFF ) .sort( ([aKey, aValue]: any[], [bKey, bValue]: any[]) => @@ -734,7 +734,7 @@ const Map = (props) => { .filter( ([key, value]: any[]) => !Number.isInteger(value.priority) || - value.priority >= FILTER_CUTOFF + value.priority > FILTER_CUTOFF ) .sort( ( diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index ecc9d6c..7408bfa 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -198,7 +198,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -232,7 +232,7 @@ export default compose( async function rename(e, item) { let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -248,7 +248,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -272,7 +272,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -297,7 +297,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -323,7 +323,7 @@ export default compose( let index = 0; let index2 = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -349,7 +349,7 @@ export default compose( function disableCat(item) { let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -368,7 +368,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -384,7 +384,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; @@ -408,7 +408,7 @@ export default compose( setIsLoading(true); let index = 0; for (let i of categories) { - if(i.name === item.name) { + if(i.id === item.id) { break; } index++; From 2afd950aca30c2f27dbfec90d38bd25ee423ba78 Mon Sep 17 00:00:00 2001 From: Athanasios Taprantzis Date: Wed, 23 Oct 2024 06:34:15 -0400 Subject: [PATCH 11/11] Fixed filter deletion from providers --- src/components/template/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/template/index.tsx b/src/components/template/index.tsx index 7408bfa..aa369b4 100644 --- a/src/components/template/index.tsx +++ b/src/components/template/index.tsx @@ -390,8 +390,8 @@ export default compose( index++; } providers.forEach((val) => { - if (item.id in val) { - delete val[item.id as keyof typeof val]; + if (item.id in val['filters']) { + delete val['filters'][item.id]; } }); await categories.splice(index, 1); @@ -610,7 +610,7 @@ export default compose( index={index} disableCat={disableCat} enableCat={enableCat} - deleteCat={deletePrim} + deleteCat={deleteCat} changeType={changeType} rename={rename} addOption={addPrimOption}