Skip to content

Commit

Permalink
Merge pull request #2632 from getAlby/fix/conditional-publisher
Browse files Browse the repository at this point in the history
fix: don't render the publisher widget if there is an allowance
  • Loading branch information
bumi authored Aug 5, 2023
2 parents 047979a + 0837ba3 commit 0fb8b93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app/screens/Home/DefaultView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dayjs.extend(relativeTime);
export type Props = {
lnDataFromCurrentTab?: Battery[];
currentUrl?: URL | null;
renderPublisherWidget?: boolean;
};

const DefaultView: FC<Props> = (props) => {
Expand Down Expand Up @@ -110,7 +111,7 @@ const DefaultView: FC<Props> = (props) => {

return (
<div className="w-full max-w-screen-sm h-full mx-auto overflow-y-auto no-scrollbar">
{!!props.lnDataFromCurrentTab?.length && (
{props.renderPublisherWidget && !!props.lnDataFromCurrentTab?.length && (
<PublisherLnData lnData={props.lnDataFromCurrentTab[0]} />
)}
<div className="p-4">
Expand Down
15 changes: 11 additions & 4 deletions src/app/screens/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useState, useEffect, useCallback } from "react";
import { FC, useCallback, useEffect, useState } from "react";
import browser from "webextension-polyfill";
import api from "~/common/lib/api";
import type { Allowance, Battery } from "~/types";
Expand All @@ -11,6 +11,7 @@ const Home: FC = () => {
const [currentUrl, setCurrentUrl] = useState<URL | null>(null);
const [loadingAllowance, setLoadingAllowance] = useState(true);
const [lnData, setLnData] = useState<Battery[]>([]);
const [renderDefaultView, setRenderDefaultView] = useState(false);

const loadAllowance = useCallback(async () => {
try {
Expand Down Expand Up @@ -84,19 +85,25 @@ const Home: FC = () => {
return null;
}

if (allowance) {
if (allowance && !renderDefaultView) {
return (
<AllowanceView
allowance={allowance}
lnDataFromCurrentTab={lnData}
onGoBack={() => setAllowance(null)}
onGoBack={() => setRenderDefaultView(true)}
onEditComplete={loadAllowance}
onDeleteComplete={() => setAllowance(null)}
/>
);
}

return <DefaultView currentUrl={currentUrl} lnDataFromCurrentTab={lnData} />;
return (
<DefaultView
renderPublisherWidget={!allowance}
currentUrl={currentUrl}
lnDataFromCurrentTab={lnData}
/>
);
};

export default Home;

0 comments on commit 0fb8b93

Please sign in to comment.