Skip to content

Commit

Permalink
Merge pull request #250 from Megha-Dev-19/project-updates
Browse files Browse the repository at this point in the history
Project Bug fixes
  • Loading branch information
Megha-Dev-19 authored Apr 22, 2024
2 parents 712036f + 9bd55c2 commit 7679bfa
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 34 deletions.
36 changes: 19 additions & 17 deletions apps/builddao/widget/components/modals/CreateProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ const isNearAddress = (address) => {
}

const parts = address.split(".");
if (parts.length !== 2) {
return false;
}

if (parts[0].length < 2 || parts[0].length > 32) {
return false;
Expand All @@ -54,7 +51,7 @@ const tabs = [
{ id: "roadmap", label: "Roadmap", checked: false },
];

const app = props.app ?? "testing122.near";
const app = props.app ?? "${config_account}";

const [tags, setTags] = useState(props.filters.tags ?? []);
const [projectAccount, setProjectAccount] = useState(accountId);
Expand Down Expand Up @@ -87,8 +84,7 @@ const handleCheckboxChange = (event) => {
};

const following = Social.get(`${context.accountId}/graph/follow/*`);

const accounts = following && Object.keys(following);
const followingAccountSuggestion = following && Object.keys(following);

const handleTags = (tags) => {
let filtered = tags.map((tag) => (tag.customOption ? tag.label : tag));
Expand Down Expand Up @@ -228,7 +224,6 @@ const Main = styled.div`
`;

function onCreateProject() {
const projectAccountId = projectAccount;
const projectID = normalize(title);
const project = {
title,
Expand All @@ -243,32 +238,35 @@ function onCreateProject() {
tabs: Array.from(selectedTabs),
profileImage: avatar,
backgroundImage: coverImage,
projectAccountId,
projectAccountId: projectAccount,
teamSize,
};
const data = {
"user-project": {
[projectID]: JSON.stringify(project),
metadata: project,
project: {
[projectID]: {
"": JSON.stringify(project),
metadata: project,
},
},
[app]: {
project: {
[`${context.accountId}_user-project_${projectID}`]: "",
[`${context.accountId}_project_${projectID}`]: "",
},
},
};
if (projectAccountId.includes(".sputnik-dao.near")) {
const policy = Near.view(projectAccountId, "get_policy");
if (projectAccount.includes(".sputnik-dao.near")) {
const policy = Near.view(projectAccount, "get_policy");
const base64 = Buffer.from(
JSON.stringify({
data: {
[projectAccountId]: data,
[projectAccount]: data,
},
options: { refund_unused_deposit: true },
}),
"utf-8",
).toString("base64");
Near.call({
contractName: projectAccountId,
contractName: projectAccount,
methodName: "add_proposal",
args: {
proposal: {
Expand Down Expand Up @@ -361,7 +359,11 @@ return (
<Typeahead
multiple
options={
allMainnetAddresses ?? ["frank.near", "ellie.near", "jane.near"]
followingAccountSuggestion ?? [
"frank.near",
"ellie.near",
"jane.near",
]
}
allowNew
placeholder="frank.near, ellie.near"
Expand Down
13 changes: 3 additions & 10 deletions apps/builddao/widget/components/project/page/Overview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const { id } = props;

const project = getProjectMeta(id);

const { description, tags, contributors, accountId, location } = project;
const { description, tags, contributors, accountId, location, teamSize } =
project;

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -84,15 +85,7 @@ return (
<p className="heading">Team Size</p>
<p className="description d-flex align-items-center gap-2">
<i className="bi bi-person"></i>
{!contributors || !contributors.length
? "0"
: contributors.length <= 10
? "1-10"
: contributors.length <= 50
? "10-50"
: contributors.length <= 100
? "50-100"
: "100+"}
{teamSize}
</p>
</div>
</div>
Expand Down
49 changes: 44 additions & 5 deletions apps/builddao/widget/components/project/page/Task.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { id } = props;
const project = getProjectMeta(id);
const app = props.app || "${config_account}";
const type = props.type || "task";
const projectTask = "project";
const projectTask = "project-task";

const ThemeContainer =
props.ThemeContainer ||
Expand Down Expand Up @@ -219,6 +219,7 @@ function fetchTasks() {
"final",
{
order: "desc",
subscribe: true,
},
);
if (!keys) {
Expand All @@ -245,11 +246,28 @@ function fetchTasks() {
const data = fetchTasks();
const tasks = processData(data);

function sortByPriority(a, b) {
const priorityOrder = { P0: 0, P1: 1, P2: 2, P3: 3 };
return priorityOrder[a.priority] - priorityOrder[b.priority];
}

useEffect(() => {
if (Array.isArray(tasks)) {
setProposedTasks(tasks.filter((i) => i.status === StatusValues.PROPOSED));
setProgresTasks(tasks.filter((i) => i.status === StatusValues.PROGRESS));
setCompletedTasks(tasks.filter((i) => i.status === StatusValues.COMPLETED));
setProposedTasks(
tasks
.filter((i) => i.status === StatusValues.PROPOSED)
.sort(sortByPriority),
);
setProgresTasks(
tasks
.filter((i) => i.status === StatusValues.PROGRESS)
.sort(sortByPriority),
);
setCompletedTasks(
tasks
.filter((i) => i.status === StatusValues.COMPLETED)
.sort(sortByPriority),
);
}
}, [tasks]);

Expand Down Expand Up @@ -322,7 +340,27 @@ const onEditTask = useCallback(
[taskDetail, currentEditTaskId],
);

const onDeleteTask = () => {};
const onDeleteTask = useCallback(
(data) => {
const taskId = currentEditTaskId;
const updatedData = {
[type]: {
[taskId]: null,
},
[app]: {
[projectTask]: {
[projectID]: {
[type]: {
[`${context.accountId}_task_${taskId}`]: null,
},
},
},
},
};
Social.set(updatedData, { force: true });
},
[taskDetail, currentEditTaskId],
);

function handleDropdownToggle(columnTitle, index, value) {
setShowDropdownIndex((prevState) => ({
Expand Down Expand Up @@ -718,6 +756,7 @@ const Column = ({ title, addTask, columnTasks, changeStatusOptions }) => {
<div className="d-flex flex-column gap-2">
<div className="h6 bold">{item.title}</div>
<div className="h6">Author: {item.author}</div>
<div className="h6">Priority: {item.priority}</div>
{/* <div className="h6">Last edited: </div> */}
</div>
{isAllowedToEdit && (
Expand Down
7 changes: 5 additions & 2 deletions apps/builddao/widget/page/projects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { ProjectCard } = VM.require(
ProjectCard: () => <></>,
};

const app = props.app || "testing122.near";
const app = props.app || "${config_account}";
const type = props.type || "project";

const flattenObject = (obj) => {
Expand All @@ -31,7 +31,10 @@ const flattenObject = (obj) => {

// ${alias_devs}/project/name-of-the-project
const fetchProjects = () => {
const keys = Social.keys(`*/${app}/${type}/*`, "final", { order: "desc" });
const keys = Social.keys(`*/${app}/${type}/*`, "final", {
order: "desc",
subscribe: true,
});
if (!keys) {
return "Loading...";
}
Expand Down

0 comments on commit 7679bfa

Please sign in to comment.