-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- name: Install modules | ||
run: npm install | ||
- name: Run ESLint | ||
run: npx eslint . --ext .js,.jsx,.ts,.tsx | ||
- name: Run Prettier | ||
run: npx prettier --check . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"announcements": [ | ||
{ | ||
"title": { | ||
"de": "Infoveranstaltung", | ||
"en": "Information event" | ||
}, | ||
"description": { | ||
"de": "Neuland Ingolstadt e.V. lädt ein zur Infoveranstaltung am 10.04.2024 um 18:00 Uhr. Hier erfährst du alles über Neuland, unsere Projekte und wie du dich einbringen kannst.", | ||
"en": "Neuland Ingolstadt e.V. invites you to the information event on 10.04.2024 at 6:00 p.m. Here you will learn everything about Neuland, our projects and how you can get involved." | ||
}, | ||
"startDateTime": "2024-04-06T00:00:00", | ||
"endDateTime": "2024-04-10T18:00:00", | ||
"priority": 1, | ||
"url": "https://neuland-ingolstadt.de" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import demoData from '@/data/demo-data.json' | ||
import fs from 'fs/promises' | ||
|
||
const dataStore = `${process.env.STORE}/announcements.json` | ||
const isDev = process.env.NODE_ENV !== 'production' | ||
|
||
/** | ||
* Announcement data. | ||
* In development mode, this will return demo data. | ||
*/ | ||
export async function announcements(): Promise<Announcement[]> { | ||
if (isDev) { | ||
return demoData.announcements | ||
} | ||
const data = await fs.readFile(dataStore) | ||
return JSON.parse(data.toString()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,13 @@ | ||
import staticData from '@/data/mobility.json' | ||
import { getCharging } from '@/scraping/charging' | ||
|
||
import { cache } from '../..' | ||
|
||
const URL = | ||
'https://app.chargecloud.de/emobility:ocpi/7d25c525838f55d21766c0dfee5ad21f/app/2.0/locations?swlat=48.7555&swlng=11.4146&nelat=48.7767&nelng=11.4439' | ||
export const charging = async (): Promise<ChargingData[]> => { | ||
try { | ||
const data = cache.get<ChargingData[]>('chargingStations') | ||
if (data == null) { | ||
const resp = await fetch(URL) | ||
const data = await resp.json() | ||
if (resp.status !== 200) { | ||
throw new Error('Charging station data not available') | ||
} | ||
const result = data.data.map( | ||
(entry: { | ||
id: any | ||
name: string | ||
address: any | ||
city: any | ||
coordinates: { latitude: any; longitude: any } | ||
evses: { | ||
filter: (arg0: (x: any) => boolean) => { | ||
(): any | ||
new (): any | ||
length: any | ||
} | ||
length: any | ||
} | ||
operator: { name: any } | ||
}) => ({ | ||
id: entry.id, | ||
name: entry.name.trim(), | ||
address: entry.address, | ||
city: entry.city, | ||
latitude: entry.coordinates.latitude, | ||
longitude: entry.coordinates.longitude, | ||
operator: entry.operator.name, | ||
available: entry.evses.filter( | ||
(x) => x.status === 'AVAILABLE' | ||
).length, | ||
total: entry.evses.length, | ||
freeParking: | ||
staticData.charging.find((x) => x.id === entry.id) | ||
?.freeParking ?? null, | ||
}) | ||
) | ||
cache.set('chargingStations', result, 60) | ||
return result | ||
} | ||
return data | ||
} catch (e) { | ||
console.error(e) | ||
throw new Error('Charging station data not available') | ||
const data = cache.get<ChargingData[]>('chargingStations') | ||
if (data == null) { | ||
const result = await getCharging() | ||
cache.set('chargingStations', result, 60) | ||
return result | ||
} | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const announcementsType = gql` | ||
type Announcement { | ||
title: MultiLanguageString! | ||
description: MultiLanguageString! | ||
startDateTime: String! | ||
endDateTime: String! | ||
priority: Int! | ||
url: String | ||
} | ||
type MultiLanguageString { | ||
de: String | ||
en: String | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import staticData from '@/data/mobility.json' | ||
|
||
const URL = | ||
'https://app.chargecloud.de/emobility:ocpi/7d25c525838f55d21766c0dfee5ad21f/app/2.0/locations?swlat=48.7555&swlng=11.4146&nelat=48.7767&nelng=11.4439' | ||
|
||
export const getCharging = async (): Promise<ChargingData[]> => { | ||
try { | ||
const resp = await fetch(URL) | ||
const data = await resp.json() | ||
if (resp.status !== 200) { | ||
throw new Error('Charging station data not available') | ||
} | ||
const result = data.data.map( | ||
(entry: { | ||
id: number | ||
name: string | ||
address: string | ||
city: string | ||
coordinates: { latitude: number; longitude: number } | ||
evses: { | ||
filter: (arg0: (x: any) => boolean) => { | ||
(): number | ||
new (): number | ||
length: number | ||
} | ||
length: number | ||
} | ||
operator: { name: string } | ||
}) => ({ | ||
id: entry.id, | ||
name: entry.name.trim(), | ||
address: entry.address, | ||
city: entry.city, | ||
latitude: entry.coordinates.latitude, | ||
longitude: entry.coordinates.longitude, | ||
operator: entry.operator.name, | ||
available: entry.evses.filter((x) => x.status === 'AVAILABLE') | ||
.length, | ||
total: entry.evses.length, | ||
freeParking: | ||
staticData.charging.find( | ||
(x) => (x.id as unknown as number) === entry.id | ||
)?.freeParking ?? null, | ||
}) | ||
) | ||
|
||
return result | ||
} catch (e) { | ||
console.error(e) | ||
throw new Error('Charging station data not available') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
interface Announcement { | ||
title: { | ||
de: string | ||
en: string | ||
} | ||
description: { | ||
de: string | ||
en: string | ||
} | ||
startDateTime: string | ||
endDateTime: string | ||
priority: number | ||
url: string | null | ||
} |
File renamed without changes.