Skip to content
Open
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
43 changes: 16 additions & 27 deletions apps/cyberstorm-remix/app/p/packageListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ export default function PackageListing() {

const listingAndTeamPromise = useMemo(() => Promise.all([listing, team]), []);

const packageLikeAction = PackageLikeAction({
isLoggedIn: Boolean(currentUser?.username),
dataUpdateTrigger: fetchAndSetRatedPackages,
config: config,
});

return (
<>
<Suspense>
Expand Down Expand Up @@ -434,8 +440,7 @@ export default function PackageListing() {
listing={resolvedValue[0]}
isLiked={isLiked}
currentUser={currentUser}
likeUpdateTrigger={fetchAndSetRatedPackages}
requestConfig={config}
packageLikeAction={packageLikeAction}
/>
)}
</Await>
Expand Down Expand Up @@ -598,8 +603,7 @@ export default function PackageListing() {
listing={resolvedValue[0]}
isLiked={isLiked}
currentUser={currentUser}
likeUpdateTrigger={fetchAndSetRatedPackages}
requestConfig={config}
packageLikeAction={packageLikeAction}
/>
)}
</Await>
Expand Down Expand Up @@ -953,34 +957,19 @@ function managementTools(
);
}

function likeAction(
currentUser: CurrentUser | undefined,
updateTrigger: () => Promise<void>,
requestConfig: () => RequestConfig
) {
return PackageLikeAction({
isLoggedIn: Boolean(currentUser?.username),
dataUpdateTrigger: updateTrigger,
config: requestConfig,
});
}

const Actions = memo(function Actions(props: {
team: Awaited<ReturnType<DapperTsInterface["getTeamDetails"]>>;
listing: Awaited<ReturnType<DapperTsInterface["getPackageListingDetails"]>>;
isLiked: boolean;
currentUser: CurrentUser | undefined;
likeUpdateTrigger: () => Promise<void>;
requestConfig: () => RequestConfig;
packageLikeAction: (
isLiked: boolean,
namespace: string,
packageName: string,
isLoggedIn: boolean
) => void;
}) {
const {
team,
listing,
isLiked,
currentUser,
likeUpdateTrigger,
requestConfig,
} = props;
const { team, listing, isLiked, currentUser, packageLikeAction } = props;
return (
<>
<NewButton
Expand Down Expand Up @@ -1010,7 +999,7 @@ const Actions = memo(function Actions(props: {
<NewButton
primitiveType="button"
onClick={() =>
likeAction(currentUser, likeUpdateTrigger, requestConfig)(
packageLikeAction(
isLiked,
listing.namespace,
listing.name,
Expand Down
Loading