Skip to content

Commit

Permalink
Use snsFilteredActionableProposalsStore instead snsFilteredProposalsS…
Browse files Browse the repository at this point in the history
…tore
  • Loading branch information
mstrasinskis committed Mar 26, 2024
1 parent 84d8cce commit 414b088
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 2 additions & 6 deletions frontend/src/lib/components/proposals/ProposalCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
import { PROPOSER_ID_DISPLAY_SPLIT_LENGTH } from "$lib/constants/proposals.constants";
import type { UniversalProposalStatus } from "$lib/types/proposals";
import ProposalStatusTag from "$lib/components/ui/ProposalStatusTag.svelte";
import type { Readable } from "svelte/store";
import { createIsActionableProposalStore } from "$lib/derived/actionable-proposals.derived";
export let hidden = false;
export let actionable = false;
export let status: UniversalProposalStatus | undefined;
export let id: bigint | undefined;
export let heading: string;
Expand All @@ -26,9 +25,6 @@
export let proposer: string | undefined;
export let deadlineTimestampSeconds: bigint | undefined;
export let href: string;
let isActionableStore: Readable<boolean | undefined>;
$: isActionableStore = createIsActionableProposalStore(id);
</script>

<li class:hidden>
Expand All @@ -44,7 +40,7 @@
</div>

{#if nonNullish(status)}
<ProposalStatusTag {status} actionable={$isActionableStore} />
<ProposalStatusTag {status} {actionable} />
{/if}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import type {
SnsNervousSystemFunction,
SnsNeuronId,
SnsProposalData,
SnsProposalId,
} from "@dfinity/sns";
import { subaccountToHexString } from "$lib/utils/sns-neuron.utils";
import type { UniversalProposalStatus } from "$lib/types/proposals";
import type { SnsProposalActionableData } from "$lib/derived/sns/sns-filtered-actionable-proposals.derived";
export let proposalData: SnsProposalData;
export let proposalData: SnsProposalActionableData;
export let nsFunctions: SnsNervousSystemFunction[] | undefined;
export let hidden = false;
Expand Down Expand Up @@ -49,6 +49,7 @@
<ProposalCard
{status}
{hidden}
actionable={proposalData.isActionable}
{href}
id={id?.id}
{title}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import type { SnsProposalData } from "@dfinity/sns";
import SnsProposalCard from "$lib/components/sns-proposals/SnsProposalCard.svelte";
import { InfiniteScroll } from "@dfinity/gix-components";
import type { SnsNervousSystemFunction } from "@dfinity/sns";
Expand All @@ -15,9 +14,10 @@
import ActionableProposalsSignIn from "$lib/components/proposals/ActionableProposalsSignIn.svelte";
import ActionableProposalsNotSupported from "$lib/components/proposals/ActionableProposalsNotSupported.svelte";
import ActionableProposalsEmpty from "$lib/components/proposals/ActionableProposalsEmpty.svelte";
import type { SnsProposalActionableData } from "$lib/derived/sns/sns-filtered-actionable-proposals.derived";
export let snsName: string;
export let proposals: SnsProposalData[] | undefined;
export let proposals: SnsProposalActionableData[] | undefined;
export let includeBallots: boolean;
export let actionableSelected: boolean;
export let nsFunctions: SnsNervousSystemFunction[] | undefined;
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/lib/pages/SnsProposals.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { loadSnsProposals } from "$lib/services/$public/sns-proposals.services";
import type { SnsProposalData } from "@dfinity/sns";
import { snsProposalsStore } from "$lib/stores/sns-proposals.store";
import type { SnsNervousSystemFunction } from "@dfinity/sns";
import SnsProposalsList from "$lib/components/sns-proposals/SnsProposalsList.svelte";
Expand All @@ -18,7 +17,6 @@
type SnsFiltersStoreData,
} from "$lib/stores/sns-filters.store";
import { isNullish, nonNullish } from "@dfinity/utils";
import { snsFilteredProposalsStore } from "$lib/derived/sns/sns-filtered-proposals.derived";
import type { Principal } from "@dfinity/principal";
import { createSnsNsFunctionsProjectStore } from "$lib/derived/sns-ns-functions-project.derived";
import type { Readable } from "svelte/store";
Expand All @@ -27,6 +25,10 @@
type ActionableSnsProposalsData,
} from "$lib/stores/actionable-sns-proposals.store";
import { actionableProposalsSegmentStore } from "$lib/stores/actionable-proposals-segment.store";
import {
snsFilteredActionableProposalsStore,
type SnsProposalActionableData,
} from "$lib/derived/sns/sns-filtered-actionable-proposals.derived";
let nsFunctionsStore: Readable<SnsNervousSystemFunction[] | undefined>;
$: nsFunctionsStore = createSnsNsFunctionsProjectStore($snsOnlyProjectStore);
Expand Down Expand Up @@ -125,13 +127,14 @@
$: includeBallots = actionableProposalsData?.includeBallotsByCaller ?? false;
// `undefined` means that we haven't loaded the proposals yet.
let proposals: SnsProposalData[] | undefined;
let proposals: SnsProposalActionableData[] | undefined;
$: proposals = nonNullish(currentProjectCanisterId)
? sortSnsProposalsById(
actionableSelected
? actionableProposalsData?.proposals
: $snsFilteredProposalsStore[currentProjectCanisterId.toText()]
?.proposals
: $snsFilteredActionableProposalsStore[
currentProjectCanisterId.toText()
]?.proposals
)
: undefined;
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/lib/utils/sns-proposals.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export type SnsProposalDataMap = {
};

// TODO: Return also a type and the type description that for now maps to the topic
export const mapProposalInfo = ({
export const mapProposalInfo = <T extends SnsProposalData>({
proposalData,
nsFunctions,
}: {
proposalData: SnsProposalData;
proposalData: T;
nsFunctions: SnsNervousSystemFunction[] | undefined;
}): SnsProposalDataMap => {
const {
Expand Down Expand Up @@ -313,8 +313,8 @@ export const snsRewardStatus = ({
return SnsProposalRewardStatus.PROPOSAL_REWARD_STATUS_SETTLED;
};

export const lastProposalId = (
proposals: SnsProposalData[]
export const lastProposalId = <T extends SnsProposalData>(
proposals: T[]
): SnsProposalId | undefined => {
const last = sortSnsProposalsById(proposals)?.[proposals.length - 1];
return fromNullable(last?.id ?? []);
Expand All @@ -328,9 +328,9 @@ export const lastProposalId = (
* @param {SnsProposalData[]} proposals
* @returns {SnsProposalData[]}
*/
export const sortSnsProposalsById = (
proposals: SnsProposalData[] | undefined
): SnsProposalData[] | undefined =>
export const sortSnsProposalsById = <T extends SnsProposalData>(
proposals: T[] | undefined
): T[] | undefined =>
proposals === undefined
? undefined
: [...proposals].sort(({ id: idA }, { id: idB }) =>
Expand Down

0 comments on commit 414b088

Please sign in to comment.