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

download csv newsflash #1116

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion public/locales/he/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@
"Search": "חיפוש",
"User Greeting": "שלום",
"User Info Update": "פרטי משתמש",
"management": "ניהול"
"management": "ניהול",
"download":"הורדת מידע"
},
"sideBar": "מיקום משוער:",
"changeLocationButton": "שינוי/אישור מיקום",
Expand Down
19 changes: 13 additions & 6 deletions src/components/molecules/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -33,11 +32,10 @@ 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 [zoomLevel] = useState(parseInt(process.env.REACT_APP_DEFAULT_MAP_ZOOM!));

const isUserDetailsRequired: boolean = !userStore.userInfo?.meta.isCompleteRegistration;
const roadSegmentLocation = store.gpsLocationData;

Expand All @@ -58,12 +56,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]);
Expand Down Expand Up @@ -95,10 +100,12 @@ const Header: FC = () => {
}
}


return (
<AppBar>
<Logo src={logo} alt={'Anyway'} height={30} onClick={reloadHomePage} />
<Box className={classes.userSection}>
<Button.Standard onClick={DownLoadCSVNews}>{t('header.download')}</Button.Standard>
<Button.Standard onClick={() => setOpen(true)}>{t('header.Search')}</Button.Standard>
{FEATURE_FLAGS.language && <LanguageMenu />}
{authElement}
Expand Down
4 changes: 3 additions & 1 deletion src/components/organisms/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand Down Expand Up @@ -43,6 +43,8 @@ const FilterBar: FC<IProps> = () => {
}
}, [queryParam, newsFlashStore]);

console.log(toJS(newsFlashStore.newsFlashWidgetsTimerFilter));

return (
<div className={classes.grow}>
<AppBar position="static" color="transparent" elevation={0}>
Expand Down
18 changes: 18 additions & 0 deletions src/services/news.data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}

}
1 change: 1 addition & 0 deletions src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ export const logoutUserFromSession = async function (): Promise<boolean> {
}
return isSessionLogOut;
};

18 changes: 14 additions & 4 deletions src/store/news-flash-store.ts
Original file line number Diff line number Diff line change
@@ -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<INewsFlash>) => Array<INewsFlash> } = {};
Expand All @@ -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);
Expand Down Expand Up @@ -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)
}
}
Loading