add link to yesterday's daily discussion

This commit is contained in:
keyan 2022-01-13 13:05:43 -06:00
parent cefd6793f8
commit 5a4c249a74
4 changed files with 32 additions and 0 deletions

View File

@ -398,6 +398,29 @@ export default {
return pin.position return pin.position
}, },
prior: async (item, args, { models }) => {
if (!item.pinId) {
return null
}
const prior = await models.item.findFirst({
where: {
pinId: item.pinId,
createdAt: {
lt: item.createdAt
}
},
orderBy: {
createdAt: 'desc'
}
})
if (!prior) {
return null
}
return prior.id
},
user: async (item, args, { models }) => user: async (item, args, { models }) =>
await models.user.findUnique({ where: { id: item.userId } }), await models.user.findUnique({ where: { id: item.userId } }),
ncomments: async (item, args, { models }) => { ncomments: async (item, args, { models }) => {

View File

@ -64,5 +64,6 @@ export default gql`
comments: [Item!]! comments: [Item!]!
path: String path: String
position: Int position: Int
prior: Int
} }
` `

View File

@ -70,6 +70,13 @@ export default function Item ({ item, rank, children }) {
<Link href={`/items/${item.id}`} passHref> <Link href={`/items/${item.id}`} passHref>
<a title={item.createdAt} className='text-reset'>{timeSince(new Date(item.createdAt))}</a> <a title={item.createdAt} className='text-reset'>{timeSince(new Date(item.createdAt))}</a>
</Link> </Link>
{item.prior &&
<>
<span> \ </span>
<Link href={`/items/${item.prior}`} passHref>
<a className='text-reset'>yesterday</a>
</Link>
</>}
</span> </span>
{canEdit && {canEdit &&
<> <>

View File

@ -72,6 +72,7 @@ export const ITEM_FULL = gql`
query Item($id: ID!) { query Item($id: ID!) {
item(id: $id) { item(id: $id) {
...ItemFields ...ItemFields
prior
position position
text text
comments { comments {