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

Only show install extension item in sidebar if user has matching browser #460

Open
wants to merge 1 commit into
base: develop
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
11 changes: 7 additions & 4 deletions frontend/src/components/SidebarLayout/const.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
export const instrumentsItems = [
{
export const browserExtensions = {
chrome: {
color: "green",
title: "Instalează-ți extensia de Chrome pentru a depista știri false",
ctaText: "Instalează extensia",
ctaLink:
"https://chrome.google.com/webstore/detail/covid-19-stiri-oficiale/pdcpkplohipjhdfdchpmgekifmcdbnha"
},
{
firefox: {
color: "green",
title: "Instalează-ți extensia de Firefox pentru a depista știri false",
ctaText: "Instalează extensia",
ctaLink:
"https://addons.mozilla.org/en-US/firefox/addon/covid-19-%C8%99tiri-oficiale/"
},
}
};

export const instrumentsItems = [
{
color: "green",
title: "Știri oficiale și informații la zi",
Expand Down
25 changes: 16 additions & 9 deletions frontend/src/components/SidebarLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ import {
InstrumentsItem,
Hero
} from "@code4ro/taskforce-fe-components";
import { instrumentsItems } from "./const";
import { browserExtensions, instrumentsItems } from "./const";

const SidebarLayout = ({ children }) => {
// Browser detection based on this answer:
// https://stackoverflow.com/a/9851769/5723188
const isChrome =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: this doesn't seem to work on Chrome mobile.
Screenshot_20200628-003042
But that should not matter as Chrome mobile doesn't support extensions yet.

The Firefox detection works on mobile, which matter the most

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the mechanism for detecting Chrome relies on detecting Chrome extension support, so if mobile doesn't have it, it won't show up.

!!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
const isFirefox = typeof InstallTrigger !== "undefined";

let installExtensionItem = null;
if (isChrome) {
installExtensionItem = <InstrumentsItem {...browserExtensions.chrome} />;
} else if (isFirefox) {
installExtensionItem = <InstrumentsItem {...browserExtensions.firefox} />;
}

return (
<div className="columns">
<div className="column is-8">{children}</div>
<aside className="column is-4">
<Instruments layout="column">
<Hero useFallbackIcon title="Instrumente utile" />
{installExtensionItem}
{instrumentsItems.map((item, index) => (
<InstrumentsItem
key={index}
color={item.color}
title={item.title}
content={item.content}
ctaText={item.ctaText}
ctaLink={item.ctaLink}
/>
<InstrumentsItem key={index} {...item} />
))}
</Instruments>
</aside>
Expand Down