-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #784 from near/jh/edit-promote-button
- Loading branch information
Showing
2 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
const item = props.item; | ||
|
||
if (!item) { | ||
return ""; | ||
} | ||
|
||
// ------- Resposts is work in progress --------- | ||
|
||
// const reposts = Social.index("repost", item); | ||
// console.log("reposts", reposts); | ||
|
||
// const dataLoading = reposts === null; | ||
|
||
// const repostsByUsers = Object.fromEntries( | ||
// (reposts || []).filter((repost) => repost.value.type === "repost").map((repost) => [repost.accountId, repost]), | ||
// ); | ||
|
||
// console.log("repostsByUsers", repostsByUsers); | ||
|
||
// if (state.hasRepost === true) { | ||
// repostsByUsers[context.accountId] = { | ||
// accountId: context.accountId, | ||
// }; | ||
// } | ||
|
||
// const accountsWithReposts = Object.keys(repostsByUsers); | ||
// const hasRepost = context.accountId && !!repostsByUsers[context.accountId]; | ||
|
||
// const repostClick = () => { | ||
// if (state.loading) { | ||
// return; | ||
// } | ||
// State.update({ | ||
// loading: true, | ||
// }); | ||
// const reposts = [ | ||
// { | ||
// key: "main", | ||
// value: { | ||
// type: "repost", | ||
// item, | ||
// }, | ||
// }, | ||
// ]; | ||
// if (!hasRepost) { | ||
// reposts.push({ | ||
// key: item, | ||
// value: { | ||
// type: "repost", | ||
// }, | ||
// }); | ||
// } | ||
// const data = { | ||
// index: { | ||
// repost: JSON.stringify(reposts), | ||
// }, | ||
// }; | ||
|
||
// if (!hasRepost && props.notifyAccountId) { | ||
// data.index.notify = JSON.stringify({ | ||
// key: props.notifyAccountId, | ||
// value: { | ||
// type: "repost", | ||
// item, | ||
// }, | ||
// }); | ||
// } | ||
// Social.set(data, { | ||
// onCommit: () => State.update({ loading: false, hasRepost: true }), | ||
// onCancel: () => State.update({ loading: false }), | ||
// }); | ||
// }; | ||
|
||
const Button = styled.button` | ||
border: 0; | ||
display: inline-flex; | ||
align-items: center; | ||
gap: 6px; | ||
color: #687076; | ||
font-weight: 400; | ||
font-size: 14px; | ||
line-height: 17px; | ||
cursor: pointer; | ||
background: none; | ||
padding: 6px; | ||
transition: color 200ms; | ||
i { | ||
font-size: 18px; | ||
transition: color 200ms; | ||
} | ||
&:hover, | ||
&:focus { | ||
outline: none; | ||
color: #11181c; | ||
} | ||
`; | ||
|
||
const promoteToBlog = () => { | ||
if (state.loading) { | ||
return; | ||
} | ||
|
||
if (!context.accountId && props.requestAuthentication) { | ||
props.requestAuthentication(); | ||
return; | ||
} else if (!context.accountId) { | ||
return; | ||
} | ||
|
||
State.update({ | ||
loading: true, | ||
}); | ||
|
||
const data = { | ||
index: { | ||
promote: JSON.stringify({ | ||
key: context.accountId, | ||
value: { | ||
operation: "add", | ||
type: "blog", | ||
post: item, | ||
blockHeight, | ||
}, | ||
}), | ||
}, | ||
}; | ||
|
||
Social.set(data, { | ||
onCommit: () => State.update({ loading: false }), | ||
onCancel: () => | ||
State.update({ | ||
loading: false, | ||
}), | ||
}); | ||
}; | ||
|
||
const buildMenu = (accountId, blockHeight) => { | ||
// Hiding repost until dataplatform indexers are ready | ||
const menu = [ | ||
// { | ||
// name: "Activity Feed", | ||
// disabled: !context.accountId, | ||
// onSelect: () => repostClick(), | ||
// }, | ||
]; | ||
|
||
if (item.path && item?.path?.includes("post/main")) { | ||
menu.unshift({ | ||
name: "My Blog", | ||
disabled: !context.accountId, | ||
onSelect: () => promoteToBlog(accountId, blockHeight), | ||
}); | ||
} | ||
|
||
return menu; | ||
}; | ||
|
||
return ( | ||
<> | ||
<OverlayTrigger placement="top" overlay={<Tooltip>{!state.hasRepost ? "Repost" : "You've reposted"}</Tooltip>}> | ||
<Widget | ||
src="${REPL_ACCOUNT}/widget/DIG.DropdownMenu" | ||
props={{ | ||
trigger: !state.hasRepost ? <i className="bi bi-repeat" /> : <i className="bi bi-check2" />, | ||
items: buildMenu(accountId, blockHeight), | ||
}} | ||
/> | ||
<Button type="button" title="Repost" aria-label="Repost" onClick={repostClick}> | ||
{!state.hasRepost ? <i className="bi bi-repeat" /> : <i className="bi bi-check2" />} | ||
</Button> | ||
</OverlayTrigger> | ||
</> | ||
); |