GoldSim / Website

Source code for the GoldSim.com website
https://www.goldsim.com/
3 stars 1 forks source link

Announcement View Component #34

Closed JeremyCaney closed 11 months ago

JeremyCaney commented 11 months ago

Create an ASP.NET View Component that optionally displays an announcement.

Benefits

This approach will allow @rkossik to create announcements via the editor without developer intervention. This will also automate error-prone details due to layout shifts needed when the attaching the announcement to the footer.

Placement

The Announcement view component will be called from the following views:

Data

The source data will be placed within Web:Home Topic in the following (new) attributes:

Note: While there are multiple places where we could logically store this data, the homepage makes sense given that a) the announcement is displayed at the top of the homepage, and b) the homepage is already a custom Home content type descriptor, which can easily be extended. That said, this can be migrated without much impact in the future, if appropriate.

Challenges

In addition to the above, we need to account for the layout shift in the Calls to Action view component. By default, this is anchored to the footer. When the announcement is in place, it should anchor to the announcement instead. An open challenge is how to relay this data to the Calls to Action view component, which uses the centralized NavigationViewModel, making it difficult to extend.

JeremyCaney commented 11 months ago

For the Calls to Action view component, there are several options:

  1. Place the Announcement view component in the footer and conditionally set the height of the footer in the HTML, instead of the CSS.
  2. Extend the Calls to Action view component’s view model to include a bit for whether it should be anchored to the announcement or the footer. This complicates the Calls to Action view component.
  3. Relay the bit for the Calls to Action anchor via ViewData instead of the view model. This isn’t typically preferred, but would be dramatically simpler.

Given that this is a relatively superficial add-on which isn’t deeply implicated in the rest of the site’s architecture or any core libraries, my inclination is to accept the breach of coding preferences, and go with the last option.

JeremyCaney commented 11 months ago

This was completed with the merging of feature/AnnouncementViewComponent into develop (72ae7db0). In the end, I decided to introduce a view model for the CallsToAction view component to relay the HasAnnouncement bit to the view, thus preventing the need to shortcut this with `ViewData (as suggested in the previous comment).