Browse Source

feat: import & use github discussion categories

main
mistakia 2 weeks ago
parent
commit
b695ee7cf3
  1. 1
      api/routes/github/discussions.mjs
  2. 2
      db/schema.sql
  3. 31
      scripts/import-github-discussions.mjs
  4. 24
      src/views/components/github-discussion/github-discussion.js
  5. 4
      src/views/components/github-discussion/github-discussion.styl
  6. 4
      src/views/pages/roadmap/roadmap.styl

1
api/routes/github/discussions.mjs

@ -11,6 +11,7 @@ router.get('/nano-community', async (req, res) => { @@ -11,6 +11,7 @@ router.get('/nano-community', async (req, res) => {
}
const discussions = await db('github_discussions')
.where('category_id', 'MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyOTA1MTIz') // proposals category
.orderBy('created_at', 'desc')
.limit(20)
const ids = discussions.map((i) => i.id)

2
db/schema.sql

@ -403,6 +403,8 @@ CREATE TABLE `github_discussions` ( @@ -403,6 +403,8 @@ CREATE TABLE `github_discussions` (
`repo` varchar(255) NOT NULL,
`body` text CHARACTER SET utf8mb4 DEFAULT NULL,
`upvotes` int(11) NOT NULL,
`category_name` varchar(100) NOT NULL,
`category_id` varchar(100) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)

31
scripts/import-github-discussions.mjs

@ -30,6 +30,10 @@ const getDiscussions = async ({ repo, query }) => { @@ -30,6 +30,10 @@ const getDiscussions = async ({ repo, query }) => {
id
title
url
category {
id
name
}
author {
avatarUrl
... on User {
@ -81,6 +85,8 @@ const formatDiscussion = ({ item, repo }) => ({ @@ -81,6 +85,8 @@ const formatDiscussion = ({ item, repo }) => ({
repo: repo,
body: item.body,
upvotes: item.upvoteCount,
category_id: item.category.id,
category_name: item.category.name,
created_at: dayjs(item.publishedAt).unix(),
updated_at: item.updatedAt ? dayjs(item.updatedAt).unix() : null
})
@ -125,16 +131,25 @@ const saveDiscussions = async ({ items, repo }) => { @@ -125,16 +131,25 @@ const saveDiscussions = async ({ items, repo }) => {
}
}
const importGithubDiscussions = async ({ repo }) => {
const importGithubDiscussions = async ({ repo, all = false }) => {
if (!repo) {
log('missing repo')
return
}
log(`importing discussions from ${repo}`)
// get latest updated_at from database
const rows = await db('github_discussions')
.where({ repo })
.orderBy('updated_at', 'desc')
.limit(1)
const lastUpdated = rows.length ? rows[0].updated_at : undefined
log(`last updated: ${lastUpdated}`)
let lastUpdated
if (all) {
log('importing all discussions')
} else {
const rows = await db('github_discussions')
.where({ repo })
.orderBy('updated_at', 'desc')
.limit(1)
lastUpdated = rows.length ? rows[0].updated_at : undefined
log(`importing discussions updated since: ${lastUpdated}`)
}
let result = {}
do {

24
src/views/components/github-discussion/github-discussion.js

@ -6,6 +6,9 @@ import Accordion from '@material-ui/core/Accordion' @@ -6,6 +6,9 @@ import Accordion from '@material-ui/core/Accordion'
import AccordionSummary from '@material-ui/core/AccordionSummary'
import AccordionDetails from '@material-ui/core/AccordionDetails'
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'
import OpenInNewIcon from '@material-ui/icons/OpenInNew'
import Box from '@material-ui/core/Box'
import Button from '@material-ui/core/Button'
import markdown from 'markdown-it'
import mdTasks from 'markdown-it-task-checkbox'
@ -16,6 +19,10 @@ import './github-discussion.styl' @@ -16,6 +19,10 @@ import './github-discussion.styl'
const md = markdown({ html: true }).use(mdTasks)
export default class GithubDiscussion extends React.Component {
handleClick = () => {
window.open(this.props.discussion.url, '_blank', 'noopener,noreferrer')
}
render() {
const { discussion } = this.props
@ -39,13 +46,7 @@ export default class GithubDiscussion extends React.Component { @@ -39,13 +46,7 @@ export default class GithubDiscussion extends React.Component {
return (
<Accordion elevation={2} className='github__discussion'>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<a
className='github__discussion-title'
href={discussion.url}
rel='noreferrer'
target='_blank'>
{discussion.title}
</a>
<div className='github__discussion-title'>{discussion.title}</div>
<div className='github__discussion-meta'>
<div>
{discussion.repo}#{discussion.ref}
@ -56,6 +57,15 @@ export default class GithubDiscussion extends React.Component { @@ -56,6 +57,15 @@ export default class GithubDiscussion extends React.Component {
{/* <GithubLabels labels={discussion.labels} /> */}
</AccordionSummary>
<AccordionDetails>
<Box style={{ flex: '0 0 100%' }}>
<Button
onClick={this.handleClick}
variant='outlined'
size='small'
endIcon={<OpenInNewIcon />}>
Github
</Button>
</Box>
<div
className='github__discussion-body markdown__content'
dangerouslySetInnerHTML={{ __html: html }}

4
src/views/components/github-discussion/github-discussion.styl

@ -18,8 +18,6 @@ @@ -18,8 +18,6 @@
word-wrap break-word
padding 14px 14px 0
cursor pointer
&:hover
color $nanoSoftBlue
.github__discussion-meta
font-family 'Roboto Mono', monospace
@ -34,4 +32,4 @@ @@ -34,4 +32,4 @@
margin-left 5px
.github__discussion-body
padding 0 16px
padding-top 16px

4
src/views/pages/roadmap/roadmap.styl

@ -25,6 +25,10 @@ @@ -25,6 +25,10 @@
min-height 48px
position relative
.MuiAccordionDetails-root
flex-wrap wrap
padding 0 30px
.roadmap__container .MuiCard-root
display flex
flex-direction column

Loading…
Cancel
Save