matrix-art

An image gallery for Matrix
git clone git://archive.git.mtrnord.blog/MTRNord/matrix-art.git
Log | Files | Refs | README | LICENSE

commit 2aaea866b92c6c1d3c39c2acb68145316ac79d55
parent 6451abaaec9728ccc8927220535323763e96a49e
Author: MTRNord <mtrnord1@gmail.com>
Date:   Thu, 13 Jan 2022 23:49:52 +0100

Use getStaticProps for Homepage

Diffstat:
Mpages/index.tsx | 20++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/pages/index.tsx b/pages/index.tsx @@ -6,11 +6,10 @@ import { client, ClientContext } from '../components/ClientContext'; import FrontPageImage from '../components/FrontPageImage'; import Footer from '../components/Footer'; import { NextRouter, withRouter } from 'next/router'; -import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; +import { GetStaticProps, InferGetStaticPropsType } from 'next'; import { get_data } from './api/directory'; -type Props = InferGetServerSidePropsType<typeof getServerSideProps> & { - router: NextRouter; +type Props = InferGetStaticPropsType<typeof getStaticProps> & { }; type State = { @@ -68,20 +67,13 @@ class Home extends PureComponent<Props, State>{ } Home.contextType = ClientContext; -export const getServerSideProps: GetServerSideProps = async (context) => { - const { res } = context; - - res.setHeader( - 'Cache-Control', - 'public, s-maxage=10, stale-while-revalidate=59' - ); +export const getStaticProps: GetStaticProps = async (context) => { let image_events: MatrixImageEvents[] = []; try { const data = await get_data(); - // TODO fix this. It is super inefficent. + // TODO fix this somehow. It is super inefficent. for (let user of data) { - // TODO check what happens if this is a non public image. // We dont need many events const roomId = await client?.followUser(user.user_room); const events = await client?.getTimeline(roomId, 100); @@ -101,4 +93,4 @@ export const getServerSideProps: GetServerSideProps = async (context) => { } }; -export default withRouter(Home); -\ No newline at end of file +export default Home; +\ No newline at end of file