Skip to content

Commit

Permalink
snapshot message now changes when space is changed in dropdown (#7007)
Browse files Browse the repository at this point in the history
* snapshot message now changes when space is changed in dropdown

* deleted commented out code

* deleted console log

* refactored code to not be redundant

* destructured props to pass tests and clean up codebase
  • Loading branch information
Israellund authored Mar 18, 2024
1 parent 4325a55 commit 315dddc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState, useEffect, useMemo } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

import type Thread from '../../models/Thread';
import app from '../../state';
import { NewSnapshotProposalForm } from '../pages/new_snapshot_proposal';
import { CWDropdown } from '../components/component_kit/cw_dropdown';
import {
CWModalBody,
CWModalHeader,
} from '../components/component_kit/new_designs/CWModal';
import { NewSnapshotProposalForm } from '../pages/new_snapshot_proposal';

import '../../../styles/modals/new_snapshot_proposal_modal.scss';

Expand All @@ -23,16 +23,20 @@ export const NewSnapshotProposalModal = ({
onModalClose,
}: NewSnapshotProposalModalProps) => {
const [selectedSnapshotId, setSelectedSnapshotId] = useState<string | null>(
null
null,
);
const handleSelect = async (item) => {
setSelectedSnapshotId(item.value);
await app.snapshot.init(item.value);
};

const snapshotOptions = useMemo(
() =>
app.chain?.meta.snapshot.map((snapshot) => ({
value: snapshot,
label: snapshot,
})) || [],
[]
[],
);

useEffect(() => {
Expand All @@ -50,7 +54,7 @@ export const NewSnapshotProposalModal = ({
<CWDropdown
label="Select Snapshot Space"
options={snapshotOptions}
onSelect={(item) => setSelectedSnapshotId(item.value)}
onSelect={handleSelect}
/>
{selectedSnapshotId && (
<NewSnapshotProposalForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ type SnapshotProposalCardProps = {
showSkeleton?: boolean;
};

export const SnapshotProposalCard = (props: SnapshotProposalCardProps) => {
const { proposal, snapshotId } = props;
export const SnapshotProposalCard = ({
showSkeleton,
snapshotId,
proposal,
}: SnapshotProposalCardProps) => {
const navigate = useCommonNavigate();

const proposalLink = `/snapshot/${snapshotId}/${proposal.id}`;

const time = moment(+proposal.end * 1000);
const now = moment();

if (props.showSkeleton) return <SnapshotProposalCardSkeleton />
if (showSkeleton) return <SnapshotProposalCardSkeleton />;

// TODO: display proposal.scores and proposal.scores_total on card
return (
Expand All @@ -48,7 +51,7 @@ export const SnapshotProposalCard = (props: SnapshotProposalCardProps) => {
<div className="proposal-card-metadata">
<ProposalTag
label={`${proposal.ipfs.slice(0, 6)}...${proposal.ipfs.slice(
proposal.ipfs.length - 6
proposal.ipfs.length - 6,
)}`}
/>
<CWText title={proposal.title} fontWeight="semiBold" noWrap>
Expand Down

0 comments on commit 315dddc

Please sign in to comment.