diff --git a/apps/builddao/widget/Bookmarks.jsx b/apps/builddao/widget/Bookmarks.jsx
deleted file mode 100644
index 04a0ff56..00000000
--- a/apps/builddao/widget/Bookmarks.jsx
+++ /dev/null
@@ -1,70 +0,0 @@
-const { Post } = VM.require("buildhub.near/widget/components") || (() => <>>);
-
-const accountId = props.accountId ?? context.accountId;
-
-const bookmarks = Social.getr(`${accountId}/graph/bookmark`, "final", {
- withBlockHeight: true,
-});
-
-const StorageKey = "order";
-const order = Storage.privateGet(StorageKey);
-const apps = useMemo(() => {
- if (bookmarks === null || order === null) {
- return [];
- }
- const starredApps = new Map();
- const path = [];
-
- const buildSrc = (node) => {
- if (node.hasOwnProperty("")) {
- starredApps.set(path.join("/"), node[":block"]);
- }
- Object.entries(node).forEach(([key, value]) => {
- if (typeof value === "object") {
- path.push(key);
- buildSrc(value);
- path.pop();
- }
- });
- };
-
- buildSrc(bookmarks ?? {}, [], starredApps);
- let apps = [...starredApps.entries()];
- apps.sort((a, b) => b[1] - a[1]);
- apps = apps.map((a) => a[0]);
- apps.sort((a, b) => (order?.[a] || 0) - (order?.[b] || 0));
- Storage.privateSet(
- StorageKey,
- Object.fromEntries(apps.map((a, i) => [a, i + 1]))
- );
- return apps;
-}, [bookmarks, order]);
-
-let transformedArray = apps.map((item) => {
- let splitParts = item.split("/");
- let accountId = splitParts[0];
- let lastPart = splitParts[splitParts.length - 1];
- let blockHeight = isNaN(lastPart) ? null : parseInt(lastPart);
-
- return { accountId, blockHeight };
-});
-
-let filteredArray = transformedArray.filter(
- (item) => item.blockHeight !== null
-);
-
-return (
- <>
- {(filteredArray ?? []).map((item) => (
-
No Bookmarks Yet!
- )} - > -); diff --git a/apps/builddao/widget/Compose.jsx b/apps/builddao/widget/Compose.jsx index 306fa0e4..6cf5406d 100644 --- a/apps/builddao/widget/Compose.jsx +++ b/apps/builddao/widget/Compose.jsx @@ -3,27 +3,17 @@ const { Avatar, Button } = VM.require("buildhub.near/widget/components") || { Button: () => <>>, }; -const draftKey = props.feed.name || "draft"; +const draftKey = props.draftKey || "draft"; const draft = Storage.privateGet(draftKey); -const autocompleteEnabled = true; - if (draft === null) { return ""; } -State.init({ - image: {}, -}); - const [view, setView] = useState("editor"); const [postContent, setPostContent] = useState(""); const [hideAdvanced, setHideAdvanced] = useState(true); const [labels, setLabels] = useState([]); -const [showAccountAutocomplete, setShowAccountAutocomplete] = useState(false); -const [mentionsArray, setMentionsArray] = useState([]); -const [mentionInput, setMentionInput] = useState(null); -const [handler, setHandler] = useState("update"); setPostContent(draft || props.template); @@ -33,6 +23,16 @@ function generateUID() { return randomNumber.toString(16).padStart(8, "0"); } +function tagsFromLabels(labels) { + return labels.reduce( + (newLabels, label) => ({ + ...newLabels, + [label]: "", + }), + {} + ); +} + const extractMentions = (text) => { const mentionRegex = /@((?:(?:[a-z\d]+[-_])*[a-z\d]+\.)*(?:[a-z\d]+[-_])*[a-z\d]+)/gi; @@ -86,28 +86,19 @@ function checkAndAppendHashtag(input, target) { } const postToCustomFeed = ({ feed, text, labels }) => { - const postId = generateUID(); - if (!labels) labels = []; + // if (!labels) labels = []; - labels = labels.map((label) => label.toLowerCase()); - labels.push(feed.name.toLowerCase()); + // labels = labels.map((label) => label.toLowerCase()); + // labels.push(feed.name.toLowerCase()); - const requiredHashtags = ["build"]; + const requiredHashtags = props.requiredHashtags || ["build"]; if (feed.hashtag) requiredHashtags.push(feed.hashtag.toLowerCase()); requiredHashtags.push(feed.name.toLowerCase()); - text = text + `\n\n`; - requiredHashtags.forEach((hashtag) => { text = checkAndAppendHashtag(text, hashtag); }); - const content = { - type: "md", - image: state.image.cid ? { ipfs_cid: state.image.cid } : undefined, - text: text, - }; - const data = { // [feed.name]: { // [postId]: { @@ -123,7 +114,12 @@ const postToCustomFeed = ({ feed, text, labels }) => { // }, // }, post: { - main: JSON.stringify(content), + main: JSON.stringify({ + type: "md", + text, + // tags: tagsFromLabels(labels), + // postType: feed.name, + }), }, index: { post: JSON.stringify({ key: "main", value: { type: "md" } }), @@ -168,98 +164,16 @@ const postToCustomFeed = ({ feed, text, labels }) => { }); }; -function textareaInputHandler(value) { - const words = value.split(/\s+/); - const allMentiones = words - .filter((word) => word.startsWith("@")) - .map((mention) => mention.slice(1)); - const newMentiones = allMentiones.filter( - (item) => !mentionsArray.includes(item) - ); - setMentionInput(newMentiones?.[0] ?? ""); - setMentionsArray(allMentiones); - setShowAccountAutocomplete(newMentiones?.length > 0); - setPostContent(value); - setHandler("update"); - Storage.privateSet(draftKey, value || ""); -} - -function autoCompleteAccountId(id) { - let currentIndex = 0; - const updatedDescription = postContent.replace( - /(?:^|\s)(@[^\s]*)/g, - (match) => { - if (currentIndex === mentionsArray.indexOf(mentionInput)) { - currentIndex++; - return ` @${id}`; - } else { - currentIndex++; - return match; - } - } - ); - setPostContent(updatedDescription); - setShowAccountAutocomplete(false); - setMentionInput(null); - setHandler("autocompleteSelected"); - Storage.privateSet(draftKey, updatedDescription || ""); -} - const PostCreator = styled.div` display: flex; flex-direction: column; gap: 1.5rem; padding: 1rem; - background: #23242b; + background: var(--compose-bg, #23242b); border-radius: 12px; margin-bottom: 1rem; - - .upload-image-button { - display: flex; - align-items: center; - justify-content: center; - background: #f1f3f5; - color: #11181c; - border-radius: 40px; - height: 40px; - min-width: 40px; - font-size: 0; - border: none; - cursor: pointer; - transition: background 200ms, opacity 200ms; - - &::before { - font-size: 16px; - } - - &:hover, - &:focus { - background: #d7dbde; - outline: none; - } - - &:disabled { - opacity: 0.5; - pointer-events: none; - } - - span { - margin-left: 12px; - } - } - - .d-inline-block { - display: flex !important; - gap: 12px; - margin: 0 !important; - - .overflow-hidden { - width: 40px !important; - height: 40px !important; - } - } `; const TextareaWrapper = styled.div` @@ -458,36 +372,6 @@ const MarkdownPreview = styled.div` } `; -const LabelSelect = styled.div` - label { - color: #fff; - } - - .rbt-input-multi { - background: #23242b !important; - color: #fff !important; - } - - .rbt-token { - background: #202020 !important; - color: #fff !important; - } - - .rbt-menu { - background: #23242b !important; - color: #fff !important; - - .dropdown-item { - color: #fff !important; - transition: all 300ms; - - &:hover { - background: #202020; - } - } - } -`; - const avatarComponent = useMemo(() => { return (No graph item type passed.
; +} + +const items = Social.getr(`${accountId}/graph/${itemType}`, "final", { + withBlockHeight: true, +}); + +const StorageKey = "order"; +const order = Storage.privateGet(StorageKey); +const graphItems = useMemo(() => { + if (items === null || order === null) { + return []; + } + const itemMap = new Map(); + const path = []; + + const buildSrc = (node) => { + if (node.hasOwnProperty("")) { + itemMap.set(path.join("/"), node[":block"]); + } + Object.entries(node).forEach(([key, value]) => { + if (typeof value === "object") { + path.push(key); + buildSrc(value); + path.pop(); + } + }); + }; + + buildSrc(items ?? {}, [], itemMap); + let entries = [...itemMap.entries()]; + entries.sort((a, b) => b[1] - a[1]); + entries = entries.map((a) => a[0]); + entries.sort((a, b) => (order?.[a] || 0) - (order?.[b] || 0)); + Storage.privateSet( + StorageKey, + Object.fromEntries(entries.map((a, i) => [a, i + 1])) + ); + return entries; +}, [items, order]); + +let transformedArray = graphItems.map((item) => { + let splitParts = item.split("/"); + let accountId = splitParts[0]; + let lastPart = splitParts[splitParts.length - 1]; + let blockHeight = isNaN(lastPart) ? null : parseInt(lastPart); + + return { accountId, blockHeight }; +}); + +let filteredArray = transformedArray.filter( + (item) => item.blockHeight !== null +); + +return ( + <> + {(filteredArray ?? []).map((item) => renderItem(item))} + {filteredArray.length === 0 && ( +No {itemType}s!
+ )} + > +); diff --git a/apps/builddao/widget/Post.jsx b/apps/builddao/widget/Post.jsx deleted file mode 100644 index 94901be7..00000000 --- a/apps/builddao/widget/Post.jsx +++ /dev/null @@ -1,372 +0,0 @@ -const accountId = props.accountId; -if (!accountId) { - return "No accountId"; -} -const blockHeight = - props.blockHeight === "now" ? "now" : parseInt(props.blockHeight); -const pinned = !!props.pinned; -const hideMenu = !!props.hideMenu; -const hideButtons = !!props.hideButtons; -const content = - props.content ?? - JSON.parse(Social.get(`${accountId}/post/main`, blockHeight) ?? "null"); -const subscribe = !!props.subscribe; -const raw = !!props.raw; -const groupId = props.groupId ?? content.groupId; -const indexKey = props.indexKey; -const permissions = props.permissions; -const fullPostLink = props.fullPostLink; -const postPage = props.postPage ?? "mob.near/widget/MainPage.N.Post.Page"; - -const notifyAccountId = accountId; -const item = { - type: "social", - path: `${accountId}/post/main`, - blockHeight, -}; - -const link = - props.link ?? - props.fullPostLink ?? - `/${postPage}?accountId=${accountId}&blockHeight=${blockHeight}`; - -const StyledPost = styled.div` - margin-bottom: 1rem; - .post { - border-radius: 16px; - border: 1px solid var(--Stroke-color, rgba(255, 255, 255, 0.2)); - color: #b6b6b8; - padding: 24px !important; - background-color: #0b0c14; - transition: all 300ms; - - &:hover { - background-color: #171929 !important; - .expand-post { - background-image: linear-gradient( - to bottom, - rgb(23, 25, 41, 0), - rgb(23, 25, 41, 1) 25% - ) !important; - } - } - - .post-header { - span, - .text-muted { - color: #fff !important; - } - } - - .buttons { - border-top: 1px solid #3c3d43; - padding: 0.5rem; - } - - .expand-post { - background-image: linear-gradient( - to bottom, - rgb(11, 12, 20, 0), - rgb(11, 12, 20, 1) 25% - ) !important; - } - } - - .dropdown-menu { - background-color: #0b0c14 !important; - color: #fff !important; - - li.dropdown-item { - color: #fff !important; - &:hover { - a { - color: #0b0c14 !important; - } - } - } - - .link-dark, - .dropdown-item { - color: #fff !important; - - &:hover { - color: #0b0c14 !important; - - span { - color: #0b0c14 !important; - } - } - } - } - - textarea { - color: #b6b6b8 !important; - } -`; - -const Wrapper = styled.div` - margin: 0 -12px; - line-height: normal; - - .post { - position: relative; - padding: 12px; - padding-bottom: 4px; - display: flex; - h1, - h2, - h3, - h4, - h5, - h6 { - font-size: 16px !important; - } - @media (max-width: 767px) { - font-size: 15px !important; - h1, - h2, - h3, - h4, - h5, - h6 { - font-size: 15px !important; - } - } - - h1, - h2, - h3, - h4, - h5, - h6, - strong, - b { - font-weight: 500 !important; - } - ol, - ul, - dl { - margin-bottom: 0.5rem; - white-space: inherit; - } - p { - margin-bottom: 0.5rem; - } - hr { - display: none; - } - img { - border-radius: var(--bs-border-radius-lg); - max-height: 40em; - } - th { - min-width: 5em; - } - - .table > :not(caption) > * > * { - padding: 0.3rem; - } - - &:hover { - background-color: rgba(0, 0, 0, 0.03); - .expand-post { - background-image: linear-gradient( - to bottom, - rgba(0, 0, 0, 0), - rgba(247.35, 247.35, 247.35, 1) 25% - ); - } - } - - .post-header { - margin: 4px 0; - } - } - - .post:not(:last-child):before { - content: ""; - position: absolute; - left: 30px; - top: 56px; - bottom: 0; - width: 2px; - background-color: #ddd; - z-index: -1; - } - - .post:not(:first-child):after { - content: ""; - position: absolute; - left: 30px; - top: 0; - width: 2px; - height: 8px; - background-color: #ddd; - z-index: -1; - } - - .left { - margin-right: 12px; - min-width: 40px; - width: 40px; - overflow: hidden; - } - .right { - margin-top: -4px; - flex-grow: 1; - min-width: 0; - } - - .buttons-placeholder { - padding-bottom: 10px; - } - - .buttons { - margin-top: 10px; - margin-bottom: 6px; - column-gap: 4px; - color: #888; - } - - .reposted { - padding-top: 30px; - } -`; - -const contentWidget = ( -404 Not Found
; + } + } + + return ( +