OpenVAA / voting-advice-application

An open-source platform for creating Voting Advice Applications (VAAs)
https://openvaa.org/en
GNU General Public License v3.0
10 stars 0 forks source link

feat: vaa-data module #513

Open kaljarv opened 4 months ago

kaljarv commented 4 months ago

For some preliminary information, see the deprecated PR #141

Make sure to move all default values, color handling and similar functions from StrapiDataProvider to either vaa-data or the interface between DataProvider and the data model.

Notes from EE 2024 VAA project

In the first implementation, this could also include a proto vaa-data model that enables the functionalities necessary for the 2024 EU Elections VAAs, roughly:

These would implement the requisite interfaces of vaa-matching.

DataProvider would return objects that can be converted into these objects.

The Svelte components would accept objects that extend these objects, thus:


// SSR: +layout.server.ts
const dp = new StrapiDataProvider();
const electionData = dp.getElection(); // Get the default election
const constituencyData = dp.getConstituencies({electionId: electionData.id}); 
const candidatesData = dp.getCandidates({constituencyId: constituencyData[0)].id});
return {electionData, constituencyData, candidatesData};

// CSR: +layout.ts
const {electionData, constituencyData, candidatesData} = data;
const root = new DataRoot();
root.provideElectionData(electionData);
root.elections[0].provideConstituencyData(constituencyData);
root.elections[0].constituencies[0].provideCandidateData(candidatesData);

// Component: ElectionCard.type.ts

export interface ElectionCardProps {
  election: Election;
}

// vaa-data

export interface Election {
  /* Props and methods */
}

class Election implements Election {
  constructor(data: ElectionData) {}
  /* Implementation */
}

Open questions

interface Question<StringType extends string | LocalizedString = string> {
  text: StringType;
  /* Other props */
}

const question: Question; // In the Voter App
const question: Question<LocalizedString>; // In the Publisher App