Skip to content

Commit

Permalink
Merge pull request #212 from kartevonmorgen/develop
Browse files Browse the repository at this point in the history
merge develop into main
  • Loading branch information
navid-kalaei authored Jun 17, 2024
2 parents e4dd09b + 7f8f946 commit 0cd7e49
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 81 deletions.
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ assignees: wellemut

---

**Describe the bug**
A clear and concise description of what the bug is.
## Problem
A clear and concise description of the bug.

**To Reproduce**
#### To Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
## Expected behavior
A clear and concise description of what you expected to happen.

**Screenshots**
### Screenshots
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
Expand Down
4 changes: 4 additions & 0 deletions api/endpoints/BasicsEndpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// todo: should eliminate self_api because it causes troubles with the hosting domain


// todo: use SWR instead
export const BASICS_API_URL: string | undefined = process.env.NEXT_PUBLIC_BASICS_API
export const SELF_API_URL: string | undefined= process.env.NEXT_PUBLIC_SELF_API
Expand All @@ -20,4 +22,6 @@ export const BASICS_ENDPOINTS = {
postEntryRating: (): string => `${BASICS_API_URL}/ratings`,
getMainCheckboxes: (group: string): string => `${SELF_API_URL}/checkboxes/${group}/main-checkboxes`,
getTagMarkerColors: (project: string): string => `${SELF_API_URL}/maps/${project}/tags/markers/colors`,
postSubscription: (): string => `${BASICS_API_URL}/subscribe`,
getVersion: (): string => `${SELF_API_URL}/version`,
}
17 changes: 17 additions & 0 deletions components/BurgerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const Menu: FC = () => {
const { t } = useTranslation('map')


const { data: versionResponse, error: _versionError } = useRequest<{ version: string }>({
url: API_ENDPOINTS.getVersion(),
})

const version = versionResponse?.version ?? ''

const { data: linksWithIcon, error } = useRequest<LinkWithIcon[]>({
url: API_ENDPOINTS.getBurgerMenuLinks(projectName),
})
Expand Down Expand Up @@ -100,6 +106,17 @@ const Menu: FC = () => {
))
}
</Row>

<div
style={{
display: version ? 'block' : 'none',
textAlign: 'center',
marginTop: 4,
marginBottom: 4,
}}
>
{version}
</div>
</AntMenu>
)
}
Expand Down
3 changes: 1 addition & 2 deletions consts/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const version = 'v1.2.0'
const version = 'v1.2.4'


export default version

48 changes: 0 additions & 48 deletions pages/_documents.tsx

This file was deleted.

71 changes: 55 additions & 16 deletions pages/api/v0/maps/[project]/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,65 @@ import path from 'path'
import { NextApiRequest, NextApiResponse } from 'next'

import MapPageConfigs from '../../../../../../dtos/MapPageConfigs'
import { MapColorModes } from '../../../../../../components/MapColorStyle'


const getPath = (project: string = 'main'): string => {
return `./public/projects/${project}/config.json`
}


export const parseConfigFile = (project: string = 'main'): MapPageConfigs => {
let mapPageConfigs: MapPageConfigs = {
"map": {
"location": {
"lat": 50.8129,
"lng": 5.6030,
"zoom": 6
},
"colorStyle": MapColorModes.GRAY
},
"popularTags": {
"min_count": 2
},
"sidebar": {
"title": "Kartevonmorgen"
}
}

let fileContent: string = ''
try {
fileContent = fs.readFileSync(
path.resolve(getPath(project as string)),
'utf8',
)
} catch (e) {
console.error('api map config: failed to read config file for project: ', project)
console.error(e)
try {
console.log('api map config: trying to read default config file')
fileContent = fs.readFileSync(
path.resolve(getPath()),
'utf8',
)
} catch (e) {
console.error('api map config: failed to read default config file')
console.error(e)
}
}

try {
mapPageConfigs = JSON.parse(fileContent.toString())
} catch(e) {
console.error('api map config: failed to parse config file for project: ', project)
console.error(e)
}

console.log(mapPageConfigs)
return mapPageConfigs
}


export default (req: NextApiRequest, res: NextApiResponse) => {
const {
query: { project },
Expand All @@ -23,22 +76,8 @@ export default (req: NextApiRequest, res: NextApiResponse) => {
return
}

// todo: eighter move it to env or consts
// todo: catch the error if the file is not found

let fileContent: string = ''
try {
fileContent = fs.readFileSync(
path.resolve(getPath(project as string)),
'utf8',
)
} catch (e) {
fileContent = fs.readFileSync(
path.resolve(getPath()),
'utf8',
)
}
const mapPageConfigs: MapPageConfigs = JSON.parse(fileContent.toString())

const mapPageConfigs: MapPageConfigs = parseConfigFile(project as string)

res
.status(200)
Expand Down
12 changes: 12 additions & 0 deletions pages/api/v0/version/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NextApiRequest, NextApiResponse } from 'next'
import version from 'consts/version'

export default function handler(req: NextApiRequest, res: NextApiResponse) {
try {
// Return the version
res.status(200).json({ version })
} catch (error) {
// Handle any errors that occur
res.status(500).json({ error: 'Internal Server Error' })
}
}
13 changes: 3 additions & 10 deletions pages/m/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MapLocationProps } from '../../components/Map'
import { TagsCount } from '../../dtos/TagCount'
import Sidebar from '../../components/Sidebar'
import { MapColorModes } from '../../components/MapColorStyle'
import { parseConfigFile } from '../api/v0/maps/[project]/config'


const { Content } = Layout
Expand Down Expand Up @@ -81,16 +82,8 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {

// we expect to have path always not empty with the first element of project name
const project = path[0]

// set configs
const pageConfigsReq = await AxiosInstance.GetRequest<MapPageConfigs>(
API_ENDPOINTS.getMapPageConfigs(project),
{
timeout: 120000,
}
)

const pageConfigs = AxiosInstance.GetSuccessData(pageConfigsReq)

const pageConfigs = parseConfigFile(project as string)

const mapLocationProps = pageConfigs.map.location
const sidebarConfigs = pageConfigs.sidebar
Expand Down

0 comments on commit 0cd7e49

Please sign in to comment.