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

Fix/change radio detail page content #426

Closed
Closed
Show file tree
Hide file tree
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
102 changes: 102 additions & 0 deletions frontend/src/components/molecules/RadioDetails/RadioContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { FC } from "react";
import styled from "styled-components";
import ReactMarkdown from "react-markdown";
import { useLocation } from "react-router-dom";
import { device, color } from "@/constants/styles";
import { CHK } from "@/constants/url";

import { RadioPlayer } from "@/components/molecules/RadioDetails/RadioPlayer";
import Personalities from "@/components/molecules/Personalities";
import { Share } from "@/components/molecules/RadioDetails/Share";

import { IRadio } from "@/api/RadioApi";
import { PersonalityProfileMiniCard } from "@/components/atoms/FeaturedPersonality/PersonalityProfileMiniCard";

interface Props {
radio: IRadio | undefined;
}

export const RadioContainer: FC<Props> = ({ radio }) => {
const location = useLocation();
const SHARE_URL = CHK.FRONT_END.PROD + location.pathname;

if (radio) {
return (
<>
<device.Default>
<PCWrapper>
<Top>
<Left>
<RadioPlayer {...radio} />
</Left>
<Right>
<Description>
<ReactMarkdown source={radio.description} />
</Description>
<Share url={SHARE_URL} text={radio.title} />
</Right>
</Top>
<Bottom>
<Title>出演しているパーソナリティー</Title>
<Personalities personalities={radio.personalities} />
</Bottom>
</PCWrapper>
</device.Default>
<device.ForMobile>
<MobileWrapper>
<Title>{radio.title}</Title>
<RadioPlayer {...radio} />
<Description>
<ReactMarkdown source={radio.description} />
</Description>
<Share url={SHARE_URL} text={radio.title} />
<Title>出演しているパーソナリティー</Title>
{radio.personalities.map(({ name, image, id }) => (
<PersonalityProfileMiniCard name={name} image={image} key={id} />
))}
</MobileWrapper>
</device.ForMobile>
</>
);
}

return null;
};

const PCWrapper = styled.div`
padding: 50px;
`;

const MobileWrapper = styled.div`
width: calc(100% - 20px);
margin: 0 auto;
`;

const Top = styled.div`
display: flex;
width: 100%;
`;

const Left = styled.div`
width: 50%;
padding-right: 25px;
`;

const Right = styled.div`
width: 50%;
padding-left: 25px;
`;

const Title = styled.h2`
font-size: 1.5rem;
text-align: left;
color: ${color.BLUE};
margin: 5px 0;
`;

const Description = styled.div``;

const Bottom = styled.div`
width: 100%;
margin-top: 50px;
`;
107 changes: 16 additions & 91 deletions frontend/src/pages/RadioDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import React, { Suspense, useState, useEffect } from "react";
import styled from "styled-components";
import { useParams, useLocation } from "react-router-dom";
import { useParams } from "react-router-dom";
import { observer } from "mobx-react-lite";
import ReactMarkdown from "react-markdown";
import { device, color } from "@/constants/styles";
import { CHK } from "@/constants/url";

import { device } from "@/constants/styles";
import RootStore from "@/stores/RootStore";
import RadioStore from "@/stores/RadioStore";

import { RadioDetailHeroArea } from "@/components/molecules/HeroArea/RadioDetailHeroArea";
import TweetStream from "@/components/atoms/Features/TweetStream";
import { PopularRadiosWrapper } from "@/components/molecules/PopularRadio/PopularRadioWrapper";
import { RadioPlayer } from "@/components/molecules/RadioDetails/RadioPlayer";
import Personalities from "@/components/molecules/Personalities";
import { Share } from "@/components/molecules/RadioDetails/Share";
import { RadioContainer } from "@/components/molecules/RadioDetails/RadioContainer";
import CircleSpinner from "@/components/atoms/Spinners/CircleSpinner";

import { IRadio } from "@/api/RadioApi";
import { PersonalityProfileMiniCard } from "@/components/atoms/FeaturedPersonality/PersonalityProfileMiniCard";

interface Props {
radioStore: RadioStore;
Expand All @@ -27,59 +19,30 @@ interface Props {
}

const Main: React.FC<Props> = ({ radioStore, setRadio, radio }) => {
const location = useLocation();
const SHARE_URL = CHK.FRONT_END.PROD + location.pathname;
const { radioId } = useParams();

const reFetchRadio = async () => {
const cache = await radioStore.fetchRadio(Number(radioId));
setRadio(cache);
};

useEffect(() => {
reFetchRadio();
}, [radioId]);

if (radio) {
return (
<>
<device.Default>
<PCWrapper>
<Top>
<Left>
<RadioPlayer {...radio} />
</Left>
<Right>
<Description>
<ReactMarkdown source={radio.description} />
</Description>
<Share url={SHARE_URL} text={radio.title} />
</Right>
</Top>
<Bottom>
<Title>出演しているパーソナリティー</Title>
<Personalities personalities={radio.personalities} />
</Bottom>
</PCWrapper>
</device.Default>
<device.ForMobile>
<MobileWrapper>
<Title>{radio ? radio.title : ""}</Title>
<RadioPlayer {...radio} />
<Description>
<ReactMarkdown source={radio.description} />
</Description>
<Share url={SHARE_URL} text={radio.title} />
<Title>出演しているパーソナリティー</Title>
{radio.personalities.map(({ name, image, id }) => (
<PersonalityProfileMiniCard name={name} image={image} key={id} />
))}
</MobileWrapper>
</device.ForMobile>
</>
);
return <RadioContainer radio={radio} />;
}

throw (async () => {
const cache = await radioStore.fetchRadio(Number(radioId));
setRadio(cache);
reFetchRadio();
})();
};

export const RadioDetail = observer((props: { rootStore: RootStore }) => {
const { rootStore } = props;
const { radioStore } = rootStore;
const { radioId } = useParams();

const [radio, setRadio] = useState<IRadio | undefined>(undefined);

Expand All @@ -94,7 +57,7 @@ export const RadioDetail = observer((props: { rootStore: RootStore }) => {
useEffect(() => {
const radios = radioStore.shuffledRadios({ limit: 3 });
setPopularRadios(radios);
}, [radioStore.radios]);
}, [radioStore.radios, radioId]);

return (
<div>
Expand Down Expand Up @@ -137,41 +100,3 @@ const MainContentWrapper = styled.div`
flex: 0 0 100%;
}
`;

const PCWrapper = styled.div`
padding: 50px;
`;

const MobileWrapper = styled.div`
width: calc(100% - 20px);
margin: 0 auto;
`;

const Top = styled.div`
display: flex;
width: 100%;
`;

const Left = styled.div`
width: 50%;
padding-right: 25px;
`;

const Right = styled.div`
width: 50%;
padding-left: 25px;
`;

const Title = styled.h2`
font-size: 1.5rem;
text-align: left;
color: ${color.BLUE};
margin: 5px 0;
`;

const Description = styled.div``;

const Bottom = styled.div`
width: 100%;
margin-top: 50px;
`;
8 changes: 7 additions & 1 deletion frontend/src/stores/RadioStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export default class RadioStore {
];
}

return shuffledRadio.slice(0, limit);
const randomOffset = Math.floor(
Math.random() * (shuffledRadio.length - (limit || 0))
);

return limit
? shuffledRadio.slice(randomOffset, randomOffset + limit)
: shuffledRadio;
}

public async fetchRadio(radioId: number) {
Expand Down