Skip to content

IdeaVoteComponent JavaScript

Ethan Dunzer edited this page Aug 29, 2024 · 1 revision

Overview

The IdeaVoteComponent JavaScript file is responsible for managing the display and interaction of a single idea's voting system. It handles data retrieval for the idea, manages the user's voting state, and updates the UI to reflect changes in voting.

Properties

  • @api recordId: Public property that stores the ID of the idea record being displayed.
  • @track isLoading: Tracks the loading state of the component, ensuring that the UI displays a loading indicator when necessary.
  • @track idea: Tracks the idea record retrieved from the server, used for displaying idea details and voting buttons.
  • @track upVoteClass: Determines the CSS class for the upvote button based on the user's voting state.
  • @track downVoteClass: Determines the CSS class for the downvote button based on the user's voting state.
  • wiredIdeaResult: Stores the result of the @wire service call for data refresh purposes.

Methods

  • connectedCallback(): Lifecycle hook that triggers when the component is inserted into the DOM. It logs the component connection and initializes any necessary data.
  • wiredIdea(result): A wired method that retrieves the idea and its associated vote record from the server. It updates the UI based on the retrieved data, setting the appropriate voting classes.
  • logErrorDetails(error): Logs detailed error information to the console, including status, message, and any additional error details.
  • updateVoteClasses(): Updates the CSS classes for the upvote and downvote buttons based on the user's current voting state.
  • handleUpVote(): Sends a request to upvote the idea. It updates the voting state and UI based on the user's interaction.
  • handleDownVote(): Sends a request to downvote the idea. It updates the voting state and UI based on the user's interaction.
  • showToast(title, message, variant): Displays a toast notification with the provided title, message, and variant (e.g., 'success', 'error').

Usage The IdeaVoteComponent JavaScript file is crucial for managing the voting functionality of a single idea. It ensures that users can interact with the voting system, see the results of their actions in real-time, and receive feedback on their interactions through toast notifications.

Clone this wiki locally