Skip to content

Commit

Permalink
[DDW-907] Add internal link support in newsfeed items (input-output-h…
Browse files Browse the repository at this point in the history
…k#1617)

* [DDW-907] Introduce internal link support for newsfeed items and verification hash generator

* [DDW-907] Hash generator path improvement

* [DDW-907] Re-add news JSON files and ignore prettier on newsfeed-files folder

* [DDW-907] newsfeed_testnet.json file improvement

* [DDW-907] Newsfeed development JSON file with in-app events and routes

* [DDW-907] JSON files small improvement

* [DDW-907] Refactor verification hash generator to use local files instead GH request

* [DDW-907] Better error handler in verification hash generator

* [DDW-907] CHANGELOG update

* [DDW-907] FAKED Newsfeed JSON loading

* [DDW-907] Requested improvements

* [DDW-907] Reverted newsfeed JSON file fetching and local JSON file fetching helper introduced

* [DDW-907] Fetch newsfeed from local JSON files logic improvement

* [DDW-907] Add local newsfeed fetching instructions as README

* [DDW-907] Merge latest develop and fix conflicts
  • Loading branch information
Tomislav Horaček authored and nikolaglumac committed Oct 31, 2019
1 parent 4edcd8f commit b749f39
Show file tree
Hide file tree
Showing 23 changed files with 934 additions and 98 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

# Ignore the following special folders and files
source/renderer/app/i18n/locales/
source/renderer/app/config/newsfeed-files/
tests/paper-wallets/e2e/documents/*
tests/wallets/e2e/documents/*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog

### Features

- Add internal link support in newsfeed items and verification hash generator script ([PR 1617](https://github.com/input-output-hk/daedalus/pull/1617))
- Implemented date, time and number format user options ([PR 1611](https://github.com/input-output-hk/daedalus/pull/1611))

### Chores
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"themes:update": "gulp build:themes && node -r esm ./dist/scripts/update.js && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.js",
"clear:cache": "gulp clear:cache",
"nix:dev": "nix-shell --arg autoStartBackend true --arg allowFaultInjection true --arg systemStart",
"nix:staging": "nix-shell --arg autoStartBackend true --argstr cluster staging"
"nix:staging": "nix-shell --arg autoStartBackend true --argstr cluster staging",
"create-news-verification-hashes": "node utils/create-news-verification-hashes/index.js"
},
"bin": {
"electron": "./node_modules/.bin/electron"
Expand Down
1 change: 1 addition & 0 deletions source/renderer/app/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class AppActions {
initAppEnvironment: Action<any> = new Action();
setNotificationVisibility: Action<boolean> = new Action();
toggleNewsFeed: Action<boolean> = new Action();
closeNewsFeed: Action<any> = new Action();

// About dialog actions
closeAboutDialog: Action<any> = new Action();
Expand Down
8 changes: 8 additions & 0 deletions source/renderer/app/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@ export default class AdaApi {
return news;
};
// For "Testing" purposes - get newsfeed from local JSON files
getNewsFromLocalFiles = async (env?: string): Promise<GetNewsResponse> => {
const fileName = `newsfeed_${env || 'development'}`;
Logger.info('AdaApi::getNewsFromLocalFiles', `${fileName}.json`);
const news = require(`../config/newsfeed-files/${fileName}.json`);
return news;
};

setCardanoNodeFault = async (fault: FaultInjectionIpcRequest) => {
await cardanoFaultInjectionChannel.send(fault);
};
Expand Down
18 changes: 10 additions & 8 deletions source/renderer/app/components/news/AlertsOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
onCloseOpenAlert: Function,
onMarkNewsAsRead: Function,
onOpenExternalLink: Function,
onProceedNewsAction: Function,
allAlertsCount: number,
hideCounter?: boolean,
currentDateFormat: string,
Expand Down Expand Up @@ -53,15 +54,17 @@ export default class AlertsOverlay extends Component<Props, State> {
this.props.onMarkNewsAsRead(alerts[0].date);
};

onProceedNewsAction = (event: SyntheticMouseEvent<HTMLElement>) => {
const { onProceedNewsAction, alerts } = this.props;
onProceedNewsAction(alerts[0], event);
};

renderAction = (action: Object) => {
if (action && action.url) {
if (action && (action.url || action.event)) {
return (
<button
className={styles.actionBtn}
onClick={() => this.props.onOpenExternalLink(action.url)}
>
<button className={styles.actionBtn} onClick={this.onProceedNewsAction}>
{action.label}
<SVGInline svg={externalLinkIcon} />
{action.url && <SVGInline svg={externalLinkIcon} />}
</button>
);
}
Expand All @@ -83,8 +86,7 @@ export default class AlertsOverlay extends Component<Props, State> {
render() {
const { showOverlay } = this.state;
const { alerts, currentDateFormat } = this.props;
const [alert] = alerts;
const { content, date, action, title } = alert;
const { content, date, action, title } = alerts[0];
return (
showOverlay && (
<div className={styles.component}>
Expand Down
15 changes: 9 additions & 6 deletions source/renderer/app/components/news/IncidentOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import styles from './IncidentOverlay.scss';
type Props = {
incident: News.News,
onOpenExternalLink: Function,
onProceedNewsAction: Function,
currentDateFormat: string,
};

Expand All @@ -25,15 +26,17 @@ export default class IncidentOverlay extends Component<Props> {
}
}

onProceedNewsAction = (event: SyntheticMouseEvent<HTMLElement>) => {
const { incident, onProceedNewsAction } = this.props;
onProceedNewsAction(incident, event);
};

renderAction = (action: Object) => {
if (action && action.url) {
if (action && (action.url || action.event)) {
return (
<button
className={styles.actionBtn}
onClick={() => this.props.onOpenExternalLink(action.url)}
>
<button className={styles.actionBtn} onClick={this.onProceedNewsAction}>
{action.label}
<SVGInline svg={externalLinkIcon} />
{action.url && <SVGInline svg={externalLinkIcon} />}
</button>
);
}
Expand Down
12 changes: 6 additions & 6 deletions source/renderer/app/components/news/NewsFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type Props = {
onMarkNewsAsRead: Function,
openWithoutTransition?: boolean,
isLoadingNews: boolean,
onOpenExternalLink: Function,
onGoToRoute: Function,
currentDateFormat: string,
onOpenExternalLink: Function,
onProceedNewsAction: Function,
};

type State = {
Expand Down Expand Up @@ -105,9 +105,9 @@ export default class NewsFeed extends Component<Props, State> {
onClose,
onOpenAlert,
onMarkNewsAsRead,
onOpenExternalLink,
openWithoutTransition,
onGoToRoute,
onProceedNewsAction,
onOpenExternalLink,
currentDateFormat,
} = this.props;
const { hasShadow } = this.state;
Expand Down Expand Up @@ -149,9 +149,9 @@ export default class NewsFeed extends Component<Props, State> {
newsItem={newsItem}
isNewsFeedOpen={isNewsFeedOpen}
onMarkNewsAsRead={onMarkNewsAsRead}
onOpenExternalLink={onOpenExternalLink}
onOpenAlert={onOpenAlert}
onGoToRoute={onGoToRoute}
onProceedNewsAction={onProceedNewsAction}
onOpenExternalLink={onOpenExternalLink}
currentDateFormat={currentDateFormat}
/>
))}
Expand Down
24 changes: 8 additions & 16 deletions source/renderer/app/components/news/NewsItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import styles from './NewsItem.scss';
type Props = {
newsItem: News.News,
onMarkNewsAsRead: Function,
onOpenExternalLink: Function,
onOpenAlert?: Function,
onGoToRoute: Function,
onOpenExternalLink: Function,
onProceedNewsAction: Function,
expandWithoutTransition?: boolean,
isNewsFeedOpen: boolean,
currentDateFormat: string,
Expand Down Expand Up @@ -74,17 +74,9 @@ export default class NewsItem extends Component<Props, State> {
}
}

newsItemButtonClickHandler(event: SyntheticMouseEvent<HTMLElement>) {
event.preventDefault();
event.stopPropagation();
const { onOpenExternalLink, newsItem, onGoToRoute } = this.props;
const { url, route } = newsItem.action;

if (url) {
onOpenExternalLink(url, event);
} else if (route) {
onGoToRoute(route);
}
onProceedNewsAction(event: SyntheticMouseEvent<HTMLElement>) {
const { newsItem, onProceedNewsAction } = this.props;
onProceedNewsAction(newsItem, event);
}

generateTitleWithBadge = (title: string, isRead: boolean) => {
Expand Down Expand Up @@ -116,7 +108,7 @@ export default class NewsItem extends Component<Props, State> {
this.state.newsItemExpanded ? styles.expanded : null,
newsItem.read ? styles.isRead : null,
]);
const { route } = newsItem.action;
const { url } = newsItem.action;
const title = this.generateTitleWithBadge(newsItem.title, newsItem.read);

return (
Expand Down Expand Up @@ -152,10 +144,10 @@ export default class NewsItem extends Component<Props, State> {
</div>
<button
className={styles.newsItemActionBtn}
onClick={this.newsItemButtonClickHandler.bind(this)}
onClick={this.onProceedNewsAction.bind(this)}
>
{newsItem.action.label}
{!route && <SVGInline svg={externalLinkIcon} />}
{url && <SVGInline svg={externalLinkIcon} />}
</button>
</AnimateHeight>
</div>
Expand Down
Loading

0 comments on commit b749f39

Please sign in to comment.