Commit 4ef47046 authored by René Rösner's avatar René Rösner
Browse files

Feat: Added eslint config & fixes errors except of one to test (planning#428)

parent 652fc58b
......@@ -30,6 +30,21 @@
}
],
"eqeqeq": 0,
"array-callback-return": 0
"array-callback-return": 0,
"id-length": [
"error",
{
"min": 4,
"exceptions": [
"alt",
"App",
"id",
"img",
"key",
"src",
"tag"
]
}
]
}
}
\ No newline at end of file
import { MouseEvent } from 'react'
export function removeFromObjRecursive(name: string, obj: any) {
export function removeFromObjRecursive(nodeName: string, nextJsDataObject: any) {
return JSON.parse(
JSON.stringify(obj, function (key, value) {
if (key !== name) return value
JSON.stringify(nextJsDataObject, function (key, value) {
if (key !== nodeName) return value
})
)
}
export function replaceEmailsRecursive(name: string, obj: any) {
export function replaceEmailsRecursive(name: string, nextJsDataObject: any) {
return JSON.parse(
JSON.stringify(obj, function (key, value) {
JSON.stringify(nextJsDataObject, function (key, value) {
if (key === name) return encodeEmail(value)
return value
})
)
}
export function encodeEmail(str: string) {
return btoa(str)
export function encodeEmail(emailAddress: string) {
return btoa(emailAddress)
}
export function decodeEmail(str: string) {
return atob(str)
export function decodeEmail(encodedEmailAddress: string) {
return atob(encodedEmailAddress)
}
export function handleMailtoEvent(e: MouseEvent<HTMLAnchorElement>) {
const el = e.currentTarget
const base = el.dataset.base
export function handleMailtoEvent(mouseEvent: MouseEvent<HTMLAnchorElement>) {
const targetElement = mouseEvent.currentTarget
const base = targetElement.dataset.base
const mail = decodeEmail(base)
el.href = 'mailto:' + mail
targetElement.href = 'mailto:' + mail
return true
}
......
import Document, { Html, Head, Main, NextScript } from 'next/document'
class CustomizedDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
static async getInitialProps(context) {
const initialProps = await Document.getInitialProps(context)
return { ...initialProps }
}
......
......@@ -58,7 +58,7 @@ export default function ({ service }) {
export async function getStaticProps({ params }) {
const service = await fetchService(params.serviceName)
// remove unwanted data and encrypt eMails
// remove unwanted data nextJs stores globally and encrypt eMail addresses
const nosys = removeFromObjRecursive('sys', service.fields)
const fields = replaceEmailsRecursive('eMail', nosys)
return {
......
......@@ -33,48 +33,58 @@ export default function ({ services }) {
}, [router.query.filter])
function filterToParams() {
const res = []
Object.keys(activeFilters).forEach(f => {
if (activeFilters[f].length > 0) {
activeFilters[f].forEach(i => res.push(i))
const ressources = []
Object.keys(activeFilters).forEach(filter => {
if (activeFilters[filter].length > 0) {
activeFilters[filter].forEach(activeFilter => ressources.push(activeFilter))
}
})
return [...new Set(res)].join('&')
return [...new Set(ressources)].join('&')
}
function paramsToFilter(str) {
if (!str) return defaultFilters
const filters = str.split('&')
filters.forEach(f => {
const filter = f.split(':')[0]
if (activeFilters[filter].indexOf(f) < 0) {
activeFilters[filter].push(f)
function paramsToFilter(choosenFiltersAsString: String | String[]) {
if (!choosenFiltersAsString) {
return defaultFilters
} else if (Array.isArray(choosenFiltersAsString)) {
choosenFiltersAsString = choosenFiltersAsString[0]
}
const filters = choosenFiltersAsString.split('&')
filters.forEach(filterAsString => {
const filter = filterAsString.split(':')[0]
if (activeFilters[filter].indexOf(filterAsString) < 0) {
activeFilters[filter].push(filterAsString)
}
})
return activeFilters
}
function filterServices() {
return services.filter((s: ServiceType) => {
const tags: string[] = s.tags ? s.tags.map(o => o.fields ? o.fields.name : '') : []
return services.filter((service: ServiceType) => {
const tags: string[] = service.tags ? service.tags.map(tag => tag.fields ? tag.fields.name : '') : []
const groups: any = {}
let match = true
tags.forEach(tag => {
const t = tag.split(':')
if (!groups[t[0]]) groups[t[0]] = []
groups[t[0]].push(tag)
const tagTypePosition = 0
const tagLabelAsArray = tag.split(':')
const tagType = tagLabelAsArray[tagTypePosition]
if (!groups[tagType]) {
groups[tagType] = []
}
groups[tagType].push(tag)
})
Object.keys(activeFilters).forEach(f => {
if (activeFilters[f].length > 0) {
if (activeFilters[f].length === 0) return
if (!groups[f]) {
Object.keys(activeFilters).forEach(filterType => {
if (activeFilters[filterType].length > 0) {
if (activeFilters[filterType].length === 0) return
if (!groups[filterType]) {
match = false
return match
}
groups[f].forEach(item => {
if (item.startsWith(f + ':') && !activeFilters[f].includes(item)) {
groups[filterType].forEach(item => {
if (item.startsWith(filterType + ':') && !activeFilters[filterType].includes(item)) {
match = false
}
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment