Skip to content

Commit

Permalink
fix: repo structure + formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marinovl7 committed Nov 3, 2024
2 parents 69a2ea4 + 55ee683 commit adcc05d
Show file tree
Hide file tree
Showing 49 changed files with 1,183 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SERVER_ENDPOINT=https://api.hungermapdata.org/v2
NEXT_PUBLIC_API_URL=https://api.hungermapdata.org/v2
2 changes: 1 addition & 1 deletion .env_template
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SERVER_ENDPOINT=https://api.hungermapdata.org/v2
NEXT_PUBLIC_API_URL=https://api.hungermapdata.org/v2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel
Expand Down
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn commitlint --edit $1
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ Linting and styling is based on [Airbnb's React style guide](https://airbnb.io/j

### Git and GitHub

Always work on a separate branch, never commit to main! When you're creating a branch, you should use the branchname provided by Linear. Click the branch icon in the upper right corner of issue's page on Linear to copy the branchname. It should have the following format: `feature/<issue no.>-<concise description of issue>`. Also use meaningful, but concise commit messages. After you're done with your task, create a Pull Request and share it with your teammates, ask your team lead and/or TPL for a review. Use squash merge when the PR is approved.
Always work on a separate branch, never commit to main! When you're creating a branch, you should use the branchname provided by Linear. Click the branch icon in the upper right corner of issue's page on Linear to copy the branchname. It should have the following format: `feature/<issue no.>-<concise description of issue>`.

Commit messages are also linted using husky and commitlint, so make sure to start each commit message with `feat:`, `fix:` or `docs:` depending on the type of work implemented in that commit.

After you're done with your task, create a Pull Request and share it with your teammates, ask your team lead and/or TPL for a review. Use squash merge when the PR is approved.

### Project Structure

Expand All @@ -54,7 +58,8 @@ What this means for a React application, is that instead of using one global sta

- The domain folder contains all the entities and repositories. (Types, Interfaces, etc.)
- The infrastructure folder contains the implementations of the interfaces. (API calls, etc.)
- The application folder contains the services that use the infrastructure to implement the business logic.
- The operations folder contains the business logic that is not related to a specific entity.
- Bigger files and functions should be placed in the operations folder

### Dependency Injection

Expand Down
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {};

module.exports = nextConfig
module.exports = nextConfig;
21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
"leaflet": "^1.9.4",
"leaflet-defaulticon-compatibility": "^0.1.2",
"leaflet-geosearch": "^4.0.0",
"next": "14.2.4",
"next": "14.2.10",
"next-themes": "^0.2.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-leaflet": "^4.2.1",
"tailwind-variants": "0.1.20"
},
"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@types/leaflet": "^1.9.14",
"@types/node": "20.5.7",
"@types/react": "^18.3.12",
Expand All @@ -64,5 +66,22 @@
"prettier": "^3.3.3",
"tailwindcss": "3.4.3",
"typescript": "5.0.4"
},
"commitlint": {
"rules": {
"type-enum": [
2,
"always",
[
"feat",
"docs",
"fix"
]
],
"type-empty": [
2,
"never"
]
}
}
}
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
20 changes: 6 additions & 14 deletions src/app/elements/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { Suspense } from 'react';

import { ClientChart } from '@/components/Charts/ClientChart';

import Providers from './providers';
import { Chart } from '@/components/Charts/Chart';
import container from '@/container';
import CountryRepository from '@/domain/repositories/CountryRepository';
/**
* You can use this page to try and show off your components.
* It's not accessible from the UI, but you can reach it by manually navigating to /elements
*/

export default function Elements() {
return (
<Suspense fallback={<div className="w-full h-full flex justify-center items-center">Loading...</div>}>
<Providers>
<ClientChart />
</Providers>
</Suspense>
);
export default async function Elements() {
const countryData = await container.resolve<CountryRepository>('CountryRepository').getCountryData(50);
return <Chart chartData={countryData.fcsGraph} />;
}
70 changes: 4 additions & 66 deletions src/components/Charts/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,10 @@
import * as Highcharts from 'highcharts';
import { HighchartsReact } from 'highcharts-react-official';

import { FcsChartData } from '@/domain/entities/charts/FcsChartData';
import ChartProps from '@/domain/props/ChartProps';
import ChartOperations from '@/operations/charts/ChartOperations';

export function Chart(data: { data: FcsChartData[] }) {
const options: Highcharts.Options = {
title: {
text: 'FCS Chart',
},
xAxis: {
type: 'datetime',
labels: {
format: '{value:%b %d}',
},
categories: data.data.map((item) => item.x),
},
yAxis: {
title: {
text: 'FCS Value',
},
},
series: [
{
name: 'FCS',
type: 'line',
data: data.data.map((item) => item.fcs),
zIndex: 1,
marker: {
fillColor: 'white',
lineWidth: 2,
lineColor: 'orange',
},
},
{
name: 'High',
type: 'line',
data: data.data.map((item) => item.fcsHigh),
linkedTo: ':previous',
color: 'orange',
opacity: 0.3,
showInLegend: false,
},
{
name: 'Low',
type: 'line',
data: data.data.map((item) => item.fcsLow),
linkedTo: ':previous',
color: 'orange',
opacity: 0.3,
showInLegend: false,
},
],
plotOptions: {
line: {
animation: true,
marker: {
enabled: true,
},
},
arearange: {
animation: true,
fillOpacity: 0.1,
lineWidth: 0,
marker: {
enabled: false,
},
},
},
};
export function Chart({ chartData }: ChartProps) {
const options: Highcharts.Options = ChartOperations.getChartData(chartData);
return <HighchartsReact highcharts={Highcharts} options={options} />;
}
38 changes: 0 additions & 38 deletions src/components/Charts/ClientChart.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions src/container.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AlertRepositoryImpl } from './infrastructure/repositories/AlertRepositoryImpl';
import CountryRepositoryImpl from './infrastructure/repositories/CountryRepositoryImpl';
import GlobalDataRepositoryImpl from './infrastructure/repositories/GlobalDataRepositoryImpl';

class Container {
private dependencies: { [key: string]: unknown } = {};
Expand All @@ -18,5 +20,7 @@ class Container {
const container = new Container();

container.register('CountryRepository', new CountryRepositoryImpl());
container.register('AlertRepository', new AlertRepositoryImpl());
container.register('GlobalDataRepository', new GlobalDataRepositoryImpl());

export default container;
41 changes: 41 additions & 0 deletions src/domain/entities/Adm0Data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Coordinate } from './common/Coordinate';
import { Feature } from './common/Feature';

/**
* Not really sure what this represents...
*/
export type Adm0Data = Feature<{
OBJECTID: number;
adm0_name: string;
map_lab: string;
adm0_altnm: string;
iso3: string;
disp_area: string;
adm0_id: number;
source: string;
validity: number;
last_modif: string;
STSCOD: string;
MAPCLR: string;
source_adm: string;
Shape_Leng: number;
Shape_Area: number;
interactive?: boolean;
fcs?: number;
fcs_people_total?: number;
undernourishment?: number;
ipcPopulation?: number;
ipcAreasAnalysis?: string;
incomeLevel?: string;
alerts: {
covid: boolean;
fcs: boolean;
marketAccess: boolean;
conflict: boolean;
ndvi: boolean;
climateDry: boolean;
climateWet: boolean;
};
centroid: Coordinate;
dataType?: string;
}>;
5 changes: 5 additions & 0 deletions src/domain/entities/ChangeLogItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ChangeLogItem {
id_log: number;
date_log: string;
description: string;
}
14 changes: 14 additions & 0 deletions src/domain/entities/DisputedAreas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Feature } from './common/Feature';

export interface DisputedAreas {
type: string;
features: Feature<{
Code: number;
CodeISO3166_1A2: unknown;
CodeISO3166_1A3: string;
DataSource: string;
DisputedArea: boolean;
CreateDate: string;
Name: string;
}>[];
}
4 changes: 4 additions & 0 deletions src/domain/entities/YearInReview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface YearInReview {
label: string;
url: string;
}
8 changes: 8 additions & 0 deletions src/domain/entities/alerts/Conflict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ConflictType } from '@/domain/enums/ConflictType';

import { Feature } from '../common/Feature';

export type Conflict = Feature<{
count: number;
event_type: ConflictType;
}>;
10 changes: 10 additions & 0 deletions src/domain/entities/alerts/Hazard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface Hazard {
Id: number;
type: string;
severity_id: string;
hazard_name: string;
latitude: number;
longitude: number;
create_date: string;
last_update: string;
}
5 changes: 5 additions & 0 deletions src/domain/entities/charts/BalanceOfTradeGraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ChartData } from '../common/ChartData';

export interface BalanceOfTradeGraph {
data: ChartData[];
}
8 changes: 8 additions & 0 deletions src/domain/entities/charts/CurrencyExchangeGraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ChartData } from '../common/ChartData';

export interface CurrencyExchangeGraph {
name: string;
source: string;
updated: string;
data: ChartData[];
}
10 changes: 10 additions & 0 deletions src/domain/entities/charts/InflationGraphs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChartData } from '../common/ChartData';

export interface InflationGraphs {
headline: {
data: ChartData[];
};
food: {
data: ChartData[];
};
}
6 changes: 6 additions & 0 deletions src/domain/entities/charts/RegionFcsChartData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface RegionFcsChartData {
x: string;
fcs: number;
fcsHigh: number;
fcsLow: number;
}
4 changes: 4 additions & 0 deletions src/domain/entities/common/ChartData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ChartData {
y: number;
x: string;
}
4 changes: 4 additions & 0 deletions src/domain/entities/common/Coordinate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Coordinate {
latitude: number;
longitude: number;
}
7 changes: 7 additions & 0 deletions src/domain/entities/common/Feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Geometry } from './Geometry';

export interface Feature<T> {
type: string;
geometry: Geometry;
properties: T;
}
Loading

0 comments on commit adcc05d

Please sign in to comment.