Skip to content

Commit

Permalink
new loading for sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ssani7 committed Sep 6, 2023
1 parent 85ad4b2 commit 620e8e4
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 78 deletions.
76 changes: 45 additions & 31 deletions src/components/Project/ExpandableMilestone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ type ExpandableDropDownsProps = {
isProjectOwner: boolean;
balance: number;
project: Project;
milestonLoadingTitle: string;
};

const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {

const { setLoading, project, setSuccess, setSuccessTitle, setError, milestone, index, modified, setOpenVotingList, approversPreview, firstPendingMilestone, projectInMilestoneVoting, isApplicant, canVote, user, projectType, isProjectOwner, balance } = props
const { setLoading, project, setSuccess, setSuccessTitle, setError, milestone, index, modified, setOpenVotingList, approversPreview, firstPendingMilestone, projectInMilestoneVoting, isApplicant, canVote, user, projectType, isProjectOwner, balance, milestonLoadingTitle } = props

const [expanded, setExpanded] = useState(false);
const [showPolkadotAccounts, setShowPolkadotAccounts] =
Expand Down Expand Up @@ -148,20 +149,24 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
await updateFirstPendingMilestone(Number(project.id), (Number(project.first_pending_milestone) + 1))
setSuccess(true);
setSuccessTitle('Your vote was successful. This milestone has been completed.');
setLoading(false);
break;
}
else if (result.status) {
setSuccess(true);
setSuccessTitle('Your vote was successful.');
setLoading(false);
break;

} else if (result.txError) {
setError({ message: result.errorMessage });
setLoading(false);
break;
}
else if (pollResult != ImbueChainPollResult.Pending) {
setSuccess(true);
setSuccessTitle('Request resolved successfully');
setLoading(false);
break;
}
await new Promise((f) => setTimeout(f, 1000));
Expand All @@ -170,9 +175,13 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
setError({ message: 'Could not vote. Please try again later' });
// eslint-disable-next-line no-console
console.error(error)
} finally {
setLoading(false);
}
// finally {
// console.log("in finally");

// setLoading(false);
// }
};


Expand Down Expand Up @@ -294,32 +303,37 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
</h3>
</div>
<div className='flex flex-row items-center max-width-750px:w-full max-width-750px:justify-between'>
{milestone?.is_approved ? (
<ProjectStateTag
openVotingList={setOpenVotingList}
dateCreated={modified}
text='Completed'
voters={approversPreview}
allApprovers={approversPreview}
/>
) : milestone?.milestone_index == firstPendingMilestone &&
projectInMilestoneVoting ? (
<ProjectStateTag
openVotingList={setOpenVotingList}
dateCreated={modified}
text='Ongoing'
voters={approversPreview}
allApprovers={approversPreview}
/>
) : (
<ProjectStateTag
openVotingList={setOpenVotingList}
dateCreated={modified}
text='Pending'
voters={approversPreview}
allApprovers={approversPreview}
/>
)}
{
milestonLoadingTitle
? <p className="mr-5 text-content-primary text-sm">{milestonLoadingTitle}</p>
: (<>{milestone?.is_approved ? (
<ProjectStateTag
openVotingList={setOpenVotingList}
dateCreated={modified}
text='Completed'
voters={approversPreview}
allApprovers={approversPreview}
/>
) : milestone?.milestone_index == firstPendingMilestone &&
projectInMilestoneVoting ? (
<ProjectStateTag
openVotingList={setOpenVotingList}
dateCreated={modified}
text='Ongoing'
voters={approversPreview}
allApprovers={approversPreview}
/>
) : (
<ProjectStateTag
openVotingList={setOpenVotingList}
dateCreated={modified}
text='Pending'
voters={approversPreview}
allApprovers={approversPreview}
/>
)}</>)
}

<Image
src={require(expanded
? '@/assets/svgs/minus_btn.svg'
Expand Down Expand Up @@ -349,7 +363,7 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
{milestone?.description}
</p>

{!isApplicant &&
{!milestonLoadingTitle && !isApplicant &&
milestone.milestone_index == firstPendingMilestone &&
projectInMilestoneVoting && (
<Tooltip
Expand All @@ -372,7 +386,7 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
</Tooltip>
)}

{(isApplicant || (projectType === 'grant' && isProjectOwner)) &&
{!milestonLoadingTitle && (isApplicant || (projectType === 'grant' && isProjectOwner)) &&
milestone.milestone_index == firstPendingMilestone &&
!projectInMilestoneVoting &&
!milestone?.is_approved && (
Expand All @@ -395,7 +409,7 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
</Tooltip>
)}

{isApplicant && milestone.is_approved && (
{!milestonLoadingTitle && isApplicant && milestone.is_approved && (
<button
className={`primary-btn in-dark w-button ${!balance && '!bg-gray-300 !text-gray-400'
} font-normal max-width-750px:!px-[40px] h-[43px] items-center content-center !py-0 mt-[25px] px-8`}
Expand Down
75 changes: 43 additions & 32 deletions src/components/Project/Impressions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Impressions = ({
firstPendingMilestone,
projectInMilestoneVoting,
setOpenVotingList,
milestoneLoding
}: any) => {
// const votedYes: User[] = []
// const votedNo: User[] = []
Expand Down Expand Up @@ -73,40 +74,50 @@ const Impressions = ({
</AvatarGroup>
)
}
*/
}
*/}
</div>
<div className='text-xl text-content flex flex-wrap items-center'>
{firstPendingMilestone !== undefined &&
milestone?.milestone_index <= firstPendingMilestone &&
projectInMilestoneVoting ? (
<>
{milestone.is_approved ? (
<p className='text-lg cursor-pointer !text-content-primary'>
Completed
</p>
) : (
<p
onClick={() => setOpenVotingList(true)}
className='text-lg cursor-pointer'
>
Votes
</p>
)}
</>
) : (
<>
{milestone.is_approved ? (
<p className='text-lg cursor-pointer !text-content-primary'>
Completed
</p>
) : (
<p className='text-gray-500 text-opacity-30 cursor-pointer'>
Pending
</p>
)}
</>
)}
{
milestoneLoding
? <p className='text-gray-500 text-opacity-30 cursor-pointer'>Loading...</p>
: (
<>
{firstPendingMilestone !== undefined &&
milestone?.milestone_index <= firstPendingMilestone &&
projectInMilestoneVoting
? (
<>
{milestone.is_approved
? (
<p className='text-lg cursor-pointer !text-content-primary'>
Completed
</p>)
: (
<p
onClick={() => setOpenVotingList(true)}
className='text-lg cursor-pointer'
>
Votes
</p>
)}
</>)
: (
<>
{milestone.is_approved
? (
<p className='text-lg cursor-pointer !text-content-primary'>
Completed
</p>)
: (
<p className='text-gray-500 text-opacity-30 cursor-pointer'>
Pending
</p>
)}
</>
)}
</>)
}

</div>
</div>
);
Expand Down
9 changes: 6 additions & 3 deletions src/components/Project/VotingList/VotingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type VotingListProps = {
open: boolean;
firstPendingMilestone: number | undefined;
setOpenVotingList: (_value: boolean) => void;
setMilestoneVotes: (_value: any) => void;
approvers: User[];
chainProjectId: number | undefined;
}
Expand All @@ -29,7 +30,7 @@ type MilestoneVotes = {
}

const VotingList = (props: VotingListProps) => {
const { firstPendingMilestone, setOpenVotingList, approvers, chainProjectId, open } = props
const { firstPendingMilestone, setOpenVotingList, approvers, chainProjectId, open, setMilestoneVotes } = props
const [value, setValue] = React.useState(0);
const [list, setList] = useState<User[]>([]);
const [votes, setVotes] = useState<MilestoneVotes[]>([])
Expand All @@ -50,6 +51,7 @@ const VotingList = (props: VotingListProps) => {
chainProjectId,
firstPendingMilestone
);
setMilestoneVotes(milestoneVotes)

const votesArray = Object.keys(milestoneVotes)

Expand All @@ -62,14 +64,15 @@ const VotingList = (props: VotingListProps) => {
setVotes(votes)
}
} catch (error) {
console.log(error);
// eslint-disable-next-line no-console
console.error(error);
} finally {
setLoading(false)
}
}

setVotingList()
}, [chainProjectId, user, firstPendingMilestone])
}, [chainProjectId, user, firstPendingMilestone, setMilestoneVotes])

useEffect(() => {
const votedYes: User[] = []
Expand Down
10 changes: 6 additions & 4 deletions src/pages/api/project/[...id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ export default nextConnect()
status_id,
completed: status_id === OffchainProjectState.Completed,
project_in_voting_of_no_confidence,
first_pending_milestone,
project_in_milestone_voting
};

if (first_pending_milestone)
newProject.first_pending_milestone = first_pending_milestone;
// if (first_pending_milestone)
// newProject.first_pending_milestone = first_pending_milestone;

if (project_in_milestone_voting)
newProject.project_in_milestone_voting = project_in_milestone_voting;
// if (project_in_milestone_voting)
// newProject.project_in_milestone_voting = project_in_milestone_voting;

const project = await models.updateProject(projectId, newProject)(tx);

Expand Down
Loading

0 comments on commit 620e8e4

Please sign in to comment.