Fixed authorization on Add and Heart buttons
This commit is contained in:
parent
f6bc5c82a9
commit
e6289478f2
2 changed files with 69 additions and 20 deletions
|
|
@ -23,7 +23,13 @@ import { storeComponent } from "../../../types/store";
|
||||||
import cloneFLowWithParent from "../../../utils/storeUtils";
|
import cloneFLowWithParent from "../../../utils/storeUtils";
|
||||||
import { classNames } from "../../../utils/utils";
|
import { classNames } from "../../../utils/utils";
|
||||||
|
|
||||||
export const MarketCardComponent = ({ data }: { data: storeComponent }) => {
|
export const MarketCardComponent = ({
|
||||||
|
data,
|
||||||
|
authorized,
|
||||||
|
}: {
|
||||||
|
data: storeComponent;
|
||||||
|
authorized: boolean;
|
||||||
|
}) => {
|
||||||
const { savedFlows } = useContext(StoreContext);
|
const { savedFlows } = useContext(StoreContext);
|
||||||
const [added, setAdded] = useState(savedFlows.has(data.id) ? true : false);
|
const [added, setAdded] = useState(savedFlows.has(data.id) ? true : false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
@ -32,6 +38,7 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => {
|
||||||
const flowData = useRef<FlowType>();
|
const flowData = useRef<FlowType>();
|
||||||
const [liked_by_user, setLiked_by_user] = useState(data.liked_by_user);
|
const [liked_by_user, setLiked_by_user] = useState(data.liked_by_user);
|
||||||
const [likes_count, setLikes_count] = useState(data.liked_by_count ?? 0);
|
const [likes_count, setLikes_count] = useState(data.liked_by_count ?? 0);
|
||||||
|
const [hovering, setHovering] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAdded(savedFlows.has(data.id) ? true : false);
|
setAdded(savedFlows.has(data.id) ? true : false);
|
||||||
|
|
@ -116,7 +123,15 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="group relative flex flex-col justify-between overflow-hidden transition-all hover:shadow-md">
|
<Card
|
||||||
|
onMouseEnter={() => {
|
||||||
|
setHovering(true);
|
||||||
|
}}
|
||||||
|
onMouseLeave={() => {
|
||||||
|
setHovering(false);
|
||||||
|
}}
|
||||||
|
className="group relative flex flex-col justify-between overflow-hidden transition-all hover:shadow-md"
|
||||||
|
>
|
||||||
<div>
|
<div>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -172,31 +187,46 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => {
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-0.5">
|
<div className="flex gap-0.5">
|
||||||
<ShadTooltip content="Like">
|
<ShadTooltip
|
||||||
|
content={authorized ? "Like" : "Please review your API key."}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="xs"
|
size="xs"
|
||||||
className="whitespace-nowrap"
|
className={
|
||||||
|
"whitespace-nowrap" +
|
||||||
|
(!authorized ? " cursor-not-allowed" : "")
|
||||||
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleLike();
|
if (authorized) handleLike();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IconComponent
|
<IconComponent
|
||||||
name="Heart"
|
name="Heart"
|
||||||
className={classNames(
|
className={classNames(
|
||||||
"h-6 w-6 p-0.5",
|
"h-6 w-6 p-0.5",
|
||||||
liked_by_user ? "fill-destructive stroke-destructive" : ""
|
liked_by_user
|
||||||
|
? "fill-destructive stroke-destructive"
|
||||||
|
: "",
|
||||||
|
!authorized ? " text-ring" : ""
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
<ShadTooltip content="Add to Account">
|
<ShadTooltip
|
||||||
|
content={
|
||||||
|
authorized ? "Add to Account" : "Please review your API key."
|
||||||
|
}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="xs"
|
size="xs"
|
||||||
className="whitespace-nowrap"
|
className={
|
||||||
|
"whitespace-nowrap" +
|
||||||
|
(!authorized ? " cursor-not-allowed" : "")
|
||||||
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (loading) {
|
if (loading || !authorized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!added) {
|
if (!added) {
|
||||||
|
|
@ -208,9 +238,19 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => {
|
||||||
>
|
>
|
||||||
<IconComponent
|
<IconComponent
|
||||||
name={
|
name={
|
||||||
loading ? "Loader2" : added ? "GitBranchPlus" : "Plus"
|
loading
|
||||||
|
? "Loader2"
|
||||||
|
: added
|
||||||
|
? hovering
|
||||||
|
? "GitBranchPlus"
|
||||||
|
: "Check"
|
||||||
|
: "Plus"
|
||||||
}
|
}
|
||||||
className={"h-6 w-6" + (loading ? " animate-spin" : "")}
|
className={classNames(
|
||||||
|
"h-6 w-6",
|
||||||
|
loading ? " animate-spin" : "",
|
||||||
|
!authorized ? " text-ring" : ""
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
|
|
|
||||||
|
|
@ -76,14 +76,19 @@ export default function StorePage(): JSX.Element {
|
||||||
setLoadingSaved(true);
|
setLoadingSaved(true);
|
||||||
getStoreSavedComponents()
|
getStoreSavedComponents()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let savedIds = new Set<string>();
|
if (data?.authorized === false) {
|
||||||
let results = data?.results ?? [];
|
setErrorApiKey(true);
|
||||||
results.forEach((flow) => {
|
setSavedFlows(new Set<string>());
|
||||||
savedIds.add(flow.id);
|
} else {
|
||||||
});
|
let savedIds = new Set<string>();
|
||||||
setSavedFlows(savedIds);
|
let results = data?.results ?? [];
|
||||||
setErrorApiKey(false);
|
results.forEach((flow) => {
|
||||||
setLoadingSaved(false);
|
savedIds.add(flow.id);
|
||||||
|
});
|
||||||
|
setSavedFlows(savedIds);
|
||||||
|
setErrorApiKey(false);
|
||||||
|
setLoadingSaved(false);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setSavedFlows(new Set<string>());
|
setSavedFlows(new Set<string>());
|
||||||
|
|
@ -291,7 +296,11 @@ export default function StorePage(): JSX.Element {
|
||||||
searchData.map((item, idx) => {
|
searchData.map((item, idx) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<MarketCardComponent key={idx} data={item} />
|
<MarketCardComponent
|
||||||
|
key={idx}
|
||||||
|
data={item}
|
||||||
|
authorized={!loadingSaved}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue