From fed021f6561a6a9b5f2ae462a59e571115aa6539 Mon Sep 17 00:00:00 2001 From: Eyal Date: Sat, 22 Jun 2024 14:10:47 +0100 Subject: [PATCH] download csv newsflash --- public/locales/he/translation.json | 3 ++- src/components/molecules/Header.tsx | 19 +++++++++++++------ src/components/organisms/FilterBar.tsx | 4 +++- src/services/news.data.service.ts | 18 ++++++++++++++++++ src/services/user.service.ts | 1 + src/store/news-flash-store.ts | 18 ++++++++++++++---- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/public/locales/he/translation.json b/public/locales/he/translation.json index d334f32b..5cc1837a 100644 --- a/public/locales/he/translation.json +++ b/public/locales/he/translation.json @@ -129,7 +129,8 @@ "Search": "חיפוש", "User Greeting": "שלום", "User Info Update": "פרטי משתמש", - "management": "ניהול" + "management": "ניהול", + "download":"הורדת מידע" }, "sideBar": "מיקום משוער:", "changeLocationButton": "שינוי/אישור מיקום", diff --git a/src/components/molecules/Header.tsx b/src/components/molecules/Header.tsx index abae928f..9918f766 100644 --- a/src/components/molecules/Header.tsx +++ b/src/components/molecules/Header.tsx @@ -16,7 +16,6 @@ import { IPoint } from 'models/Point'; import { useNavigate } from 'react-router-dom'; import anywayLogo from 'assets/anyway.png'; - const useStyles = makeStyles({ userSection: { display: 'flex', @@ -33,10 +32,9 @@ const Header: FC = () => { const { t } = useTranslation(); const classes = useStyles(); const store: RootStore = useStore(); - const { userStore, settingsStore } = store; - + const { userStore,newsFlashStore,settingsStore } = store; + const [open, setOpen] = useState(false); - const isUserDetailsRequired: boolean = !userStore.userInfo?.meta.isCompleteRegistration; const roadSegmentLocation = store.gpsLocationData; @@ -57,12 +55,19 @@ const Header: FC = () => { const onStreetAndCitySearch = (street?: string, city?: string) => { // change to constant values until backend issues are fixed - console.log('city is', city); - console.log('street is', street); navigate(`${settingsStore.currentLanguageRouteString}/cityAndStreet/${street}/${city}`); setOpen(false); }; + + const DownLoadCSVNews = () =>{ + + const newsId = parseInt( window.location.href.split('/')[window.location.href.split('/').length-1]); + newsFlashStore.downloadNewsflash(newsId) + + } + + useEffect(() => { userStore.getUserLoginDetails(); }, [userStore]); @@ -94,10 +99,12 @@ const Header: FC = () => { } } + return ( + {t('header.download')} setOpen(true)}>{t('header.Search')} {FEATURE_FLAGS.language && } {authElement} diff --git a/src/components/organisms/FilterBar.tsx b/src/components/organisms/FilterBar.tsx index 894c75bd..6e8e7fe5 100644 --- a/src/components/organisms/FilterBar.tsx +++ b/src/components/organisms/FilterBar.tsx @@ -10,7 +10,7 @@ import queryString from 'query-string'; import { Typography, Button } from 'components/atoms'; import { useTranslation } from 'react-i18next'; import Collapse from '@material-ui/core/Collapse'; - +import { toJS } from 'mobx'; interface IProps {} const useStyles = makeStyles(() => @@ -43,6 +43,8 @@ const FilterBar: FC = () => { } }, [queryParam, newsFlashStore]); + console.log(toJS(newsFlashStore.newsFlashWidgetsTimerFilter)); + return (
diff --git a/src/services/news.data.service.ts b/src/services/news.data.service.ts index 317bcbab..ce19a0db 100644 --- a/src/services/news.data.service.ts +++ b/src/services/news.data.service.ts @@ -76,3 +76,21 @@ export function updateNews(newsId: number, newLocationQualification: any, .then((res) => res.data) .catch(onErrorFetchNewsFlash) } + +export const downloadNewsflashHandler = async function (street1_hebrew:string,yishuv_name:string,years_ago:number) { + + try{ + const res = await axios.get(`${NEWS_FLASH_API}/download-data`,{ + params:{ + street1_hebrew, + yishuv_name, + years_ago + } + }) + return res + } + catch(e){ + console.error(`an Error has occured while trying to download newsFlash : ${JSON.stringify(e)}`); + } + +} \ No newline at end of file diff --git a/src/services/user.service.ts b/src/services/user.service.ts index 91795e20..a535c8f4 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -140,3 +140,4 @@ export const logoutUserFromSession = async function (): Promise { } return isSessionLogOut; }; + diff --git a/src/store/news-flash-store.ts b/src/store/news-flash-store.ts index 86e0d62e..7eac1bcc 100644 --- a/src/store/news-flash-store.ts +++ b/src/store/news-flash-store.ts @@ -1,10 +1,9 @@ -import { runInAction, makeAutoObservable } from 'mobx'; +import { runInAction, makeAutoObservable,toJS } from 'mobx'; import { SourceFilterEnum } from 'models/SourceFilter'; -import { fetchNews, IFetchNewsQueryParams } from 'services/news.data.service'; +import { fetchNews, IFetchNewsQueryParams,downloadNewsflashHandler } from 'services/news.data.service'; import { INewsFlash } from 'models/NewFlash'; import { IPoint } from 'models/Point'; import RootStore from './root.store'; - const DEFAULT_TIME_FILTER = 5; const DEFAULT_LOCATION = { latitude: 32.0853, longitude: 34.7818 }; const LOCAL_FILTERS: { [key in SourceFilterEnum]?: (newsFlashCollection: Array) => Array } = {}; @@ -17,7 +16,7 @@ export default class NewsFlashStore { newsFlashActiveFilter: SourceFilterEnum = SourceFilterEnum.all; newsFlashLoading: boolean = false; newsFlashWidgetsTimerFilter = DEFAULT_TIME_FILTER; // newsflash time filter (in years ago, 5 is the default) - + constructor(rootStore: RootStore) { this.rootStore = rootStore; makeAutoObservable(this); @@ -145,4 +144,15 @@ export default class NewsFlashStore { } return location; } + downloadNewsflash(Id:number | undefined){ + + const years_ago = this.newsFlashWidgetsTimerFilter + const NewsFlash = this.newsFlashCollection.filter(news =>{ + return Id === news.id + }) + + const {yishuv_name,street1_hebrew} = NewsFlash[0] + + downloadNewsflashHandler(yishuv_name,street1_hebrew,years_ago) + } }