From 95f108c2f723022629c7697ee7abe3e900a01df5 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 29 Oct 2024 10:46:14 +0100 Subject: [PATCH] fix more lint errors --- src/Components/Map/Layer.tsx | 2 +- .../Map/Subcomponents/Controls/SearchControl.tsx | 4 ++-- .../ItemPopupComponents/HeaderView.tsx | 2 +- .../ItemPopupComponents/PopupButton.tsx | 2 +- src/Components/Map/Subcomponents/ItemViewPopup.tsx | 4 ++-- src/Components/Map/Tags.tsx | 8 ++++---- src/Components/Map/UtopiaMapInner.tsx | 2 +- src/Components/Map/hooks/useFilter.tsx | 12 ++++++------ src/Components/Map/hooks/useSelectPosition.tsx | 2 +- .../Profile/Subcomponents/ContactInfo.tsx | 2 +- src/Components/Profile/Templates/OnepagerView.tsx | 4 ++-- src/Components/Profile/Templates/TabsForm.tsx | 6 +++--- src/Components/Profile/Templates/TabsView.tsx | 6 +++--- src/Components/Profile/itemFunctions.ts | 14 +++++++------- src/Components/Templates/AttestationForm.tsx | 4 ++-- src/Components/Templates/ItemCard.tsx | 2 +- src/Components/Templates/MoonCalendar.tsx | 2 +- src/Utils/GetValue.ts | 4 ++-- src/Utils/Moon.ts | 2 +- src/Utils/RandomColor.ts | 12 ++++++------ src/Utils/TimeAgo.ts | 2 +- 21 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index f6b2d52d..e5f9f99b 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -94,7 +94,7 @@ export const Layer = ({ popupopen: (e) => { const item = Object.entries(leafletRefs).find(r => r[1].popup == e.popup)?.[1].item; if (item?.layer?.name == name && window.location.pathname.split("/")[1] != item.id) { - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); if (!location.pathname.includes("/item/")) { window.history.pushState({}, "", `/${item.id}` + `${params.toString() !== "" ? `?${params}` : ""}`) } diff --git a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx index 24a99f6b..8362de66 100644 --- a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx +++ b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx @@ -86,8 +86,8 @@ export const SearchControl = () => { const location = useLocation(); useEffect(() => { - let params = new URLSearchParams(location.search); - let embedded = params.get("embedded"); + const params = new URLSearchParams(location.search); + const embedded = params.get("embedded"); embedded != "true" && setEmbedded(false) }, [location]); diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx index 141151e4..48ede4ce 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx @@ -41,7 +41,7 @@ export function HeaderView({ item, api, editCallback, deleteCallback, setPositio const [address, setAdress] = React.useState(""); - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); const openDeleteModal = async (event: React.MouseEvent) => { diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx index 1c558c16..b01fa608 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx @@ -6,7 +6,7 @@ import { useGetItemTags } from '../../hooks/useTags'; export const PopupButton = ({url, parameterField, text, colorField, item} : {url: string, parameterField?: string, text: string, colorField?: string, item? : Item}) => { - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); const getItemTags = useGetItemTags(); diff --git a/src/Components/Map/Subcomponents/ItemViewPopup.tsx b/src/Components/Map/Subcomponents/ItemViewPopup.tsx index 9331c50e..37b4a073 100644 --- a/src/Components/Map/Subcomponents/ItemViewPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemViewPopup.tsx @@ -31,7 +31,7 @@ export const ItemViewPopup = React.forwardRef((props: ItemViewPopupProps, ref: a const setSelectPosition = useSetSelectPosition(); - const [infoExpanded, setInfoExpanded] = useState(false); + const [infoExpanded, setInfoExpanded] = useState(false); const handleEdit = (event: React.MouseEvent) => { event.stopPropagation(); @@ -57,7 +57,7 @@ export const ItemViewPopup = React.forwardRef((props: ItemViewPopupProps, ref: a } setLoading(false); map.closePopup(); - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); window.history.pushState({}, "", "/" + `${params ? `?${params}` : ""}`); navigate("/"); } diff --git a/src/Components/Map/Tags.tsx b/src/Components/Map/Tags.tsx index b1552f46..b6858a29 100644 --- a/src/Components/Map/Tags.tsx +++ b/src/Components/Map/Tags.tsx @@ -23,10 +23,10 @@ const filterTags = useFilterTags() useEffect(() => { - let params = new URLSearchParams(location.search); - let urlTags = params.get("tags") - let decodedTags = urlTags ? decodeURIComponent(urlTags) : ""; - let decodedTagsArray = decodedTags.split(";"); + const params = new URLSearchParams(location.search); + const urlTags = params.get("tags") + const decodedTags = urlTags ? decodeURIComponent(urlTags) : ""; + const decodedTagsArray = decodedTags.split(";"); if(decodedTagsArray?.some(ut => !filterTags.find(ft => ut.toLocaleLowerCase() === ft.name.toLocaleLowerCase()))||filterTags?.some(ft => !decodedTagsArray?.find(ut => ut.toLocaleLowerCase() === ft.name.toLocaleLowerCase()))) {resetFilterTags() decodedTagsArray?.map(urlTag => { diff --git a/src/Components/Map/UtopiaMapInner.tsx b/src/Components/Map/UtopiaMapInner.tsx index eb40f0c4..d3ef148b 100644 --- a/src/Components/Map/UtopiaMapInner.tsx +++ b/src/Components/Map/UtopiaMapInner.tsx @@ -81,7 +81,7 @@ export function UtopiaMapInner({ } const resetMetaTags = () => { - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); if (!window.location.pathname.includes("/item/")) { window.history.pushState({}, "", `/` + `${params.toString() !== "" ? `?${params}` : ""}`); } diff --git a/src/Components/Map/hooks/useFilter.tsx b/src/Components/Map/hooks/useFilter.tsx index f70349ab..a4d3e5d0 100644 --- a/src/Components/Map/hooks/useFilter.tsx +++ b/src/Components/Map/hooks/useFilter.tsx @@ -128,9 +128,9 @@ function useFilterManager(initialTags: Tag[]): { const [searchPhrase, searchPhraseSet] = React.useState(""); const addFilterTag = useCallback((tag: Tag) => { - let params = new URLSearchParams(location.search); - let urlTags = params.get("tags") - let decodedTags = urlTags ? decodeURIComponent(urlTags) : ""; + const params = new URLSearchParams(location.search); + const urlTags = params.get("tags") + const decodedTags = urlTags ? decodeURIComponent(urlTags) : ""; if(!decodedTags?.includes(tag.name)) params.set("tags", `${urlTags ? urlTags : ""}${urlTags? ';' : ''}${tag.name}`) @@ -149,10 +149,10 @@ function useFilterManager(initialTags: Tag[]): { const removeFilterTag = useCallback((name: string) => { - let params = new URLSearchParams(window.location.search); - let urlTags = params.get("tags"); + const params = new URLSearchParams(window.location.search); + const urlTags = params.get("tags"); let newUrlTags = ""; - let tags = urlTags?.split(";"); + const tags = urlTags?.split(";"); if(tags?.length==0 && urlTags?.length && urlTags?.length > 0) tags[0]=urlTags; tags?.map(urlTag => { if(!(urlTag.toLocaleLowerCase() === name.toLocaleLowerCase())) diff --git a/src/Components/Map/hooks/useSelectPosition.tsx b/src/Components/Map/hooks/useSelectPosition.tsx index 5fb60b0d..62bab475 100644 --- a/src/Components/Map/hooks/useSelectPosition.tsx +++ b/src/Components/Map/hooks/useSelectPosition.tsx @@ -97,7 +97,7 @@ function useSelectPositionManager(): { const linkItem = async (id: string) => { if (markerClicked) { - let new_relations = markerClicked.relations || []; + const new_relations = markerClicked.relations || []; if (!new_relations.some(r => r.related_items_id == id)) { new_relations?.push({ items_id: markerClicked.id, related_items_id: id }) diff --git a/src/Components/Profile/Subcomponents/ContactInfo.tsx b/src/Components/Profile/Subcomponents/ContactInfo.tsx index 0ba74f1c..abbb8d2f 100644 --- a/src/Components/Profile/Subcomponents/ContactInfo.tsx +++ b/src/Components/Profile/Subcomponents/ContactInfo.tsx @@ -60,7 +60,7 @@ const ContactInfo = ({ email, telephone, name, avatar, link }: { email: string, export default ContactInfo; const ConditionalLink = ({ url, children }) => { - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); if (url) { return ( diff --git a/src/Components/Profile/Templates/OnepagerView.tsx b/src/Components/Profile/Templates/OnepagerView.tsx index 4b30a217..bef519da 100644 --- a/src/Components/Profile/Templates/OnepagerView.tsx +++ b/src/Components/Profile/Templates/OnepagerView.tsx @@ -22,8 +22,8 @@ export const OnepagerView = ({item, userType}:{item: Item, userType: string}) => 'liebevoll.jetzt': 'liebevoll.jetzt', }; -let groupType = item.group_type ? item.group_type : 'default'; -let groupTypeText = typeMapping[groupType]; +const groupType = item.group_type ? item.group_type : 'default'; +const groupTypeText = typeMapping[groupType]; return (
diff --git a/src/Components/Profile/Templates/TabsForm.tsx b/src/Components/Profile/Templates/TabsForm.tsx index 9380faf6..f471a903 100644 --- a/src/Components/Profile/Templates/TabsForm.tsx +++ b/src/Components/Profile/Templates/TabsForm.tsx @@ -16,7 +16,7 @@ export const TabsForm = ({ item, state, setState, updatePermission, linkItem, un const updateActiveTab = useCallback((id: number) => { setActiveTab(id); - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); params.set("tab", `${id}`); const newUrl = location.pathname + "?" + params.toString(); @@ -25,8 +25,8 @@ export const TabsForm = ({ item, state, setState, updatePermission, linkItem, un }, [location.pathname]); useEffect(() => { - let params = new URLSearchParams(location.search); - let urlTab = params.get("tab"); + const params = new URLSearchParams(location.search); + const urlTab = params.get("tab"); setActiveTab(urlTab ? Number(urlTab) : 1); }, [location.search]); diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx index f2188c56..1df88be1 100644 --- a/src/Components/Profile/Templates/TabsView.tsx +++ b/src/Components/Profile/Templates/TabsView.tsx @@ -38,7 +38,7 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation const updateActiveTab = useCallback((id: number) => { setActiveTab(id); - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); params.set("tab", `${id}`); const newUrl = location.pathname + "?" + params.toString(); window.history.pushState({}, '', newUrl); @@ -47,8 +47,8 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation useEffect(() => { - let params = new URLSearchParams(location.search); - let urlTab = params.get("tab"); + const params = new URLSearchParams(location.search); + const urlTab = params.get("tab"); setActiveTab(urlTab ? Number(urlTab) : 1); }, [location.search]); diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index 7f170916..64029093 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -42,7 +42,7 @@ export const submitNewItem = async (evt: any, type: string, item, user, setLoadi } export const linkItem = async (id: string, item, updateItem) => { - let new_relations = item.relations || []; + const new_relations = item.relations || []; new_relations?.push({ items_id: item.id, related_items_id: id }) const updatedItem = { id: item.id, relations: new_relations } @@ -60,7 +60,7 @@ export const linkItem = async (id: string, item, updateItem) => { } export const unlinkItem = async (id: string, item, updateItem) => { - let new_relations = item.relations?.filter(r => r.related_items_id !== id) + const new_relations = item.relations?.filter(r => r.related_items_id !== id) const updatedItem = { id: item.id, relations: new_relations } @@ -94,7 +94,7 @@ export const handleDelete = async (event: React.MouseEvent, item, s } setLoading(false); map.closePopup(); - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); window.history.pushState({}, "", "/" + `${params ? `?${params}` : ""}`); navigate("/"); } @@ -103,7 +103,7 @@ export const handleDelete = async (event: React.MouseEvent, item, s export const onUpdateItem = async (state, item, tags, addTag, setLoading, navigate, updateItem, addItem, user, params) => { let changedItem = {} as Item; - let offer_updates: Array = []; + const offer_updates: Array = []; //check for new offers await state.offers?.map(o => { const existingOffer = item?.offers?.find(t => t.tags_id === o.id) @@ -112,7 +112,7 @@ export const onUpdateItem = async (state, item, tags, addTag, setLoading, naviga !existingOffer && offer_updates.push({ items_id: item?.id, tags_id: o.id }) }); - let needs_updates: Array = []; + const needs_updates: Array = []; await state.needs?.map(n => { const existingNeed = item?.needs?.find(t => t.tags_id === n.id) @@ -142,8 +142,8 @@ export const onUpdateItem = async (state, item, tags, addTag, setLoading, naviga ...state.needs.length > 0 && { needs: needs_updates } }; - let offers_state: Array = []; - let needs_state: Array = []; + const offers_state: Array = []; + const needs_state: Array = []; state.offers.map(o => { offers_state.push({ items_id: item?.id, tags_id: o.id }) diff --git a/src/Components/Templates/AttestationForm.tsx b/src/Components/Templates/AttestationForm.tsx index 399eb9fc..fcf5fdd6 100644 --- a/src/Components/Templates/AttestationForm.tsx +++ b/src/Components/Templates/AttestationForm.tsx @@ -17,8 +17,8 @@ export const AttestationForm = ({api}:{api?:ItemsApi}) => { const navigate = useNavigate(); useEffect(() => { - let params = new URLSearchParams(location.search); - let to_user_ids = params.get("to"); + const params = new URLSearchParams(location.search); + const to_user_ids = params.get("to"); setUsers(items.filter(i => to_user_ids?.includes(i.id))) }, [items, location]) diff --git a/src/Components/Templates/ItemCard.tsx b/src/Components/Templates/ItemCard.tsx index 97041936..7d14c8cd 100644 --- a/src/Components/Templates/ItemCard.tsx +++ b/src/Components/Templates/ItemCard.tsx @@ -12,7 +12,7 @@ export const ItemCard = ({ i, loading, url, parameterField, deleteCallback }: { return (
{ - let params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search); if (windowDimensions.width < 786 && i.position) navigate("/" + getValue(i, parameterField) + `${params ? `?${params}` : ""}`) else navigate(url + getValue(i, parameterField) + `${params ? `?${params}` : ""}`) }}> diff --git a/src/Components/Templates/MoonCalendar.tsx b/src/Components/Templates/MoonCalendar.tsx index fda1b39d..743d6dc3 100644 --- a/src/Components/Templates/MoonCalendar.tsx +++ b/src/Components/Templates/MoonCalendar.tsx @@ -18,7 +18,7 @@ export const MoonCalendar = () => { const [currMonth, setCurrMonth] = useState(() => format(today, "MMM-yyyy")); - let firstDayOfMonth = parse(currMonth, "MMM-yyyy", new Date()); + const firstDayOfMonth = parse(currMonth, "MMM-yyyy", new Date()); const getPrevMonth = (event: React.MouseEvent) => { diff --git a/src/Utils/GetValue.ts b/src/Utils/GetValue.ts index 960d7b30..2ac7b24a 100644 --- a/src/Utils/GetValue.ts +++ b/src/Utils/GetValue.ts @@ -1,8 +1,8 @@ export function getValue(obj, path) { if (!obj || typeof path !== 'string') return undefined; - var pathArray = path.split('.'); // Use a different variable for the split path - for (var i = 0, len = pathArray.length; i < len; i++) { + const pathArray = path.split('.'); // Use a different variable for the split path + for (let i = 0, len = pathArray.length; i < len; i++) { if (!obj) return undefined; // Check if obj is falsy at each step obj = obj[pathArray[i]]; // Dive one level deeper } diff --git a/src/Utils/Moon.ts b/src/Utils/Moon.ts index 814539ed..ea4f9c1b 100644 --- a/src/Utils/Moon.ts +++ b/src/Utils/Moon.ts @@ -1,4 +1,4 @@ -export const LUNAR_MONTH: number = 29.530588853; +export const LUNAR_MONTH = 29.530588853; export const getJulianDate = (date: Date = new Date()): number => { const time: number = date.getTime(); diff --git a/src/Utils/RandomColor.ts b/src/Utils/RandomColor.ts index 95004e8d..b1b7e6ae 100644 --- a/src/Utils/RandomColor.ts +++ b/src/Utils/RandomColor.ts @@ -5,12 +5,12 @@ export const randomColor = () => { const golden_ratio_conjugate = 0.618033988749895; function hsvToHex(h, s, v) { - var r, g, b; - var i = (Math.floor(h * 6)); - var f = h * 6 - i; - var p = v * (1 - s); - var q = v * (1 - f * s); - var t = v * (1 - (1 - f) * s); + let r, g, b; + const i = (Math.floor(h * 6)); + const f = h * 6 - i; + const p = v * (1 - s); + const q = v * (1 - f * s); + const t = v * (1 - (1 - f) * s); switch (i % 6) { case 0: r = v, g = t, b = p; break; diff --git a/src/Utils/TimeAgo.ts b/src/Utils/TimeAgo.ts index 6b3325ec..bbbe667d 100644 --- a/src/Utils/TimeAgo.ts +++ b/src/Utils/TimeAgo.ts @@ -20,7 +20,7 @@ export const timeAgo = (date: string | number | Date) => { }; const calculateTimeDifference = (time: number) => { - for (let { label, seconds } of units) { + for (const { label, seconds } of units) { const interval = Math.floor(time / seconds); if (interval >= 1) { return {