-
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.
Merge pull request #11 from weseek/feat/tc2023e-38-add-pages-endpoint
Feat/tc2023e-38 add pages endpoint
- Loading branch information
Showing
6 changed files
with
108 additions
and
23 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
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 @@ | ||
NEXT_PUBLIC_APP_SITE_URL=http://localhost:3000 |
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,20 +1,56 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import parse from 'html-react-parser'; | ||
import { NextPage } from 'next'; | ||
|
||
import axios from '~/utils/axios'; | ||
|
||
const Top: NextPage = () => { | ||
const [body, setBody] = useState<string>(); | ||
axios.get('http://localhost:3000/_api/v3/page?pageId=6522505d8eddc4a6c69499b0').then((data) => { | ||
setBody(data.data.page.revision.body); | ||
}); | ||
const TopPage: NextPage = () => { | ||
const [data, setData] = useState<any[]>(); | ||
const [error, setError] = useState<string>(); | ||
|
||
useEffect(() => { | ||
axios.get(`${process.env.NEXT_PUBLIC_APP_SITE_URL}/_cms/list.json`) | ||
.then((response) => { | ||
setData(response.data); | ||
}) | ||
.catch((error) => { | ||
setError(`データの取得に失敗しました。\n${JSON.stringify(error)}`); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div className="border bg-white p-5"> | ||
<pre>{body}</pre> | ||
</div> | ||
<> | ||
{error == null ? ( | ||
<> | ||
{data == null ? ( | ||
<div className="spinner-border" role="status"> | ||
<span className="visually-hidden">Loading...</span> | ||
</div> | ||
) : ( | ||
<> | ||
{data.map((pageData, index) => { | ||
return ( | ||
<div className={`border bg-white p-5${index === 0 ? '' : ' mt-5'}`}> | ||
<div className="index-preview overflow-hidden"> | ||
{parse(pageData.htmlString)} | ||
</div> | ||
<a href={`/${pageData.page._id}`} className="btn btn-outline-primary text-decoration-none rounded-0 mt-4"> | ||
続きを読む | ||
</a> | ||
</div> | ||
); | ||
})} | ||
</> | ||
)} | ||
</> | ||
) : ( | ||
<div className="border bg-white p-5"> | ||
<p>{error}</p> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Top; | ||
export default TopPage; |
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 |
---|---|---|
|
@@ -28,3 +28,11 @@ a { | |
text-decoration: underline; | ||
} | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
} | ||
|
||
.index-preview { | ||
max-height: 500px; | ||
} |