Skip to content

Commit

Permalink
Refactor modals out of post to feed
Browse files Browse the repository at this point in the history
  • Loading branch information
itexpert120 committed Feb 1, 2024
1 parent f175eb5 commit eefc30f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
32 changes: 28 additions & 4 deletions apps/builddao/widget/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,40 @@ const { Post } = VM.require("buildhub.near/widget/components") || {
Post: () => <></>,
};

const { name, template, requiredHashtags, customActions } = props;
const { name: feedName, template, requiredHashtags, customActions } = props;

// for modals
const [item, setItem] = useState(null);
const [showProposeModal, setShowProposeModal] = useState(false);
const toggleProposeModal = () => {
setShowProposeModal(!showProposeModal);
};
const modalToggles = {
propose: toggleProposeModal,
};

return (
<div key={name}>
<div key={feedName}>
{feedName.toLowerCase() === "request" && (
<>
<Widget
src="buildhub.near/widget/components.modals.CreateProposal"
loading="..."
props={{
showModal: showProposeModal,
toggleModal: toggleProposeModal,
item: item,
}}
/>
</>
)}
{!context.accountId ? ( // if not logged in
<Widget src="buildhub.near/widget/components.login-now" props={props} />
) : (
<Widget
src="buildhub.near/widget/Compose"
props={{
draftKey: name,
draftKey: feedName,
template: template,
requiredHashtags: requiredHashtags,
}}
Expand All @@ -41,7 +64,8 @@ return (
noBorder={true}
currentPath={`/buildhub.near/widget/app?page=feed`}
customActions={customActions}
feedType={name}
modalToggles={modalToggles}
setItem={setItem}
/>
)}
/>
Expand Down
21 changes: 2 additions & 19 deletions apps/builddao/widget/components/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,8 @@ const contentWidget = (
</>
);

// need to refactor this
const [showModal, setShowModal] = useState(false);
const toggleModal = () => {
setShowModal(!showModal);
};

return (
<>
{props.feedType.toLowerCase() === "request" && (
<>
<Widget
src="buildhub.near/widget/components.modals.CreateProposal"
props={{
showModal,
toggleModal,
item: item,
}}
/>
</>
)}
<StyledPost key={`Post-${item.path}-${item.blockHeight}`}>
<Wrapper
className="w-100 mx-auto"
Expand All @@ -330,7 +312,8 @@ return (
postType: "post",
flagItem: item,
customActions: customActions,
toggleModal: toggleModal,
modalToggles: props.modalToggles,
setItem: props.setItem,
}}
/>
{fullPostLink ? (
Expand Down
12 changes: 6 additions & 6 deletions apps/builddao/widget/components/modals/CreateProposal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { Modal, Button, User } = VM.require(
) || {
Modal: () => <></>,
Button: () => <></>,
User: () => <></>
User: () => <></>,
};

const showModal = props.showModal;
Expand Down Expand Up @@ -128,7 +128,7 @@ return (
selectedDAO: selectedDAO,
item: props.item,
bootstrapTheme: bootstrapTheme,
customCSS: editorCSS
customCSS: editorCSS,
}}
/>
</>
Expand All @@ -141,7 +141,7 @@ return (
selectedDAO: selectedDAO,
item: props.item,
bootstrapTheme: bootstrapTheme,
customCSS: editorCSS
customCSS: editorCSS,
}}
/>
</>
Expand All @@ -154,7 +154,7 @@ return (
selectedDAO: selectedDAO,
item: props.item,
bootstrapTheme: bootstrapTheme,
customCSS: editorCSS
customCSS: editorCSS,
}}
/>
</>
Expand All @@ -168,7 +168,7 @@ return (
selectedDAO: selectedDAO,
item: props.item,
bootstrapTheme: bootstrapTheme,
customCSS: editorCSS
customCSS: editorCSS,
}}
/>
</>
Expand All @@ -182,7 +182,7 @@ return (
selectedDAO: selectedDAO,
item: props.item,
bootstrapTheme: bootstrapTheme,
customCSS: editorCSS
customCSS: editorCSS,
}}
/>
</>
Expand Down
14 changes: 8 additions & 6 deletions apps/builddao/widget/components/post/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const isPremium = !!props.isPremium;
const flagItem = props.flagItem;
const customActions = props.customActions ?? [];
const showTime = props.showTime ?? true;
const toggleModal = props.toggleModal;
const modalToggles = props.modalToggles;
const setItem = props.setItem;

const { href } = VM.require("buildhub.near/widget/lib.url") || (() => {});

Expand Down Expand Up @@ -195,11 +196,12 @@ return (
customActions.map((action) => (
<li key={action.label}>
<button
onClick={() =>
action.type === "modal"
? action.onClick(toggleModal)
: action.onClick(flagItem)
}
onClick={() => {
if (action.type === "modal") {
action.onClick(modalToggles);
setItem(flagItem);
}
}}
className="btn btn-outline-dark dropdown-item"
>
<i className={`bi ${action.icon}`}></i>{" "}
Expand Down
7 changes: 4 additions & 3 deletions apps/builddao/widget/config/feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ return {
type: "modal",
icon: "bi-file",
label: "Propose",
onClick: (modalToggle) => {
console.log("modal", modalToggle);
modalToggle();
onClick: (modalToggles) => {
console.log(modalToggles);
const toggle = modalToggles.propose;
toggle();
},
},
],
Expand Down

0 comments on commit eefc30f

Please sign in to comment.