Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make critical filter non local #958

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/organisms/News.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const News: FC = () => {
{date}, {news.display_source}
</Typography.Body5>
</p>
{(news.hasOwnProperty('critical') && news.critical) && <img src={CriticalIcon} alt="" style={{ height: "30px", width: "30px", mixBlendMode: "multiply" }} />}
{news.critical && <img src={CriticalIcon} style={{ height: "30px", width: "30px", mixBlendMode: "multiply" }} />}
</Box>
<Typography.Body5>{news.title}</Typography.Body5>
</Box>
Expand Down
11 changes: 10 additions & 1 deletion src/services/news.data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@ const errorNews: INewsFlash = {
};

const NEWS_FLASH_API: string = '/api/news-flash';
export interface IFetchNewsQueryParams {
source?: string;
offSet?: number;
limit?: number;
critical?: boolean | null;
};

export function fetchNews(source = '', offSet = 0, limit = 100): Promise<any> {
export function fetchNews({source = '', offSet = 0, limit = 100, critical = null}: IFetchNewsQueryParams = {}): Promise<any> {
const query = [];
if (source) {
query.push(`source=${source}`);
}
if (limit) {
query.push(`limit=${limit}`);
}
if (critical !== null) {
query.push(`critical=${critical}`);
}
query.push(`offset=${offSet}`);

query.push('resolution=suburban_road');
Expand Down
20 changes: 11 additions & 9 deletions src/store/news-flash-store.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { runInAction, makeAutoObservable } from 'mobx';
import { SourceFilterEnum } from 'models/SourceFilter';
import { fetchNews } from 'services/news.data.service';
import { fetchNews, IFetchNewsQueryParams } from 'services/news.data.service';
import { INewsFlash } from 'models/NewFlash';
import { IPoint } from 'models/Point';
import RootStore from './root.store';

function filterByCritical(newsFlashCollection: Array<INewsFlash>): Array<INewsFlash> {
return newsFlashCollection.filter(news => news.hasOwnProperty("critical") && news.critical);
}

const DEFAULT_TIME_FILTER = 5;
const DEFAULT_LOCATION = { latitude: 32.0853, longitude: 34.7818 };
const LOCAL_FILTERS: { [key in SourceFilterEnum]?: (newsFlashCollection: Array<INewsFlash>) => Array<INewsFlash> } = {
[SourceFilterEnum.critical]: filterByCritical
}
const LOCAL_FILTERS: { [key in SourceFilterEnum]?: (newsFlashCollection: Array<INewsFlash>) => Array<INewsFlash> } = {};

export default class NewsFlashStore {
rootStore: RootStore;
Expand Down Expand Up @@ -114,7 +108,15 @@ export default class NewsFlashStore {
runInAction(() => (this.newsFlashCollection = [...(filtered || [])]));
runInAction(() => (this.newsFlashLoading = false));
} else {
fetchNews(this.newsFlashActiveFilter, this.newsFlashFetchOffSet).then((data: any) => {
const queryParams: IFetchNewsQueryParams = {
offSet: this.newsFlashFetchOffSet
};
if (this.newsFlashActiveFilter == "critical") {
queryParams["critical"] = true;
} else {
queryParams["source"] = this.newsFlashActiveFilter;
}
fetchNews(queryParams).then((data: any) => {
runInAction(() => (this.newsFlashLoading = false));
if (data) {
runInAction(() => (this.newsFlashCollection = [...this.newsFlashCollection, ...data]));
Expand Down