From 36aeda5919f87200090791c6763229c6aa51ea19 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 29 Oct 2024 18:24:11 +0100 Subject: [PATCH] lint fixes --- src/Components/AppShell/NavBar.tsx | 4 +- src/Components/AppShell/SideBar.tsx | 2 +- src/Components/AppShell/SidebarSubmenu.tsx | 2 +- src/Components/Auth/RequestPasswordPage.tsx | 4 +- src/Components/Auth/useAuth.tsx | 20 ++-- src/Components/Gaming/Quests.tsx | 2 +- src/Components/Input/Autocomplete.tsx | 4 +- src/Components/Input/ComboBoxInput.tsx | 2 +- src/Components/Map/Layer.tsx | 21 ++-- .../Map/Subcomponents/AddButton.tsx | 1 + .../Subcomponents/Controls/SearchControl.tsx | 6 +- .../Map/Subcomponents/ItemFormPopup.tsx | 1 + .../Map/Subcomponents/ItemViewPopup.tsx | 2 +- src/Components/Map/Tags.tsx | 1 + src/Components/Map/hooks/useFilter.tsx | 7 +- src/Components/Map/hooks/useItems.tsx | 2 + src/Components/Map/hooks/usePermissions.tsx | 2 + .../Map/hooks/useSelectPosition.tsx | 10 +- src/Components/Map/hooks/useTags.tsx | 9 +- src/Components/Profile/ProfileForm.tsx | 8 +- src/Components/Profile/ProfileView.tsx | 15 ++- .../Profile/Subcomponents/ActionsButton.tsx | 2 +- .../Subcomponents/ProfileSubHeader.tsx | 2 +- .../Profile/Templates/OnepagerView.tsx | 4 +- src/Components/Profile/Templates/TabsForm.tsx | 6 +- src/Components/Profile/Templates/TabsView.tsx | 10 +- src/Components/Profile/itemFunctions.ts | 48 ++++---- src/Components/Templates/AttestationForm.tsx | 4 +- src/Components/Templates/DateUserInfo.tsx | 2 +- src/Components/Templates/EmojiPicker.tsx | 8 +- src/Components/Templates/MarketView.tsx | 3 + .../Templates/OverlayItemsIndexPage.tsx | 7 +- src/Components/Templates/SelectUser.tsx | 2 +- src/Utils/FormatTags.ts | 4 +- src/Utils/RandomColor.ts | 8 +- src/types.ts | 103 +++++++++--------- 36 files changed, 185 insertions(+), 153 deletions(-) diff --git a/src/Components/AppShell/NavBar.tsx b/src/Components/AppShell/NavBar.tsx index ebde697d..d276e3f6 100644 --- a/src/Components/AppShell/NavBar.tsx +++ b/src/Components/AppShell/NavBar.tsx @@ -34,7 +34,7 @@ export default function NavBar ({ appName, userType }: { appName: string, userTy useEffect(() => { const params = new URLSearchParams(location.search) const embedded = params.get('embedded') - embedded != 'true' && setShowNav(true) + embedded !== 'true' && setShowNav(true) }, [location]) const onLogout = () => { @@ -43,7 +43,7 @@ export default function NavBar ({ appName, userType }: { appName: string, userTy { success: { render () { - return `Bye bye` + return 'Bye bye' }, // other options icon: '👋' diff --git a/src/Components/AppShell/SideBar.tsx b/src/Components/AppShell/SideBar.tsx index 59a9a2d5..3448ad0a 100644 --- a/src/Components/AppShell/SideBar.tsx +++ b/src/Components/AppShell/SideBar.tsx @@ -48,7 +48,7 @@ export function SideBar ({ routes, bottomRoutes }: { routes: route[], bottomRout useEffect(() => { const params = new URLSearchParams(location.search) const embedded = params.get('embedded') - embedded != 'true' && setEmbedded(false) + embedded !== 'true' && setEmbedded(false) }, [location]) const params = new URLSearchParams(window.location.search) diff --git a/src/Components/AppShell/SidebarSubmenu.tsx b/src/Components/AppShell/SidebarSubmenu.tsx index 3dea57ec..c9d88432 100644 --- a/src/Components/AppShell/SidebarSubmenu.tsx +++ b/src/Components/AppShell/SidebarSubmenu.tsx @@ -35,7 +35,7 @@ function SidebarSubmenu ({ submenu, name, icon } : { path: string; {m.icon}{m.name} { - location.pathname == m.path + location.pathname === m.path ? () : null diff --git a/src/Components/Auth/RequestPasswordPage.tsx b/src/Components/Auth/RequestPasswordPage.tsx index c74c75ff..6eaa8288 100644 --- a/src/Components/Auth/RequestPasswordPage.tsx +++ b/src/Components/Auth/RequestPasswordPage.tsx @@ -5,7 +5,7 @@ import { useAuth } from './useAuth' import { MapOverlayPage } from '../Templates' // eslint-disable-next-line react/prop-types -export function RequestPasswordPage ({ reset_url }) { +export function RequestPasswordPage ({ resetUrl }) { const [email, setEmail] = useState('') const { requestPasswordReset, loading } = useAuth() @@ -14,7 +14,7 @@ export function RequestPasswordPage ({ reset_url }) { const onReset = async () => { await toast.promise( - requestPasswordReset(email, reset_url), + requestPasswordReset(email, resetUrl), { success: { render () { diff --git a/src/Components/Auth/useAuth.tsx b/src/Components/Auth/useAuth.tsx index 6294a575..2139d2bf 100644 --- a/src/Components/Auth/useAuth.tsx +++ b/src/Components/Auth/useAuth.tsx @@ -34,14 +34,14 @@ type AuthContextProps = { const AuthContext = createContext({ isAuthenticated: false, user: null, - login: () => Promise.reject(), - register: () => Promise.reject(), + login: () => Promise.reject(Error('Unimplemented')), + register: () => Promise.reject(Error('Unimplemented')), loading: false, - logout: () => Promise.reject(), - updateUser: () => Promise.reject(), + logout: () => Promise.reject(Error('Unimplemented')), + updateUser: () => Promise.reject(Error('Unimplemented')), token: '', - requestPasswordReset: () => Promise.reject(), - passwordReset: () => Promise.reject() + requestPasswordReset: () => Promise.reject(Error('Unimplemented')), + passwordReset: () => Promise.reject(Error('Unimplemented')) }) export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { @@ -123,10 +123,10 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { } } - const requestPasswordReset = async (email: string, reset_url?: string): Promise => { + const requestPasswordReset = async (email: string, resetUrl?: string): Promise => { setLoading(true) try { - await userApi.requestPasswordReset(email, reset_url) + await userApi.requestPasswordReset(email, resetUrl) return setLoading(false) } catch (error: any) { setLoading(false) @@ -134,10 +134,10 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { } } - const passwordReset = async (token: string, new_password:string): Promise => { + const passwordReset = async (token: string, newPassword:string): Promise => { setLoading(true) try { - await userApi.passwordReset(token, new_password) + await userApi.passwordReset(token, newPassword) return setLoading(false) } catch (error: any) { setLoading(false) diff --git a/src/Components/Gaming/Quests.tsx b/src/Components/Gaming/Quests.tsx index 648a5cd2..d95633a5 100644 --- a/src/Components/Gaming/Quests.tsx +++ b/src/Components/Gaming/Quests.tsx @@ -19,7 +19,7 @@ export function Quests () { const items = useItems() useEffect(() => { - setProfie(items.find(i => i.user_created?.id === user?.id && i.layer?.itemType.name == 'user' && i.user_created?.id != null)) + setProfie(items.find(i => i.user_created?.id === user?.id && i.layer?.itemType.name === 'user' && i.user_created?.id != null)) }, [items, user]) return ( diff --git a/src/Components/Input/Autocomplete.tsx b/src/Components/Input/Autocomplete.tsx index 86e77132..3f774404 100644 --- a/src/Components/Input/Autocomplete.tsx +++ b/src/Components/Input/Autocomplete.tsx @@ -57,7 +57,7 @@ export const Autocomplete = ({ inputProps, suggestions, onSelected, pushFiltered onSelected(filteredSuggestions[heighlightedSuggestion]) setHeighlightedSuggestion(0) } - filteredSuggestions.length == 0 && inputProps.onKeyDown(event) + filteredSuggestions.length === 0 && inputProps.onKeyDown(event) break default: inputProps.onKeyDown(event) @@ -70,7 +70,7 @@ export const Autocomplete = ({ inputProps, suggestions, onSelected, pushFiltered handleChange(e)} tabIndex="-1" onKeyDown={handleKeyDown}/>
    0 && 'tw-bg-base-100 tw-rounded-xl tw-p-2'}`}> {filteredSuggestions.map((suggestion, index) => ( -
  • handleSuggestionClick(suggestion)}>
  • +
  • handleSuggestionClick(suggestion)}>
  • ))}
diff --git a/src/Components/Input/ComboBoxInput.tsx b/src/Components/Input/ComboBoxInput.tsx index cff7fc9c..24e0619b 100644 --- a/src/Components/Input/ComboBoxInput.tsx +++ b/src/Components/Input/ComboBoxInput.tsx @@ -26,7 +26,7 @@ const ComboBoxInput = ({ id, options, value, onValueChange }: ComboBoxProps) => onChange={handleChange} > {options.map((o) => - + )} ) diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index 084e57c1..f300a06e 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -44,6 +44,7 @@ export const Layer = ({ onlyOnePerOwner = false, customEditLink, customEditParameter, + // eslint-disable-next-line camelcase public_edit_items, listed = true, setItemFormPopup, @@ -82,15 +83,17 @@ export const Layer = ({ const visibleGroupTypes = useVisibleGroupType() useEffect(() => { + // eslint-disable-next-line camelcase data && setItemsData({ data, children, name, menuIcon, menuText, menuColor, markerIcon, markerShape, markerDefaultColor, markerDefaultColor2, api, itemType, itemNameField, itemSubnameField, itemTextField, itemAvatarField, itemColorField, itemOwnerField, itemTagsField, itemOffersField, itemNeedsField, onlyOnePerOwner, customEditLink, customEditParameter, public_edit_items, listed, setItemFormPopup, itemFormPopup, clusterRef }) + // eslint-disable-next-line camelcase api && setItemsApi({ data, children, name, menuIcon, menuText, menuColor, markerIcon, markerShape, markerDefaultColor, markerDefaultColor2, api, itemType, itemNameField, itemSubnameField, itemTextField, itemAvatarField, itemColorField, itemOwnerField, itemTagsField, itemOffersField, itemNeedsField, onlyOnePerOwner, customEditLink, customEditParameter, public_edit_items, listed, setItemFormPopup, itemFormPopup, clusterRef }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [data, api]) useMapEvents({ 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) { + 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) { const params = new URLSearchParams(window.location.search) if (!location.pathname.includes('/item/')) { window.history.pushState({}, '', `/${item.id}` + `${params.toString() !== '' ? `?${params}` : ''}`) @@ -138,6 +141,7 @@ export const Layer = ({ processedTags[newtag.name] = true addTag(newtag) } + return null }) } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -149,9 +153,9 @@ export const Layer = ({ items .filter(item => item.layer?.name === name) ?.filter(item => - filterTags.length == 0 ? item : filterTags.some(tag => getItemTags(item).some(filterTag => filterTag.name.toLocaleLowerCase() === tag.name.toLocaleLowerCase()))) + filterTags.length === 0 ? item : filterTags.some(tag => getItemTags(item).some(filterTag => filterTag.name.toLocaleLowerCase() === tag.name.toLocaleLowerCase()))) ?.filter(item => item.layer && isLayerVisible(item.layer)) - .filter(item => item.group_type && isGroupTypeVisible(item.group_type) || visibleGroupTypes.length == 0) + .filter(item => item.group_type && isGroupTypeVisible(item.group_type) || visibleGroupTypes.length === 0) .map((item: Item) => { if (getValue(item, itemLongitudeField) && getValue(item, itemLatitudeField)) { if (getValue(item, itemTextField)) item[itemTextField] = getValue(item, itemTextField) @@ -171,6 +175,7 @@ export const Layer = ({ const newTag = { id: crypto.randomUUID(), name: tag.slice(1), color: randomColor() } setNewTagsToAdd(current => [...current, newTag]) } + return null }) !tagsReady && setTagsReady(true) } @@ -192,7 +197,7 @@ export const Layer = ({ } return ( { - if (!(item.id in leafletRefs && leafletRefs[item.id].marker == r)) { r && addMarker(item, r) } + if (!(item.id in leafletRefs && leafletRefs[item.id].marker === r)) { r && addMarker(item, r) } }} eventHandlers={{ click: () => { @@ -205,7 +210,7 @@ export const Layer = ({ ? React.Children.toArray(children).map((child) => React.isValidElement(child) && child.props.__TYPE === 'ItemView' ? { - if (!(item.id in leafletRefs && leafletRefs[item.id].popup == r)) { r && addPopup(item, r as Popup) } + if (!(item.id in leafletRefs && leafletRefs[item.id].popup === r)) { r && addPopup(item, r as Popup) } }} key={item.id + item.name} item={item} setItemFormPopup={setItemFormPopup}> @@ -215,7 +220,7 @@ export const Layer = ({ ) : <> { - if (!(item.id in leafletRefs && leafletRefs[item.id].popup == r)) { r && addPopup(item, r as Popup) } + if (!(item.id in leafletRefs && leafletRefs[item.id].popup === r)) { r && addPopup(item, r as Popup) } }} item={item} setItemFormPopup={setItemFormPopup} /> @@ -229,7 +234,7 @@ export const Layer = ({ } {// {children}} } - {itemFormPopup && itemFormPopup.layer!.name == name && + {itemFormPopup && itemFormPopup.layer!.name === name && (children && React.Children.toArray(children).some(child => React.isValidElement(child) && child.props.__TYPE === 'ItemForm') ? React.Children.toArray(children).map((child) => React.isValidElement(child) && child.props.__TYPE === 'ItemForm' diff --git a/src/Components/Map/Subcomponents/AddButton.tsx b/src/Components/Map/Subcomponents/AddButton.tsx index 0ffc6efd..025c7e04 100644 --- a/src/Components/Map/Subcomponents/AddButton.tsx +++ b/src/Components/Map/Subcomponents/AddButton.tsx @@ -10,6 +10,7 @@ export default function AddButton ({ triggerAction }: { triggerAction: React.Dis let canAdd = false layers.map(layer => { if (layer.api?.createItem && hasUserPermission(layer.api.collectionName!, 'create', undefined, layer) && layer.listed) canAdd = true + return null }) return canAdd } diff --git a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx index 5ac2a494..3041e528 100644 --- a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx +++ b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx @@ -80,7 +80,7 @@ export const SearchControl = () => { useEffect(() => { const params = new URLSearchParams(location.search) const embedded = params.get('embedded') - embedded != 'true' && setEmbedded(false) + embedded !== 'true' && setEmbedded(false) }, [location]) return (<> @@ -101,7 +101,7 @@ export const SearchControl = () => { - {hideSuggestions || Array.from(geoResults).length == 0 && itemsResults.length == 0 && tagsResults.length == 0 && !isGeoCoordinate(value) || value.length == 0 + {hideSuggestions || Array.from(geoResults).length === 0 && itemsResults.length === 0 && tagsResults.length === 0 && !isGeoCoordinate(value) || value.length === 0 ? '' :
{tagsResults.length > 0 && @@ -119,7 +119,7 @@ export const SearchControl = () => { {itemsResults.length > 0 && tagsResults.length > 0 &&
} {itemsResults.slice(0, 5).map(item => (
{ - const marker = Object.entries(leafletRefs).find(r => r[1].item == item)?.[1].marker + const marker = Object.entries(leafletRefs).find(r => r[1].item === item)?.[1].marker if (marker) { navigate(`/${item.id}?${new URLSearchParams(window.location.search)}`) } else { diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index 8694f282..2e731d2a 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -59,6 +59,7 @@ export function ItemFormPopup (props: ItemFormPopupProps) { if (!tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) { addTag({ id: crypto.randomUUID(), name: tag.slice(1), color: randomColor() }) } + return null }) if (props.item) { diff --git a/src/Components/Map/Subcomponents/ItemViewPopup.tsx b/src/Components/Map/Subcomponents/ItemViewPopup.tsx index c095edf2..e1dc56a2 100644 --- a/src/Components/Map/Subcomponents/ItemViewPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemViewPopup.tsx @@ -80,7 +80,7 @@ export const ItemViewPopup = React.forwardRef((props: ItemViewPopupProps, ref: a { infoExpanded - ?

{`${props.item.date_updated && props.item.date_updated != props.item.date_created ? 'updated' : 'posted'} ${props.item && props.item.user_created && props.item.user_created.first_name ? `by ${props.item.user_created.first_name}` : ''} ${props.item.date_updated ? timeAgo(props.item.date_updated) : timeAgo(props.item.date_created!)}`}

+ ?

{`${props.item.date_updated && props.item.date_updated !== props.item.date_created ? 'updated' : 'posted'} ${props.item && props.item.user_created && props.item.user_created.first_name ? `by ${props.item.user_created.first_name}` : ''} ${props.item.date_updated ? timeAgo(props.item.date_updated) : timeAgo(props.item.date_created!)}`}

:

setInfoExpanded(true)}>ⓘ

}
diff --git a/src/Components/Map/Tags.tsx b/src/Components/Map/Tags.tsx index 32238030..400a04c2 100644 --- a/src/Components/Map/Tags.tsx +++ b/src/Components/Map/Tags.tsx @@ -31,6 +31,7 @@ export function Tags ({ data, api } : {data?: Tag[], api?: ItemsApi}) { decodedTagsArray?.map(urlTag => { const tag = tags.find(t => t.name.toLocaleLowerCase() === urlTag.toLocaleLowerCase()) tag && addFilterTag(tag) + return null }) } diff --git a/src/Components/Map/hooks/useFilter.tsx b/src/Components/Map/hooks/useFilter.tsx index 32526c4e..294aafd9 100644 --- a/src/Components/Map/hooks/useFilter.tsx +++ b/src/Components/Map/hooks/useFilter.tsx @@ -105,7 +105,7 @@ function useFilterManager (initialTags: Tag[]): { case 'TOGGLE_LAYER': const exist2 = state.some((layer) => layer.name === action.layer.name) - if (exist2) return state.filter(({ name }) => name != action.layer.name) + if (exist2) return state.filter(({ name }) => name !== action.layer.name) else return [...state, action.layer] case 'RESET_LAYERS': return initialLayers @@ -129,7 +129,7 @@ function useFilterManager (initialTags: Tag[]): { case 'TOGGLE_GROUP_TYPE': const exist2 = state.some((groupType) => groupType === action.groupType) - if (exist2) return state.filter((groupType) => groupType != action.groupType) + if (exist2) return state.filter((groupType) => groupType !== action.groupType) else return [...state, action.groupType] case 'RESET_GROUP_TYPE': return [] @@ -162,9 +162,10 @@ function useFilterManager (initialTags: Tag[]): { const urlTags = params.get('tags') let newUrlTags = '' const tags = urlTags?.split(';') - if (tags?.length == 0 && urlTags?.length && urlTags?.length > 0) tags[0] = urlTags + if (tags?.length === 0 && urlTags?.length && urlTags?.length > 0) tags[0] = urlTags tags?.map(urlTag => { if (!(urlTag.toLocaleLowerCase() === name.toLocaleLowerCase())) { newUrlTags = newUrlTags + `${newUrlTags === '' ? urlTag : `;${urlTag}`}` } + return null }) if (newUrlTags !== '') { params.set('tags', `${newUrlTags}`) diff --git a/src/Components/Map/hooks/useItems.tsx b/src/Components/Map/hooks/useItems.tsx index 835d1caf..6fb25faf 100644 --- a/src/Components/Map/hooks/useItems.tsx +++ b/src/Components/Map/hooks/useItems.tsx @@ -91,6 +91,7 @@ function useItemsManager (initialItems: Item[]): { if (result) { result.map(item => { dispatch({ type: 'ADD', item: { ...item, layer } }) + return null }) setallItemsLoaded(true) } @@ -101,6 +102,7 @@ function useItemsManager (initialItems: Item[]): { addLayer(layer) layer.data?.map(item => { dispatch({ type: 'ADD', item: { ...item, layer } }) + return null }) setallItemsLoaded(true) // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index 4635650a..71d08d0c 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -57,6 +57,7 @@ function usePermissionsManager (initialPermissions: Permission[]): { if (result) { result.map(permission => { dispatch({ type: 'ADD', permission }) + return null }) } }, []) @@ -64,6 +65,7 @@ function usePermissionsManager (initialPermissions: Permission[]): { const setPermissionData = useCallback((data: Permission[]) => { data.map(permission => { dispatch({ type: 'ADD', permission }) + return null }) }, []) diff --git a/src/Components/Map/hooks/useSelectPosition.tsx b/src/Components/Map/hooks/useSelectPosition.tsx index 5f1031da..73ecadbc 100644 --- a/src/Components/Map/hooks/useSelectPosition.tsx +++ b/src/Components/Map/hooks/useSelectPosition.tsx @@ -94,11 +94,11 @@ function useSelectPositionManager (): { const linkItem = async (id: string) => { if (markerClicked) { - const new_relations = markerClicked.relations || [] + const newRelations = markerClicked.relations || [] - if (!new_relations.some(r => r.related_items_id == id)) { - new_relations?.push({ items_id: markerClicked.id, related_items_id: id }) - const updatedItem = { id: markerClicked.id, relations: new_relations } + if (!newRelations.some(r => r.related_items_id === id)) { + newRelations?.push({ items_id: markerClicked.id, related_items_id: id }) + const updatedItem = { id: markerClicked.id, relations: newRelations } let success = false try { @@ -108,7 +108,7 @@ function useSelectPositionManager (): { toast.error(error.toString()) } if (success) { - updateItem({ ...markerClicked, relations: new_relations }) + updateItem({ ...markerClicked, relations: newRelations }) toast.success('Item linked') } } diff --git a/src/Components/Map/hooks/useTags.tsx b/src/Components/Map/hooks/useTags.tsx index 4efeef68..9125abba 100644 --- a/src/Components/Map/hooks/useTags.tsx +++ b/src/Components/Map/hooks/useTags.tsx @@ -43,7 +43,7 @@ function useTagsManager (initialTags: Tag[]): { ...state, { ...action.tag } ] - if (tagCount == newState.length) setallTagsLoaded(true) + if (tagCount === newState.length) setallTagsLoaded(true) return newState } else return state default: @@ -57,11 +57,12 @@ function useTagsManager (initialTags: Tag[]): { setApi(api) const result = await api.getItems() setTagCount(result.length) - if (tagCount == 0) setallTagsLoaded(true) + if (tagCount === 0) setallTagsLoaded(true) if (result) { result.map(tag => { // tag.name = tag.name.toLocaleLowerCase(); dispatch({ type: 'ADD', tag }) + return null }) } @@ -72,6 +73,7 @@ function useTagsManager (initialTags: Tag[]): { data.map(tag => { // tag.name = tag.name.toLocaleLowerCase(); dispatch({ type: 'ADD', tag }) + return null }) }, []) @@ -93,14 +95,17 @@ function useTagsManager (initialTags: Tag[]): { if (tags.find(t => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) { itemTags.push(tags.find(t => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())!) } + return null }) item.layer?.itemOffersField && getValue(item, item.layer.itemOffersField)?.map(o => { const offer = tags.find(t => t.id === o.tags_id) offer && itemTags.push(offer) + return null }) item.layer?.itemNeedsField && getValue(item, item.layer.itemNeedsField)?.map(n => { const need = tags.find(t => t.id === n.tags_id) need && itemTags.push(need) + return null }) return itemTags diff --git a/src/Components/Profile/ProfileForm.tsx b/src/Components/Profile/ProfileForm.tsx index b658ebad..e12b2e29 100644 --- a/src/Components/Profile/ProfileForm.tsx +++ b/src/Components/Profile/ProfileForm.tsx @@ -64,7 +64,7 @@ export function ProfileForm ({ userType }: { userType: string }) { const item = items.find(i => i.id === itemId) item && setItem(item) - const layer = layers.find(l => l.itemType.name == userType) + const layer = layers.find(l => l.itemType.name === userType) !item && setItem({ id: crypto.randomUUID(), name: user ? user.first_name : '', text: '', layer, new: true }) @@ -132,15 +132,15 @@ export function ProfileForm ({ userType }: { userType: string }) { - {template == 'onepager' && ( + {template === 'onepager' && ( )} - {template == 'simple' && + {template === 'simple' && } - {template == 'tabs' && + {template === 'tabs' && linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)} setUrlParams={setUrlParams}> } diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index 4ad6733a..0b5ad6c6 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -69,14 +69,17 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a item?.layer?.itemOffersField && getValue(item, item.layer.itemOffersField)?.map(o => { const tag = tags.find(t => t.id === o.tags_id) tag && setOffers(current => [...current, tag]) + return null }) item?.layer?.itemNeedsField && getValue(item, item.layer.itemNeedsField)?.map(n => { const tag = tags.find(t => t.id === n.tags_id) tag && setNeeds(current => [...current, tag]) + return null }) item?.relations?.map(r => { - const item = items.find(i => i.id == r.related_items_id) + const item = items.find(i => i.id === r.related_items_id) item && setRelations(current => [...current, item]) + return null }) // eslint-disable-next-line react-hooks/exhaustive-deps @@ -91,7 +94,7 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a } if (item) { if (item.position) { - const marker = Object.entries(leafletRefs).find(r => r[1].item == item)?.[1].marker + const marker = Object.entries(leafletRefs).find(r => r[1].item === item)?.[1].marker marker && clusterRef.hasLayer(marker) && clusterRef?.zoomToShowLayer(marker, () => { const bounds = map.getBounds() const x = bounds.getEast() - bounds.getWest() @@ -100,7 +103,7 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a ) } else { const parent = getFirstAncestor(item) - const marker = Object.entries(leafletRefs).find(r => r[1].item == parent)?.[1].marker + const marker = Object.entries(leafletRefs).find(r => r[1].item === parent)?.[1].marker marker && clusterRef.hasLayer(marker) && clusterRef?.zoomToShowLayer(marker, () => { const bounds = map.getBounds() const x = bounds.getEast() - bounds.getWest() @@ -146,15 +149,15 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a handleDelete(e, item, setLoading, removeItem, map, navigate)} editCallback={() => navigate('/edit-item/' + item.id)} setPositionCallback={() => { map.closePopup(); setSelectPosition(item); navigate('/') }} big truncateSubname={false} />
- {template == 'onepager' && + {template === 'onepager' && } - {template == 'simple' && + {template === 'simple' && } - {template == 'tabs' && + {template === 'tabs' && linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)}/> } diff --git a/src/Components/Profile/Subcomponents/ActionsButton.tsx b/src/Components/Profile/Subcomponents/ActionsButton.tsx index 8b4b493e..b6417c7d 100644 --- a/src/Components/Profile/Subcomponents/ActionsButton.tsx +++ b/src/Components/Profile/Subcomponents/ActionsButton.tsx @@ -25,7 +25,7 @@ export function ActionButton ({ item, triggerAddButton, triggerItemSelected, exi const items = useItems() - const filterdItems = items.filter(i => !itemType || i.layer?.itemType.name == itemType).filter(i => !existingRelations.some(s => s.id == i.id)).filter(i => i.id != item.id) + const filterdItems = items.filter(i => !itemType || i.layer?.itemType.name === itemType).filter(i => !existingRelations.some(s => s.id === i.id)).filter(i => i.id !== item.id) return ( <>{hasUserPermission(collection, 'update', item) && diff --git a/src/Components/Profile/Subcomponents/ProfileSubHeader.tsx b/src/Components/Profile/Subcomponents/ProfileSubHeader.tsx index 6b2c00de..a7c45a8a 100644 --- a/src/Components/Profile/Subcomponents/ProfileSubHeader.tsx +++ b/src/Components/Profile/Subcomponents/ProfileSubHeader.tsx @@ -29,7 +29,7 @@ const SubHeader = ({ type, status, url, title }) => (
{status &&
- {statusMapping[status]} + {statusMapping[status]}
} {type &&
{type} diff --git a/src/Components/Profile/Templates/OnepagerView.tsx b/src/Components/Profile/Templates/OnepagerView.tsx index d67b4762..ec82bf69 100644 --- a/src/Components/Profile/Templates/OnepagerView.tsx +++ b/src/Components/Profile/Templates/OnepagerView.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react' import { useItems } from '../../Map/hooks/useItems' export const OnepagerView = ({ item, userType }:{item: Item, userType: string}) => { - const [profile_owner, setProfileOwner] = useState() + const [profileOwner, setProfileOwner] = useState() const items = useItems() useEffect(() => { @@ -34,7 +34,7 @@ export const OnepagerView = ({ item, userType }:{item: Item, userType: string}) />
{item.user_created.first_name && ( - + )} {/* Description Section */} diff --git a/src/Components/Profile/Templates/TabsForm.tsx b/src/Components/Profile/Templates/TabsForm.tsx index ab751435..adcc9de1 100644 --- a/src/Components/Profile/Templates/TabsForm.tsx +++ b/src/Components/Profile/Templates/TabsForm.tsx @@ -35,7 +35,7 @@ export const TabsForm = ({ item, state, setState, updatePermission, linkItem, un return (
- updateActiveTab(1)} /> + updateActiveTab(1)} />
{item.layer.itemType.show_start_end_input && @@ -76,7 +76,7 @@ export const TabsForm = ({ item, state, setState, updatePermission, linkItem, un
{item.layer?.itemType.offers_and_needs && <> - updateActiveTab(3)} /> + updateActiveTab(3)} />
@@ -97,7 +97,7 @@ export const TabsForm = ({ item, state, setState, updatePermission, linkItem, un } {item.layer?.itemType.relations && <> - updateActiveTab(7)} /> + updateActiveTab(7)} />
diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx index acba15db..c294560b 100644 --- a/src/Components/Profile/Templates/TabsView.tsx +++ b/src/Components/Profile/Templates/TabsView.tsx @@ -56,7 +56,7 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation
updateActiveTab(1)} />
@@ -71,14 +71,14 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation <> updateActiveTab(2)} />
{attestations - .filter(a => a.to.some(t => t.directus_users_id == item.user_created.id)) + .filter(a => a.to.some(t => t.directus_users_id === item.user_created.id)) .sort((a, b) => new Date(b.date_created).getTime() - new Date(a.date_created).getTime()) .map((a, i) => ( @@ -120,7 +120,7 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation <> - updateActiveTab(3)} /> + updateActiveTab(3)} />
@@ -159,7 +159,7 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation {item.layer?.itemType.relations && <> - updateActiveTab(7)} /> + updateActiveTab(7)} />
diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index ffbd1709..309a0f18 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -20,10 +20,11 @@ export const submitNewItem = async (evt: any, type: string, item, user, setLoadi if (!tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) { addTag({ id: crypto.randomUUID(), name: tag.slice(1), color: randomColor() }) } + return null }) const uuid = crypto.randomUUID() - const layer = layers.find(l => l.name.toLocaleLowerCase().replace('s', '') == addItemPopupType.toLocaleLowerCase()) + const layer = layers.find(l => l.name.toLocaleLowerCase().replace('s', '') === addItemPopupType.toLocaleLowerCase()) let success = false try { @@ -43,9 +44,9 @@ export const submitNewItem = async (evt: any, type: string, item, user, setLoadi } export const linkItem = async (id: string, item, updateItem) => { - const new_relations = item.relations || [] - new_relations?.push({ items_id: item.id, related_items_id: id }) - const updatedItem = { id: item.id, relations: new_relations } + const newRelations = item.relations || [] + newRelations?.push({ items_id: item.id, related_items_id: id }) + const updatedItem = { id: item.id, relations: newRelations } let success = false try { @@ -55,14 +56,14 @@ export const linkItem = async (id: string, item, updateItem) => { toast.error(error.toString()) } if (success) { - updateItem({ ...item, relations: new_relations }) + updateItem({ ...item, relations: newRelations }) toast.success('Item linked') } } export const unlinkItem = async (id: string, item, updateItem) => { - const new_relations = item.relations?.filter(r => r.related_items_id !== id) - const updatedItem = { id: item.id, relations: new_relations } + const newRelations = item.relations?.filter(r => r.related_items_id !== id) + const updatedItem = { id: item.id, relations: newRelations } let success = false try { @@ -72,7 +73,7 @@ export const unlinkItem = async (id: string, item, updateItem) => { toast.error(error.toString()) } if (success) { - updateItem({ ...item, relations: new_relations }) + updateItem({ ...item, relations: newRelations }) toast.success('Item unlinked') } } @@ -101,22 +102,24 @@ 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 - const offer_updates: Array = [] + const offerUpdates: Array = [] // check for new offers await state.offers?.map(o => { const existingOffer = item?.offers?.find(t => t.tags_id === o.id) - existingOffer && offer_updates.push(existingOffer.id) + existingOffer && offerUpdates.push(existingOffer.id) if (!existingOffer && !tags.some(t => t.id === o.id)) addTag({ ...o, offer_or_need: true }) - !existingOffer && offer_updates.push({ items_id: item?.id, tags_id: o.id }) + !existingOffer && offerUpdates.push({ items_id: item?.id, tags_id: o.id }) + return null }) - const needs_updates: Array = [] + const needsUpdates: Array = [] await state.needs?.map(n => { const existingNeed = item?.needs?.find(t => t.tags_id === n.id) - existingNeed && needs_updates.push(existingNeed.id) - !existingNeed && needs_updates.push({ items_id: item?.id, tags_id: n.id }) + existingNeed && needsUpdates.push(existingNeed.id) + !existingNeed && needsUpdates.push({ items_id: item?.id, tags_id: n.id }) !existingNeed && !tags.some(t => t.id === n.id) && addTag({ ...n, offer_or_need: true }) + return null }) // update profile item in current state @@ -136,22 +139,24 @@ export const onUpdateItem = async (state, item, tags, addTag, setLoading, naviga ...state.markerIcon && { markerIcon: state.markerIcon }, next_appointment: state.nextAppointment, ...state.image.length > 10 && { image: state.image }, - ...state.offers.length > 0 && { offers: offer_updates }, - ...state.needs.length > 0 && { needs: needs_updates } + ...state.offers.length > 0 && { offers: offerUpdates }, + ...state.needs.length > 0 && { needs: needsUpdates } } - const offers_state: Array = [] - const needs_state: Array = [] + const offersState: Array = [] + const needsState: Array = [] state.offers.map(o => { - offers_state.push({ items_id: item?.id, tags_id: o.id }) + offersState.push({ items_id: item?.id, tags_id: o.id }) + return null }) state.needs.map(n => { - needs_state.push({ items_id: item?.id, tags_id: n.id }) + needsState.push({ items_id: item?.id, tags_id: n.id }) + return null }) - changedItem = { ...changedItem, offers: offers_state, needs: needs_state } + changedItem = { ...changedItem, offers: offersState, needs: needsState } setLoading(true) @@ -159,6 +164,7 @@ export const onUpdateItem = async (state, item, tags, addTag, setLoading, naviga if (!tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) { addTag({ id: crypto.randomUUID(), name: encodeTag(tag.slice(1).toLocaleLowerCase()), color: randomColor() }) } + return null }) // take care that addTag request comes before item request diff --git a/src/Components/Templates/AttestationForm.tsx b/src/Components/Templates/AttestationForm.tsx index 52c9b6f0..0c19604b 100644 --- a/src/Components/Templates/AttestationForm.tsx +++ b/src/Components/Templates/AttestationForm.tsx @@ -16,8 +16,8 @@ export const AttestationForm = ({ api }:{api?:ItemsApi}) => { useEffect(() => { const params = new URLSearchParams(location.search) - const to_user_ids = params.get('to') - setUsers(items.filter(i => to_user_ids?.includes(i.id))) + const toUserIds = params.get('to') + setUsers(items.filter(i => toUserIds?.includes(i.id))) // eslint-disable-next-line react-hooks/exhaustive-deps }, [items, location]) diff --git a/src/Components/Templates/DateUserInfo.tsx b/src/Components/Templates/DateUserInfo.tsx index adf3c9f8..7415923e 100644 --- a/src/Components/Templates/DateUserInfo.tsx +++ b/src/Components/Templates/DateUserInfo.tsx @@ -9,7 +9,7 @@ export const DateUserInfo = ({ item }: { item: Item }) => { { infoExpanded - ?

setInfoExpanded(false)} >{`${item.date_updated && item.date_updated != item.date_created ? 'updated' : 'posted'} ${item && item.user_created && item.user_created.first_name ? `by ${item.user_created.first_name}` : ''} ${item.date_updated ? timeAgo(item.date_updated) : timeAgo(item.date_created!)}`}

+ ?

setInfoExpanded(false)} >{`${item.date_updated && item.date_updated !== item.date_created ? 'updated' : 'posted'} ${item && item.user_created && item.user_created.first_name ? `by ${item.user_created.first_name}` : ''} ${item.date_updated ? timeAgo(item.date_updated) : timeAgo(item.date_created!)}`}

:

setInfoExpanded(true)}>ⓘ

}
diff --git a/src/Components/Templates/EmojiPicker.tsx b/src/Components/Templates/EmojiPicker.tsx index e9b4102a..e08957f7 100644 --- a/src/Components/Templates/EmojiPicker.tsx +++ b/src/Components/Templates/EmojiPicker.tsx @@ -39,7 +39,7 @@ export const EmojiPicker = ({ selectedEmoji, selectedColor, selectedShape, setSe <>
{selectedEmoji}
@@ -51,7 +51,7 @@ export const EmojiPicker = ({ selectedEmoji, selectedColor, selectedShape, setSe @@ -62,7 +62,7 @@ export const EmojiPicker = ({ selectedEmoji, selectedColor, selectedShape, setSe {shapes.map(shape => (
selectShape(shape)}>
@@ -73,7 +73,7 @@ export const EmojiPicker = ({ selectedEmoji, selectedColor, selectedShape, setSe {colors.map(color => (
selectColor(color)}>
diff --git a/src/Components/Templates/MarketView.tsx b/src/Components/Templates/MarketView.tsx index 65adda58..2606f57b 100644 --- a/src/Components/Templates/MarketView.tsx +++ b/src/Components/Templates/MarketView.tsx @@ -38,11 +38,14 @@ export const MarketView = () => { i?.layer?.itemOffersField && getValue(i, i.layer.itemOffersField)?.map(o => { const tag = tags.find(t => t.id === o.tags_id) tag && setOffers(current => [...current, tag]) + return null }) i?.layer?.itemNeedsField && getValue(i, i.layer.itemNeedsField)?.map(n => { const tag = tags.find(t => t.id === n.tags_id) tag && setNeeds(current => [...current, tag]) + return null }) + return null }) console.log(offers) diff --git a/src/Components/Templates/OverlayItemsIndexPage.tsx b/src/Components/Templates/OverlayItemsIndexPage.tsx index b2261691..456068a0 100644 --- a/src/Components/Templates/OverlayItemsIndexPage.tsx +++ b/src/Components/Templates/OverlayItemsIndexPage.tsx @@ -46,7 +46,7 @@ export const OverlayItemsIndexPage = ({ url, layerName, parameterField, plusButt const filterTags = useFilterTags() const getItemTags = useGetItemTags() - const layer = layers.find(l => l.name == layerName) + const layer = layers.find(l => l.name === layerName) const submitNewItem = async (evt: any) => { evt.preventDefault() @@ -61,6 +61,7 @@ export const OverlayItemsIndexPage = ({ url, layerName, parameterField, plusButt if (!tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) { addTag({ id: crypto.randomUUID(), name: tag.slice(1), color: randomColor() }) } + return null }) const uuid = crypto.randomUUID() let success = false @@ -109,7 +110,7 @@ export const OverlayItemsIndexPage = ({ url, layerName, parameterField, plusButt { items?.filter(i => i.layer?.name === layerName) .filter(item => - filterTags.length == 0 ? item : filterTags.some(tag => getItemTags(item).some(filterTag => filterTag.name.toLocaleLowerCase() === tag.name.toLocaleLowerCase()))) + filterTags.length === 0 ? item : filterTags.some(tag => getItemTags(item).some(filterTag => filterTag.name.toLocaleLowerCase() === tag.name.toLocaleLowerCase()))) ?.sort((a, b) => { // Convert date_created to milliseconds, handle undefined by converting to lowest possible date (0 milliseconds) const dateA = a.date_updated ? new Date(a.date_updated).getTime() : a.date_created ? new Date(a.date_created).getTime() : 0 @@ -122,7 +123,7 @@ export const OverlayItemsIndexPage = ({ url, layerName, parameterField, plusButt
)) } - {addItemPopupType == 'place' && ( + {addItemPopupType === 'place' && (
submitNewItem(e)}>