Skip to content

Commit

Permalink
Support default package icon in offline scenarios (loic-sharma#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-sharma authored Jan 4, 2020
1 parent 8404130 commit 847142f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/BaGet.UI/src/DisplayPackage/DisplayPackage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SourceRepository from './SourceRepository';
import { Versions, IPackageVersion } from './Versions';

import './DisplayPackage.css';
import DefaultPackageIcon from "../default-package-icon-256x256.png";

interface IDisplayPackageProps {
match: {
Expand Down Expand Up @@ -60,8 +61,6 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
package: undefined,
};

private readonly defaultIconUrl: string = 'https://www.nuget.org/Content/gallery/img/default-package-icon-256x256.png';

private id: string;
private version?: string;

Expand Down Expand Up @@ -210,7 +209,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
<div className="row display-package">
<aside className="col-sm-1 package-icon">
<img
src={this.state.package.iconUrl}
src={this.state.package.iconUrl || DefaultPackageIcon}
className="img-responsive"
onError={this.loadDefaultIcon}
alt="The package icon" />
Expand Down Expand Up @@ -307,7 +306,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
}

private loadDefaultIcon = (e: React.SyntheticEvent<HTMLImageElement>) => {
e.currentTarget.src = this.defaultIconUrl;
e.currentTarget.src = DefaultPackageIcon;
}

private normalizeVersion(version: string): string {
Expand Down
6 changes: 3 additions & 3 deletions src/BaGet.UI/src/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Checkbox, Dropdown, IDropdownOption, SelectableOptionMenuItemType } fro
import * as React from 'react';
import { Link } from 'react-router-dom';
import './SearchResults.css';
import DefaultPackageIcon from "./default-package-icon-256x256.png";

interface ISearchResultsProps {
input: string;
Expand Down Expand Up @@ -32,7 +33,6 @@ interface ISearchResponse {

class SearchResults extends React.Component<ISearchResultsProps, ISearchResultsState> {

private readonly defaultIconUrl: string = 'https://www.nuget.org/Content/gallery/img/default-package-icon-256x256.png';
private resultsController?: AbortController;

constructor(props: ISearchResultsProps) {
Expand Down Expand Up @@ -160,7 +160,7 @@ class SearchResults extends React.Component<ISearchResultsProps, ISearchResultsS
<div key={value.id} className="row search-result">
<div className="col-sm-1 hidden-xs hidden-sm">
<img
src={value.iconUrl || this.defaultIconUrl}
src={value.iconUrl || DefaultPackageIcon}
className="package-icon img-responsive"
onError={this.loadDefaultIcon}
alt="The package icon" />
Expand Down Expand Up @@ -272,7 +272,7 @@ class SearchResults extends React.Component<ISearchResultsProps, ISearchResultsS
}

private loadDefaultIcon = (e: React.SyntheticEvent<HTMLImageElement>) => {
e.currentTarget.src = this.defaultIconUrl;
e.currentTarget.src = DefaultPackageIcon;
}

private onChangePackageType = (e: React.FormEvent<HTMLDivElement>, option?: IDropdownOption) : void => {
Expand Down
Binary file added src/BaGet.UI/src/default-package-icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 847142f

Please sign in to comment.