-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
223 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,72 @@ | ||
import React from 'react'; | ||
import styles from './styles.module.scss'; | ||
import { Metadata, ResolvingMetadata } from 'next'; | ||
import { serviceShares } from '@/services'; | ||
import { ShareIntro } from '@/components/ShareIntro'; | ||
import { BuyStock } from '@/components/BuyStock'; | ||
import { serviceShares } from '@/services'; | ||
import Candles from '@/components/Candles/Candles'; | ||
import styles from './styles.module.scss'; | ||
|
||
const PageStock = async ({ params }: { params: { slug: string } }) => { | ||
const { data } = await serviceShares.getByTicker(params.slug); | ||
const { data: dataLastPrice } = await serviceShares.getLastPriceByTicker( | ||
params.slug, | ||
); | ||
return ( | ||
<div className={styles.page}> | ||
<div className={styles.main}> | ||
{/*@ts-ignore*/} | ||
<ShareIntro value={data} /> | ||
</div> | ||
<div className={styles.side}> | ||
<BuyStock info={dataLastPrice} /> | ||
type Props = { | ||
params: { slug: string }; | ||
}; | ||
|
||
export async function generateMetadata( | ||
{ params }: Props, | ||
parent: ResolvingMetadata, | ||
): Promise<Metadata> { | ||
const shareData = await serviceShares.getByTicker(params.slug); | ||
const dataIntro = shareData?.data; | ||
|
||
if (!dataIntro) { | ||
return { | ||
title: 'Stock not found', | ||
}; | ||
} | ||
|
||
const metaDescription = `Information about stock ${dataIntro.name} (${dataIntro.ticker}). Sector: ${dataIntro.sector}, Country: ${dataIntro.countryOfRiskName}`; | ||
const keywords = `${dataIntro.name}, ${dataIntro.ticker}, ${dataIntro.sector}, ${dataIntro.countryOfRiskName}, stock, invest`; | ||
|
||
return { | ||
title: `${dataIntro.name} (${dataIntro.ticker}) - Information about stock`, | ||
description: metaDescription, | ||
keywords: keywords, | ||
openGraph: { | ||
title: `${dataIntro.name} (${dataIntro.ticker}) - Information about stock`, | ||
description: metaDescription, | ||
type: 'website', | ||
}, | ||
}; | ||
} | ||
|
||
const PageStock = async ({ params }: Props) => { | ||
try { | ||
const [shareData, lastPriceData, candlesData] = await Promise.all([ | ||
serviceShares.getByTicker(params.slug), | ||
serviceShares.getLastPriceByTicker(params.slug), | ||
serviceShares.getCandlesByTicker(params.slug), | ||
]); | ||
|
||
const dataIntro = shareData?.data; | ||
const dataLastPrice = lastPriceData?.data; | ||
const dataCandlesByTicker = candlesData?.data; | ||
|
||
return ( | ||
<div className={styles.page}> | ||
<div className={styles.main}> | ||
<div className={styles.intro}> | ||
{dataIntro && <ShareIntro value={dataIntro} />} | ||
</div> | ||
{dataCandlesByTicker && <Candles data={dataCandlesByTicker} />} | ||
</div> | ||
<div className={styles.side}> | ||
<BuyStock info={dataLastPrice} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
} catch (error) { | ||
console.error('Error loading stock data:', error); | ||
return <div>Error loading stock data</div>; | ||
} | ||
}; | ||
|
||
export default PageStock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React from 'react'; | ||
import styles from './styles.module.scss'; | ||
|
||
export const Button = ({ children, ...props }: any) => { | ||
return <button {...props}>{children}</button>; | ||
return <button className={styles.btn} {...props}>{children}</button>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.btn { | ||
padding: 10px; | ||
background-color: var(--button-background-color); | ||
color: var(--button-text-color); | ||
border-radius: var(--button-border-radius); | ||
border: none; | ||
width: 100%; | ||
cursor: pointer; | ||
transition: .3s; | ||
&:hover { | ||
opacity: .8; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import dynamic from 'next/dynamic'; | ||
import styles from './styles.module.scss'; | ||
const Chart = dynamic(() => import('./Chart/Chart'), { ssr: false }); | ||
|
||
const Candles = ({ data }: { data: any }) => { | ||
return ( | ||
<div className={styles.chart}> | ||
<Chart data={data} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Candles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { FC } from 'react'; | ||
// @ts-ignore | ||
import CanvasJSReact from '@canvasjs/react-charts'; | ||
const CanvasJSChart = CanvasJSReact.CanvasJSChart; | ||
|
||
interface CandleData { | ||
open: { units: string; nano: number }; | ||
high: { units: string; nano: number }; | ||
low: { units: string; nano: number }; | ||
close: { units: string; nano: number }; | ||
volume: string; | ||
time: string; | ||
isComplete: boolean; | ||
candleSource: string; | ||
} | ||
|
||
interface CandlesProps { | ||
data: { | ||
candles: CandleData[]; | ||
}; | ||
} | ||
|
||
const Candles: FC<CandlesProps> = ({ data }) => { | ||
const dataPoints = data.candles.map((candle) => ({ | ||
x: new Date(candle.time), | ||
y: [ | ||
parseFloat(`${candle.open.units}.${candle.open.nano}`), | ||
parseFloat(`${candle.high.units}.${candle.high.nano}`), | ||
parseFloat(`${candle.low.units}.${candle.low.nano}`), | ||
parseFloat(`${candle.close.units}.${candle.close.nano}`), | ||
], | ||
})); | ||
|
||
const options = { | ||
theme: 'light2', | ||
axisX: { | ||
valueFormatString: 'DD MMM', | ||
}, | ||
axisY: { | ||
prefix: '$', | ||
}, | ||
data: [ | ||
{ | ||
type: 'candlestick', | ||
yValueFormatString: '$###0.00', | ||
xValueFormatString: 'DD MMM YYYY', | ||
dataPoints: dataPoints, | ||
}, | ||
], | ||
}; | ||
|
||
return <CanvasJSChart options={options} />; | ||
}; | ||
|
||
export default Candles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Chart' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Candles' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.chart { | ||
border-radius: 8px; | ||
overflow: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters