Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WV-890] Politician Name and State renders offline [TEAM REVIEW] #4227

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/js/common/pages/Politician/PoliticianDetailsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,15 @@ function extractPoliticianDetailsFromUrl(url) {

// assume the second part of the path is the SEO-friendly string ("nancy-a-montgomery-politician-from-new-york")
const seoFriendlyPart = parts[1];
console.log('SEO Friendly Part:', seoFriendlyPart);

if (!seoFriendlyPart) {
return { state: null, name: null }; // If there's no seoFriendlyPart, return null for state and name
}

// Split the SEO-friendly part by dashes to get the name and state words
const words = seoFriendlyPart.split('-');
console.log('Words:', words);

const fromIndex = words.lastIndexOf('from'); // Look for the last occurrence of "from", as it typically separates the name and state, reduce chances of pulling "from" in the name
console.log('From last Index:', fromIndex);

if (fromIndex === -1) {
return { state: null, name: null }; // If 'from' is not found, return null for both
Expand Down Expand Up @@ -630,9 +627,7 @@ class PoliticianDetailsPage extends Component {

render () {
renderLog('PoliticianDetailsPage'); // Set LOG_RENDER_EVENTS to log all renders

const { politicianStateParsedFromURLBeforeLoad } = this.state; // reaname variable state calculated from URL to be used when page is still loading.
const { politicianNameParsedFromURLBeforeLoad } = this.state; // reaname variable name calculated from URL to be used when page is still loading.
const { politicianStateParsedFromURLBeforeLoad, politicianNameParsedFromURLBeforeLoad } = this.state; // reaname variable state calculated from URL to be used when page is still loading.
const { classes } = this.props;
const { match: { params } } = this.props;
const { politicianSEOFriendlyPath: politicianSEOFriendlyPathFromUrl } = params;
Expand Down Expand Up @@ -820,7 +815,7 @@ class PoliticianDetailsPage extends Component {
officeName={contestOfficeName}
politicalParty={candidateCampaign.party}
showOfficeName={showOfficeName}
stateName={stateName || politicianStateParsedFromURLBeforeLoad}
stateName={stateName}
year={`${year}`}
/>
</CandidateCampaignWrapper>
Expand Down Expand Up @@ -964,8 +959,8 @@ class PoliticianDetailsPage extends Component {
{/* Candidate Name */}
<CandidateNameAndPartyWrapper>
<CandidateNameH4>
{politicianName || politicianNameParsedFromURLBeforeLoad}
</CandidateNameH4>
{politicianName}
</CandidateNameH4>'
<CandidateParty>
{politicalParty}
</CandidateParty>
Expand Down Expand Up @@ -1155,8 +1150,8 @@ class PoliticianDetailsPage extends Component {
<CampaignOwnersList politicianWeVoteId={politicianWeVoteIdForDisplay} />
</CampaignOwnersDesktopWrapper>
<CampaignDescriptionDesktopWrapper>
{politicianDataFound && (
<DelayedLoad waitBeforeShow={250}>
{politicianDataFound ? (
<DelayedLoad waitBeforeShow={250} onLoad={this.handleDelayContentLoad}>
<CampaignDescriptionDesktop>
<AboutAndEditFlex>
<SectionTitleSimple>
Expand All @@ -1175,6 +1170,11 @@ class PoliticianDetailsPage extends Component {
)}
</CampaignDescriptionDesktop>
</DelayedLoad>
) : (
<CampaignDescriptionDesktop>
<h1>{politicianNameParsedFromURLBeforeLoad}</h1>
<h2>{politicianStateParsedFromURLBeforeLoad}</h2>
</CampaignDescriptionDesktop>
)}
{politicianDataFound && (
<DelayedLoad waitBeforeShow={250}>
Expand Down
Loading