Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 261cfd4

Browse files
committed
Show entire goal on the panel
1 parent 3373dbf commit 261cfd4

File tree

8 files changed

+78
-176
lines changed

8 files changed

+78
-176
lines changed

src/adapters/fauna/clear-db.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ async function main() {
3939
q.Paginate(q.Documents(q.Collection('goal_updates'))),
4040
(goalUpdate) => q.Delete(goalUpdate)
4141
)
42+
q.Map(
43+
q.Paginate(q.Documents(q.Collection('goal_likes'))),
44+
(goalUpdate) => q.Delete(goalUpdate)
45+
)
46+
q.Map(
47+
q.Paginate(q.Documents(q.Collection('update_comments'))),
48+
(goalUpdate) => q.Delete(goalUpdate)
49+
)
4250
)
4351
)
4452
}

src/adapters/fauna/shell.mjs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ const client = new faunadb.Client({
99
})
1010

1111
async function main() {
12-
const goalId = '290932327237812736'
13-
const response = await client.query(
14-
q.Map(q.Paginate(q.Documents(q.Collection('goals'))), (goalRef) =>
15-
q.Select(['ref', 'id'], q.Get(goalRef))
16-
)
17-
)
12+
const response = client.query(q.Do())
1813
console.log(JSON.stringify(response, null, 2))
1914
}
2015

src/components/HomePageFeed.tsx

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
UpdateComments,
3030
UpdateCommentsList,
3131
} from '@/components'
32+
import { Goal } from './goals'
33+
import type { GoalResponse } from 'src/pages/[username]'
3234

3335
type LikeData = {
3436
count: number
@@ -59,7 +61,7 @@ export function HomePageFeedUpdate({
5961
update: HomePageFeedUpdateType
6062
setGoalId: () => void
6163
}) {
62-
const [session, loading] = useSession()
64+
const [session] = useSession()
6365
const [showComments, setShowComments] = useState(false)
6466
const { postedBy, createdAt: createdAtInMillis, goal, description } = update
6567
const createdAt = DateTime.fromMillis(createdAtInMillis)
@@ -417,7 +419,7 @@ function FollowButton({ user }: { user: User }) {
417419

418420
function HomePageAside({ goalId }: { goalId: string }) {
419421
const [session] = useSession()
420-
const { isLoading, isError, data: response } = useQuery(
422+
const { isLoading, isError, data } = useQuery(
421423
['/api/fauna/recent-updates', goalId],
422424
() =>
423425
fetch(`/api/fauna/recent-updates`, {
@@ -443,62 +445,38 @@ function HomePageAside({ goalId }: { goalId: string }) {
443445
return fetch(`/api/fauna/who-to-follow`).then((res) => res.json())
444446
})
445447

446-
const shouldShowRecentUpdates = Boolean(goalId) && goalId !== ''
448+
const shouldShowRecentUpdates =
449+
Boolean(goalId) && goalId !== '' && !isLoading && !isError
450+
const goal: GoalResponse = data?.response ?? {}
447451

448452
return (
449453
<>
450454
<div className="sticky top-4 space-y-4">
451455
{shouldShowRecentUpdates && (
452-
<section aria-labelledby="trending-heading">
456+
<section
457+
aria-labelledby="trending-heading"
458+
className="h-100 overflow-y-auto"
459+
>
453460
<div className="bg-white rounded-lg shadow">
454461
<div className="p-6">
455-
<h2
456-
id="trending-heading"
457-
className="text-base font-medium text-gray-900"
458-
>
459-
All Updates
460-
</h2>
461-
<div className="mt-6 flow-root">
462-
<ul className="-my-4 divide-y divide-gray-200">
463-
{!isLoading &&
464-
!isError &&
465-
response.updates.map((update) => (
466-
<li className="flex py-4 space-x-3" key={update.id}>
467-
<div className="flex-shrink-0">
468-
<img
469-
className="h-8 w-8 rounded-full"
470-
src={update.postedBy.image}
471-
alt=""
472-
/>
473-
</div>
474-
<div className="min-w-0 flex-1">
475-
<div className="prose prose-sm max-w-none">
476-
<Markdown>{update.description}</Markdown>
477-
</div>
478-
</div>
479-
</li>
480-
))}
481-
</ul>
482-
</div>
483-
{session ? (
484-
<div className="mt-6">
485-
<A
486-
href={`/${response?.updates?.[0].postedBy.username}`}
487-
className="w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
488-
>
489-
View all
490-
</A>
491-
</div>
492-
) : (
493-
<div className="mt-6">
494-
<button
495-
onClick={() => signIn('github')}
496-
className="w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
497-
>
498-
Join
499-
</button>
500-
</div>
501-
)}
462+
<Goal.Title createdBy={goal.createdBy} showEditButton={false}>
463+
{goal.title}
464+
</Goal.Title>
465+
<Goal.Description>{goal.description}</Goal.Description>
466+
<Goal.Updates>
467+
<Goal.UpdatesList>
468+
{goal.updates.data.map((update, index) => (
469+
<Goal.Update
470+
postedBy={update.postedBy}
471+
key={update.id}
472+
postedOn={DateTime.fromMillis(update.createdAt)}
473+
isLastUpdate={index === goal.updates.data.length - 1}
474+
>
475+
{update.description}
476+
</Goal.Update>
477+
))}
478+
</Goal.UpdatesList>
479+
</Goal.Updates>
502480
</div>
503481
</div>
504482
</section>

src/components/goals/GoalTitle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { Button } from '@/ui'
66
export default function GoalTitle({
77
children,
88
createdBy,
9-
onEditClick,
9+
onEditClick = () => {},
1010
showEditButton,
1111
}: {
1212
children: string
1313
createdBy: User
14-
onEditClick: () => void
14+
onEditClick?: () => void
1515
showEditButton: boolean
1616
}) {
1717
return (

src/components/goals/NewUpdate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default function NewUpdate({
5151
])
5252
if (updateFromHomePage) {
5353
queryClient.refetchQueries('/api/fauna/all-updates')
54+
queryClient.refetchQueries(['/api/fauna/recent-updates', goal.id])
5455
}
5556
reset()
5657
},

src/pages/[username]/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Update = {
2222
postedBy: User
2323
}
2424

25-
type GoalResponse = {
25+
export type GoalResponse = {
2626
id: string
2727
title: string
2828
description: string
@@ -108,7 +108,7 @@ export default function UserProfile({
108108
<Goal.UpdatesList>
109109
{goalResponse.updates.data.map((update, index) => (
110110
<Goal.Update
111-
postedBy={user}
111+
postedBy={update.postedBy}
112112
key={update.id}
113113
postedOn={DateTime.fromMillis(update.createdAt)}
114114
isLastUpdate={

src/pages/api/fauna/recent-updates.ts

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -23,85 +23,43 @@ const FaunaCreateHandler: NextApiHandler = async (
2323

2424
try {
2525
const { goalId } = req.body
26-
console.log({ goalId })
27-
const response: any = await client.query(
28-
q.Map(
29-
q.Paginate(
30-
q.Match(
31-
q.Index('all_updates_by_goal'),
32-
q.Ref(q.Collection('goals'), goalId)
26+
const goalRef = q.Ref(q.Collection('goals'), goalId)
27+
const goalDoc = q.Get(goalRef)
28+
const goalCreatedByDoc = q.Get(q.Select(['data', 'createdBy'], goalDoc))
29+
const response: any = await client.query({
30+
id: q.Select(['ref', 'id'], goalDoc),
31+
title: q.Select(['data', 'title'], goalDoc),
32+
description: q.Select(['data', 'description'], goalDoc),
33+
createdAt: q.ToMillis(
34+
q.Select(['data', 'timestamps', 'createdAt'], goalDoc, 0)
35+
),
36+
createdBy: {
37+
id: q.Select(['ref', 'id'], goalCreatedByDoc),
38+
name: q.Select(['data', 'name'], goalCreatedByDoc, null),
39+
username: q.Select(['data', 'username'], goalCreatedByDoc, null),
40+
account: {
41+
firstName: q.Select(
42+
['data', 'account', 'firstName'],
43+
goalCreatedByDoc,
44+
null
3345
),
34-
{
35-
size: 3,
36-
}
37-
),
38-
(goalUpdateRef) => {
39-
const goalUpdateDoc = q.Get(goalUpdateRef)
40-
const goalDoc = q.Get(q.Select(['data', 'goal'], goalUpdateDoc))
41-
const postedByDoc = q.Get(
42-
q.Select(['data', 'postedBy'], goalUpdateDoc)
43-
)
44-
const description = q.Select(['data', 'description'], goalUpdateDoc)
45-
46-
const createdAt = q.ToMillis(
47-
q.Select(['data', 'timestamps', 'createdAt'], goalUpdateDoc)
48-
)
46+
},
47+
},
48+
updates: q.Map(
49+
q.Paginate(q.Match(q.Index('all_updates_by_goal'), goalRef)),
50+
(updateRef) => {
51+
const updateDoc = q.Get(updateRef)
52+
const postedByDoc = q.Get(q.Select(['data', 'postedBy'], updateDoc))
4953
return {
50-
id: q.Select(['ref', 'id'], goalUpdateDoc),
51-
goal: {
52-
id: q.Select(['ref', 'id'], goalDoc),
53-
title: q.Select(['data', 'title'], goalDoc),
54-
},
55-
commentsCount: q.Count(
56-
q.Match(q.Index('all_comments_by_update'), goalUpdateRef)
54+
id: q.Select(['ref', 'id'], updateDoc),
55+
description: q.Select(['data', 'description'], updateDoc),
56+
createdAt: q.ToMillis(
57+
q.Select(['data', 'timestamps', 'createdAt'], updateDoc, 0)
5758
),
58-
comments: q.Map(
59-
q.Paginate(
60-
q.Match(q.Index('all_comments_by_update'), goalUpdateRef)
61-
),
62-
(commentRef) => {
63-
const commentDoc = q.Get(commentRef)
64-
const postedByDoc = q.Get(
65-
q.Select(['data', 'postedBy'], commentDoc)
66-
)
67-
return {
68-
id: q.Select(['ref', 'id'], commentDoc),
69-
description: q.Select(['data', 'description'], commentDoc),
70-
createdAt: q.ToMillis(
71-
q.Select(['data', 'timestamps', 'createdAt'], commentDoc)
72-
),
73-
postedBy: {
74-
id: q.Select(['ref', 'id'], postedByDoc),
75-
name: q.Select(['data', 'name'], postedByDoc, null),
76-
image: q.Select(['data', 'image'], postedByDoc, null),
77-
username: q.Select(['data', 'username'], postedByDoc, null),
78-
account: {
79-
firstName: q.Select(
80-
['data', 'account', 'firstName'],
81-
postedByDoc,
82-
null
83-
),
84-
},
85-
},
86-
}
87-
}
88-
),
89-
likes: q.Count(
90-
q.Filter(
91-
q.Paginate(
92-
q.Match(q.Index('all_likes_by_update'), goalUpdateRef)
93-
),
94-
(updateLikeRef) => {
95-
return q.Select(['data', 'liked'], q.Get(updateLikeRef))
96-
}
97-
)
98-
),
99-
description,
100-
createdAt,
10159
postedBy: {
10260
id: q.Select(['ref', 'id'], postedByDoc),
103-
name: q.Select(['data', 'name'], postedByDoc, null),
10461
image: q.Select(['data', 'image'], postedByDoc, null),
62+
name: q.Select(['data', 'name'], postedByDoc, null),
10563
username: q.Select(['data', 'username'], postedByDoc, null),
10664
account: {
10765
firstName: q.Select(
@@ -113,10 +71,9 @@ const FaunaCreateHandler: NextApiHandler = async (
11371
},
11472
}
11573
}
116-
)
117-
)
118-
119-
res.status(200).json({ updates: response.data })
74+
),
75+
})
76+
res.status(200).json({ response })
12077
} catch (error) {
12178
console.error({ msg: error.message })
12279
res.status(500).json({ message: error.message })

tailwind.config.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
extend: {
1818
spacing: {
1919
13: '3.25rem',
20+
100: '25rem',
2021
},
2122
colors: {
2223
blueGray: colors.blueGray,
@@ -39,41 +40,3 @@ module.exports = {
3940
require('nightwind'),
4041
],
4142
}
42-
43-
/**
44-
* === Already Included Colors ===
45-
* gray: coolGray
46-
* red: red
47-
* yellow: amber
48-
* green: emerald
49-
* blue: blue
50-
* indigo: indigo
51-
* purple: violet
52-
* pink: pink
53-
*/
54-
55-
/**
56-
* === All Colors ===
57-
* blueGray
58-
* coolGray
59-
* gray
60-
* trueGray
61-
* warnGray
62-
* red
63-
* orange
64-
* amber
65-
* yellow
66-
* lime
67-
* green
68-
* emerald
69-
* teal
70-
* cyan
71-
* lightBlue
72-
* blue
73-
* indigo
74-
* violet
75-
* purple
76-
* fuchsia
77-
* pink
78-
* rose
79-
*/

0 commit comments

Comments
 (0)