From c20b8c6811e2757939cbf9fca2aa814a67838ee8 Mon Sep 17 00:00:00 2001 From: Caleb Jacob Date: Tue, 2 Apr 2024 16:49:39 -0600 Subject: [PATCH 1/6] Implement pinned apps, implement emitGatewayEvent --- src/ComponentDetailsPage.jsx | 3 +- src/ComponentSummary.jsx | 109 ++++++++++++++++++++++++++------ src/GatewayWrapper.jsx | 5 +- src/ProfilePage.jsx | 33 ++++++++++ src/SocialIndexActionButton.jsx | 15 +++-- 5 files changed, 140 insertions(+), 25 deletions(-) diff --git a/src/ComponentDetailsPage.jsx b/src/ComponentDetailsPage.jsx index 2c506fb7..35326a5f 100644 --- a/src/ComponentDetailsPage.jsx +++ b/src/ComponentDetailsPage.jsx @@ -1,4 +1,4 @@ -let { src, tab, highlightComment } = props; +let { emitGatewayEvent, src, tab, highlightComment } = props; const [selectedTab, setSelectedTab] = useState(props.tab ?? "source"); @@ -126,6 +126,7 @@ return (
@@ -260,6 +279,7 @@ return ( - Copy URL to clipboard}> - - + { + emitPinnedAppsGatewayEvent(pinIsActive); + }, + onCommitFailure: (pinIsActive) => { + emitPinnedAppsGatewayEvent(pinIsActive); + }, + button: (pinCount, pinIsActive, pinOnClick) => ( + + {pinIsActive ? ( + <> + {" "} + Pinned + + ) : ( + <> + + Pin + + )} + + ), + }} + /> + ), + }} + /> + + { + State.update({ copiedShareUrl: false }); + }} + onClick={() => { + clipboard.writeText(shareUrl).then(() => { + State.update({ copiedShareUrl: true }); + }); + }} + > + {state.copiedShareUrl ? ( + + ) : ( + + )} + Share + + ), + }} + /> ); diff --git a/src/GatewayWrapper.jsx b/src/GatewayWrapper.jsx index 172f753c..acf64e2e 100644 --- a/src/GatewayWrapper.jsx +++ b/src/GatewayWrapper.jsx @@ -1,4 +1,4 @@ -let { targetComponent, targetProps, logOut, termsDomainName, privacyDomainName, recordToC } = props; +let { emitGatewayEvent, targetComponent, targetProps, logOut, termsDomainName, privacyDomainName, recordToC } = props; const tosName = props.tosName ?? "${REPL_ACCOUNT}/widget/TosContent"; @@ -8,6 +8,7 @@ return ( key="wrapper-tos-check" src="${REPL_ACCOUNT}/widget/TosCheck" props={{ + emitGatewayEvent, logOut, termsDomainName, privacyDomainName, @@ -16,6 +17,6 @@ return ( }} /> - + ); diff --git a/src/ProfilePage.jsx b/src/ProfilePage.jsx index dd537a84..eed4231a 100644 --- a/src/ProfilePage.jsx +++ b/src/ProfilePage.jsx @@ -34,6 +34,24 @@ if (starredComponentsData) { } const starredComponentsCount = (starredComponents ?? []).length; +const pinnedComponentsData = Social.keys(`${accountId}/graph/pin/*/widget/*`, "final", { + return_type: "BlockHeight", +}); +let pinnedComponents = null; +if (pinnedComponentsData) { + pinnedComponents = []; + const pinnedData = pinnedComponentsData[accountId]?.graph?.pin ?? {}; + Object.keys(pinnedData).forEach((authorAccountId) => { + Object.keys(pinnedData[authorAccountId].widget).forEach((componentName) => { + pinnedComponents.push({ + accountId: authorAccountId, + componentName, + }); + }); + }); +} +const pinnedComponentsCount = (pinnedComponents ?? []).length; + const Wrapper = styled.div``; const Main = styled.div` @@ -216,6 +234,10 @@ return ( Stars ({starredComponentsCount}) + + Pins ({pinnedComponentsCount}) + + NFTs @@ -287,6 +309,17 @@ return ( /> )} + {state.selectedTab === "pins" && ( + + )} + {state.selectedTab === "blog" && ( { return; } - setIsActive((currentIsActive) => !currentIsActive); // Optimistically update + const existingIsActive = isActive; + const newIsActive = !isActive; + onCommitStart && onCommitStart(newIsActive); // Optimistically update + setIsActive(() => newIsActive); // Optimistically update setIsProcessingAction(true); // The following logic for generating the "data" object was copied from here: @@ -78,9 +81,13 @@ const onClick = () => { } Social.set(data, { - onCommit: () => setIsProcessingAction(false), + onCommit: () => { + setIsProcessingAction(false); + onCommitSuccess && onCommitSuccess(newIsActive); + }, onCancel: () => { - setIsActive((currentIsActive) => !currentIsActive); // Undo optimistic update + setIsActive(existingIsActive); // Undo optimistic update + onCommitFailure && onCommitFailure(existingIsActive); // Undo optimistic update setIsProcessingAction(false); }, }); From 17a93502d721c005ab6d747f1959fb51cb0a2a79 Mon Sep 17 00:00:00 2001 From: Caleb Jacob Date: Thu, 4 Apr 2024 09:17:14 -0600 Subject: [PATCH 2/6] Add tooltips for star and pin actions when user is not signed in yet --- src/ComponentSummary.jsx | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/ComponentSummary.jsx b/src/ComponentSummary.jsx index bacdb836..bbc0d143 100644 --- a/src/ComponentSummary.jsx +++ b/src/ComponentSummary.jsx @@ -289,14 +289,26 @@ return ( }, notifyAccountId: accountId, button: (starCount, starIsActive, starOnClick) => ( - + + {starIsActive ? ( + + ) : ( + + )}{" "} + {starCount} + + ), + }} + /> ), }} /> @@ -322,7 +334,11 @@ return ( {pinIsActive ? ( From c0d45b64d640d46c3bcbc6b131b65725a2f2f00c Mon Sep 17 00:00:00 2001 From: Caleb Jacob Date: Thu, 4 Apr 2024 10:05:53 -0600 Subject: [PATCH 3/6] Rely on gateway events to determine if pinned apps feature is enabled --- src/ComponentSummary.jsx | 106 ++++++++++++++++++++++----------------- src/ProfilePage.jsx | 18 +++++-- 2 files changed, 74 insertions(+), 50 deletions(-) diff --git a/src/ComponentSummary.jsx b/src/ComponentSummary.jsx index bbc0d143..50afacd5 100644 --- a/src/ComponentSummary.jsx +++ b/src/ComponentSummary.jsx @@ -215,10 +215,20 @@ function emitPinnedAppsGatewayEvent(isPinned) { emitGatewayEvent({ type: "PINNED_APPS", app, - modification: isPinned ? "PINNED" : "UNPINNED", + action: isPinned ? "PINNED" : "UNPINNED", }); } +function pinnedAppsFeatureEnabled() { + if (emitGatewayEvent) { + return emitGatewayEvent({ + type: "PINNED_APPS", + action: "FEATURE_ENABLED", + }); + } + return false; +} + return (
@@ -313,52 +323,54 @@ return ( }} /> - { - emitPinnedAppsGatewayEvent(pinIsActive); - }, - onCommitFailure: (pinIsActive) => { - emitPinnedAppsGatewayEvent(pinIsActive); - }, - button: (pinCount, pinIsActive, pinOnClick) => ( - - {pinIsActive ? ( - <> - {" "} - Pinned - - ) : ( - <> - - Pin - - )} - - ), - }} - /> - ), - }} - /> + {pinnedAppsFeatureEnabled() && ( + { + emitPinnedAppsGatewayEvent(pinIsActive); + }, + onCommitFailure: (pinIsActive) => { + emitPinnedAppsGatewayEvent(pinIsActive); + }, + button: (pinCount, pinIsActive, pinOnClick) => ( + + {pinIsActive ? ( + <> + {" "} + Pinned + + ) : ( + <> + + Pin + + )} + + ), + }} + /> + ), + }} + /> + )} - - Pins ({pinnedComponentsCount}) - + {pinnedAppsFeatureEnabled() && ( + + Pins ({pinnedComponentsCount}) + + )} NFTs From fc70ce3179055b3c5a8828e5a312d25cb789fd07 Mon Sep 17 00:00:00 2001 From: Caleb Jacob Date: Thu, 4 Apr 2024 10:16:47 -0600 Subject: [PATCH 4/6] Pull in emitGatewayEvent prop for ProfilePage --- src/ProfilePage.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ProfilePage.jsx b/src/ProfilePage.jsx index 1f0e5e00..a8c5d016 100644 --- a/src/ProfilePage.jsx +++ b/src/ProfilePage.jsx @@ -1,3 +1,5 @@ +let { emitGatewayEvent } = props; + const accountId = props.accountId ?? context.accountId; if (!accountId) { return "No account ID"; From 192700a9c90d9d0bc033a6e38b0bad9ff2b256d7 Mon Sep 17 00:00:00 2001 From: Caleb Jacob Date: Fri, 5 Apr 2024 10:25:59 -0600 Subject: [PATCH 5/6] Swap out hardcoded near account ID for ${REPL_ACCOUNT} --- src/AI/Agent/AgentCard.jsx | 14 +++++++------- src/AI/Agent/AgentChat.jsx | 12 ++++++------ src/AI/Agent/AgentDetails.jsx | 2 +- src/AI/Agent/AgentSummary.jsx | 8 ++++---- src/ActivityFeeds/PostsFeedControls.jsx | 2 +- src/ComponentSummary.jsx | 6 +++--- src/Moderation/ModerationButton.jsx | 4 ++-- src/Moderation/Moderator.jsx | 4 ++-- src/Moderation/NeedsModeration.jsx | 8 ++++---- src/Moderation/ReasonDialog.jsx | 2 +- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/AI/Agent/AgentCard.jsx b/src/AI/Agent/AgentCard.jsx index 6714d937..de9397be 100644 --- a/src/AI/Agent/AgentCard.jsx +++ b/src/AI/Agent/AgentCard.jsx @@ -92,7 +92,7 @@ const AgentCard = ({ item, editFunction }) => {

{displayName}

by {accountId}

{prompt}, trigger:

{prompt ? prompt.substring(0, 20) : ""}...

, @@ -103,12 +103,12 @@ const AgentCard = ({ item, editFunction }) => { editFunction(item), iconLeft: editIcon, @@ -134,13 +134,13 @@ const AgentCard = ({ item, editFunction }) => { }} /> { }} /> { { {model === "local" && ( {
{
{ {false && accountId === context.accountId && ( {" "} 0 && ( ( ( { const renderButton = () => ( <> ( if (props.tooltip) { return ( {props.tooltip}, trigger: renderButton(), diff --git a/src/Moderation/Moderator.jsx b/src/Moderation/Moderator.jsx index 28118c92..f2912d06 100644 --- a/src/Moderation/Moderator.jsx +++ b/src/Moderation/Moderator.jsx @@ -112,7 +112,7 @@ function needsModeration() {

Needs Moderation

Previously Moderated

{
{overviewTooltip}, trigger: pathToType(item.moderated_path), @@ -250,7 +250,7 @@ const renderItem = (item) => {
{item.most_frequent_label} by 0 ? "users" : "user"}`, @@ -259,7 +259,7 @@ const renderItem = (item) => {
{ return (
Date: Fri, 5 Apr 2024 10:33:28 -0600 Subject: [PATCH 6/6] Use simpler IPFS image url for pinned apps --- src/ComponentSummary.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ComponentSummary.jsx b/src/ComponentSummary.jsx index 6e45976e..c545fdf0 100644 --- a/src/ComponentSummary.jsx +++ b/src/ComponentSummary.jsx @@ -206,9 +206,7 @@ function emitPinnedAppsGatewayEvent(isPinned) { authorAccountId: accountId, displayName: metadata.name || widgetName, componentName: widgetName, - imageUrl: metadata.image?.ipfs_cid - ? `https://i.near.social/large/https://ipfs.near.social/ipfs/${metadata.image.ipfs_cid}` - : null, + imageUrl: metadata.image?.ipfs_cid ? `https://ipfs.near.social/ipfs/${metadata.image.ipfs_cid}` : null, }; emitGatewayEvent &&