Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgebhardt committed Oct 29, 2024
1 parent 9546b2e commit 36aeda5
Show file tree
Hide file tree
Showing 36 changed files with 184 additions and 152 deletions.
4 changes: 2 additions & 2 deletions src/Components/AppShell/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -43,7 +43,7 @@ export default function NavBar ({ appName, userType }: { appName: string, userTy
{
success: {
render () {
return `Bye bye`
return 'Bye bye'
},
// other options
icon: '👋'
Expand Down
2 changes: 1 addition & 1 deletion src/Components/AppShell/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/AppShell/SidebarSubmenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function SidebarSubmenu ({ submenu, name, icon } : { path: string;
<Link to={m.path} className='' >
{m.icon}<span className="" data-te-sidenav-slim="false">{m.name}</span>
{
location.pathname == m.path
location.pathname === m.path
? (<span className="absolute mt-1 mb-1 inset-y-0 left-0 w-1 rounded-tr-md rounded-br-md bg-primary "
aria-hidden="true"></span>)
: null
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Auth/RequestPasswordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('')

const { requestPasswordReset, loading } = useAuth()
Expand All @@ -14,7 +14,7 @@ export function RequestPasswordPage ({ reset_url }) {

const onReset = async () => {
await toast.promise(
requestPasswordReset(email, reset_url),
requestPasswordReset(email, resetUrl),
{
success: {
render () {
Expand Down
20 changes: 10 additions & 10 deletions src/Components/Auth/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ type AuthContextProps = {
const AuthContext = createContext<AuthContextProps>({
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) => {
Expand Down Expand Up @@ -123,21 +123,21 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => {
}
}

const requestPasswordReset = async (email: string, reset_url?: string): Promise<any> => {
const requestPasswordReset = async (email: string, resetUrl?: string): Promise<any> => {
setLoading(true)
try {
await userApi.requestPasswordReset(email, reset_url)
await userApi.requestPasswordReset(email, resetUrl)
return setLoading(false)
} catch (error: any) {
setLoading(false)
throw error
}
}

const passwordReset = async (token: string, new_password:string): Promise<any> => {
const passwordReset = async (token: string, newPassword:string): Promise<any> => {
setLoading(true)
try {
await userApi.passwordReset(token, new_password)
await userApi.passwordReset(token, newPassword)
return setLoading(false)
} catch (error: any) {
setLoading(false)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Gaming/Quests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Input/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -70,7 +70,7 @@ export const Autocomplete = ({ inputProps, suggestions, onSelected, pushFiltered
<input ref={inputRef} {...inputProps} type="text" onChange={(e) => handleChange(e)} tabIndex="-1" onKeyDown={handleKeyDown}/>
<ul className={`tw-absolute tw-z-[4000] ${filteredSuggestions.length > 0 && 'tw-bg-base-100 tw-rounded-xl tw-p-2'}`}>
{filteredSuggestions.map((suggestion, index) => (
<li key={index} onClick={() => handleSuggestionClick(suggestion)}><TagView heighlight={index == heighlightedSuggestion} tag={suggestion}></TagView></li>
<li key={index} onClick={() => handleSuggestionClick(suggestion)}><TagView heighlight={index === heighlightedSuggestion} tag={suggestion}></TagView></li>
))}
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Input/ComboBoxInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ComboBoxInput = ({ id, options, value, onValueChange }: ComboBoxProps) =>
onChange={handleChange}
>
{options.map((o) =>
<option value={o.value} key={o.value} selected={o.value == value}>{o.label}</option>
<option value={o.value} key={o.value} selected={o.value === value}>{o.label}</option>
)}
</select>
)
Expand Down
21 changes: 13 additions & 8 deletions src/Components/Map/Layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Layer = ({
onlyOnePerOwner = false,
customEditLink,
customEditParameter,
// eslint-disable-next-line camelcase
public_edit_items,
listed = true,
setItemFormPopup,
Expand Down Expand Up @@ -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}` : ''}`)
Expand Down Expand Up @@ -138,6 +141,7 @@ export const Layer = ({
processedTags[newtag.name] = true
addTag(newtag)
}
return null
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -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)

Check failure on line 158 in src/Components/Map/Layer.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check failure on line 158 in src/Components/Map/Layer.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations
.map((item: Item) => {
if (getValue(item, itemLongitudeField) && getValue(item, itemLatitudeField)) {
if (getValue(item, itemTextField)) item[itemTextField] = getValue(item, itemTextField)
Expand All @@ -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)
}
Expand All @@ -192,7 +197,7 @@ export const Layer = ({
}
return (
<Marker ref={(r) => {
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: () => {
Expand All @@ -205,7 +210,7 @@ export const Layer = ({
? React.Children.toArray(children).map((child) =>
React.isValidElement(child) && child.props.__TYPE === 'ItemView'
? <ItemViewPopup ref={(r) => {
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}>
Expand All @@ -215,7 +220,7 @@ export const Layer = ({
)
: <>
<ItemViewPopup key={item.id + item.name} ref={(r) => {
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} />
Expand All @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/Components/Map/Subcomponents/AddButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Map/Subcomponents/Controls/SearchControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<>
Expand All @@ -101,7 +101,7 @@ export const SearchControl = () => {
</div>
<LocateControl />
</div>
{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

Check failure on line 104 in src/Components/Map/Subcomponents/Controls/SearchControl.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected mix of '||' and '&&'. Use parentheses to clarify the intended order of operations

Check failure on line 104 in src/Components/Map/Subcomponents/Controls/SearchControl.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected mix of '||' and '&&'. Use parentheses to clarify the intended order of operations
? ''
: <div className='tw-card tw-card-body tw-bg-base-100 tw-p-4 tw-mt-2 tw-shadow-xl tw-overflow-y-auto tw-max-h-[calc(100dvh-152px)] tw-absolute tw-z-3000'>
{tagsResults.length > 0 &&
Expand All @@ -119,7 +119,7 @@ export const SearchControl = () => {
{itemsResults.length > 0 && tagsResults.length > 0 && <hr className='tw-opacity-50'></hr>}
{itemsResults.slice(0, 5).map(item => (
<div key={item.id} className='tw-cursor-pointer hover:tw-font-bold' onClick={() => {
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 {
Expand Down
1 change: 1 addition & 0 deletions src/Components/Map/Subcomponents/ItemFormPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Map/Subcomponents/ItemViewPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const ItemViewPopup = React.forwardRef((props: ItemViewPopupProps, ref: a

{
infoExpanded
? <p className={'tw-italic tw-min-h-[21px] !tw-my-0 tw-text-gray-500'} >{`${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!)}`}</p>
? <p className={'tw-italic tw-min-h-[21px] !tw-my-0 tw-text-gray-500'} >{`${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!)}`}</p>
: <p className="!tw-my-0 tw-min-h-[21px] tw-font-bold tw-cursor-pointer tw-text-gray-500" onClick={() => setInfoExpanded(true)}></p>
}
<div className='tw-grow'></div>
Expand Down
1 change: 1 addition & 0 deletions src/Components/Map/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function Tags ({ data, api } : {data?: Tag[], api?: ItemsApi<Tag>}) {
decodedTagsArray?.map(urlTag => {
const tag = tags.find(t => t.name.toLocaleLowerCase() === urlTag.toLocaleLowerCase())
tag && addFilterTag(tag)
return null
})
}

Expand Down
7 changes: 4 additions & 3 deletions src/Components/Map/hooks/useFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 []
Expand Down Expand Up @@ -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}`)
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Map/hooks/useItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function useItemsManager (initialItems: Item[]): {
if (result) {
result.map(item => {
dispatch({ type: 'ADD', item: { ...item, layer } })
return null
})
setallItemsLoaded(true)
}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Map/hooks/usePermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ function usePermissionsManager (initialPermissions: Permission[]): {
if (result) {
result.map(permission => {
dispatch({ type: 'ADD', permission })
return null
})
}
}, [])

const setPermissionData = useCallback((data: Permission[]) => {
data.map(permission => {
dispatch({ type: 'ADD', permission })
return null
})
}, [])

Expand Down
10 changes: 5 additions & 5 deletions src/Components/Map/hooks/useSelectPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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')
}
}
Expand Down
Loading

0 comments on commit 36aeda5

Please sign in to comment.