Skip to content

Commit

Permalink
fix: Handle minor issues after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Jun 28, 2024
1 parent b66bf37 commit 361d6a6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const experiment2 = getExperiment({
const collectionWithDashboard = { dashboard: [experiment1, experiment2] }

const header = {
nextExperimentButtonText: 'Next experiment',
nextBlockButtonText: 'Next experiment',
aboutButtonText: 'About us',
}
const collectionWithTheme = {
Expand Down Expand Up @@ -123,4 +123,4 @@ describe('ExperimentCollectionDashboard', () => {
);
await screen.findByText('About us');
});
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ExperimentCollectionDashboardProps {

export const ExperimentCollectionDashboard: React.FC<ExperimentCollectionDashboardProps> = ({ experimentCollection, participantIdUrl, totalScore }) => {

const { dashboard, description } = experimentCollection;
const { dashboard, description, name } = experimentCollection;
const { nextExperimentButtonText, aboutButtonText } = experimentCollection.theme?.header || { nextExperimentButtonText: "", aboutButtonText: "" };

const scoreDisplayConfig = experimentCollection.theme?.header?.score;
Expand All @@ -32,9 +32,10 @@ export const ExperimentCollectionDashboard: React.FC<ExperimentCollectionDashboa
nextBlockSlug={nextBlockSlug}
collectionSlug={experimentCollection.slug}
totalScore={totalScore}
name={name}
description={description}
scoreDisplayConfig={scoreDisplayConfig}
nextExperimentButtonText={nextExperimentButtonText}
nextBlockButtonText={nextExperimentButtonText}
aboutButtonText={aboutButtonText}
/>
)}
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/ExperimentCollection/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import { ScoreDisplayConfig } from "@/types/Theme";
import Rank from "@/components/Rank/Rank";

interface HeaderProps {
name: string;
description: string;
nextBlockSlug: string | undefined;
nextExperimentButtonText: string;
nextBlockButtonText: string;
collectionSlug: string;
aboutButtonText: string;
totalScore: number;
scoreDisplayConfig?: ScoreDisplayConfig;
}

export const Header: React.FC<HeaderProps> = ({
name,
description,
nextBlockSlug,
nextExperimentButtonText,
nextBlockButtonText,
aboutButtonText,
collectionSlug,
totalScore,
Expand All @@ -33,7 +35,7 @@ export const Header: React.FC<HeaderProps> = ({
// Get current URL minus the query string
const currentUrl = window.location.href.split('?')[0];
const message = totalScore > 0 ? `Ha! Ik ben muzikaler dan ik dacht - heb maar liefst ${totalScore} punten! Speel mee met #ToontjeHoger` : "Ha! Speel mee met #ToontjeHoger en laat je verrassen: je bent muzikaler dat je denkt!";
const hashtags = [experimentCollectionTitle ? experimentCollectionTitle.replace(/ /g, '') : 'amsterdammusiclab'];
const hashtags = [name ? name.replace(/ /g, '') : 'amsterdammusiclab'];

const social = {
apps: ['facebook', 'twitter'],
Expand All @@ -47,7 +49,7 @@ export const Header: React.FC<HeaderProps> = ({
<div className="intro">
<HTML body={description} innerClassName="" />
<nav className="actions">
{nextBlockSlug && <a className="btn btn-lg btn-primary" href={`/${nextBlockSlug}`}>{nextExperimentButtonText}</a>}
{nextBlockSlug && <a className="btn btn-lg btn-primary" href={`/${nextBlockSlug}`}>{nextBlockButtonText}</a>}
{aboutButtonText && <Link className="btn btn-lg btn-outline-primary" to={`/collection/${collectionSlug}/about`}>{aboutButtonText}</Link>}
</nav>
</div>
Expand Down
80 changes: 40 additions & 40 deletions frontend/src/stories/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,71 @@ import { BrowserRouter as Router } from "react-router-dom";
import Header from "../components/ExperimentCollection/Header/Header";

export default {
title: "Header",
component: Header,
parameters: {
layout: "fullscreen",
},
title: "Header",
component: Header,
parameters: {
layout: "fullscreen",
},
};

function getHeaderData(overrides = {}) {
return {
description: "<h1>Experiment ABC</h1><p>This is the experiment description</p>",
nextExperimentSlug: '/th1-mozart',
nextExperimentButtonText: 'Volgende experiment',
collectionSlug: '/collection/thkids',
aboutButtonText: 'Over ons',
totalScore: 420,
scoreDisplayConfig: {
scoreClass: 'gold',
scoreLabel: 'points',
},
...overrides,
};
return {
description: "<h1>Experiment ABC</h1><p>This is the experiment description</p>",
nextExperimentSlug: '/th1-mozart',
nextBlockButtonText: 'Volgende experiment',
collectionSlug: '/collection/thkids',
aboutButtonText: 'Over ons',
totalScore: 420,
scoreDisplayConfig: {
scoreClass: 'gold',
scoreLabel: 'points',
},
...overrides,
};
}

const getDecorator = (Story) => (
<div
className="aha__collection"
style={{ width: "100%", height: "100%", backgroundColor: "#aaa", padding: "1rem" }}
>
<Router>
<Story />
</Router>
</div>
<div
className="aha__collection"
style={{ width: "100%", height: "100%", backgroundColor: "#aaa", padding: "1rem" }}
>
<Router>
<Story />
</Router>
</div>
);

export const Default = {
args: getHeaderData(),
decorators: [getDecorator],
args: getHeaderData(),
decorators: [getDecorator],
};

export const ZeroScore = {
args: getHeaderData({ score: 0, score_message: "No points!" }),
decorators: [getDecorator],
args: getHeaderData({ score: 0, score_message: "No points!" }),
decorators: [getDecorator],
};

export const NegativeScore = {
args: getHeaderData({ score: -100, score_message: "Incorrect!" }),
decorators: [getDecorator],
args: getHeaderData({ score: -100, score_message: "Incorrect!" }),
decorators: [getDecorator],
};

export const ScoreWithoutLabel = {
args: getHeaderData({ score_message: "" }),
decorators: [getDecorator],
args: getHeaderData({ score_message: "" }),
decorators: [getDecorator],
};

export const CustomLabel = {
args: getHeaderData({ score_message: "points earned" }),
decorators: [getDecorator],
args: getHeaderData({ score_message: "points earned" }),
decorators: [getDecorator],
};

export const CustomScoreClass = {
args: getHeaderData({ scoreClass: "silver" }),
decorators: [getDecorator],
args: getHeaderData({ scoreClass: "silver" }),
decorators: [getDecorator],
};

export const SelectableScoreClass = {
args: getHeaderData(),
decorators: [getDecorator],
args: getHeaderData(),
decorators: [getDecorator],
};

0 comments on commit 361d6a6

Please sign in to comment.