Download spectrum/api/queries/user/threadConnection.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/user/threadConnection.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/queries/user/threadConnection.js
-
curl -L -o threadConnection.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/user/threadConnection.js
1.92 kB
| // @flow | |
| import type { GraphQLContext } from '../../'; | |
| import type { DBUser } from 'shared/types'; | |
| import type { PaginationOptions } from '../../utils/paginate-arrays'; | |
| import { encode, decode } from '../../utils/base64'; | |
| const { | |
| getViewableThreadsByUser, | |
| getPublicThreadsByUser, | |
| getPublicParticipantThreadsByUser, | |
| getViewableParticipantThreadsByUser, | |
| } = require('../../models/thread'); | |
| export default ( | |
| { id }: DBUser, | |
| { | |
| first, | |
| after, | |
| kind, | |
| }: { ...PaginationOptions, kind: 'creator' | 'participant' }, | |
| { user }: GraphQLContext | |
| ) => { | |
| const currentUser = user; | |
| const cursor = decode(after); | |
| // Get the index from the encoded cursor, asdf234gsdf-2 => ["-2", "2"] | |
| const lastDigits = cursor.match(/-(\d+)$/); | |
| const lastThreadIndex = | |
| lastDigits && lastDigits.length > 0 && parseInt(lastDigits[1], 10); | |
| // if a logged in user is viewing the profile, handle logic to get viewable threads | |
| let getThreads; | |
| if (currentUser) { | |
| getThreads = | |
| kind === 'creator' | |
| ? // $FlowIssue | |
| getViewableThreadsByUser(id, currentUser.id, { | |
| first, | |
| after: lastThreadIndex, | |
| }) | |
| : // $FlowIssue | |
| getViewableParticipantThreadsByUser(id, currentUser.id, { | |
| first, | |
| after: lastThreadIndex, | |
| }); | |
| } else { | |
| getThreads = | |
| kind === 'creator' | |
| ? // $FlowIssue | |
| getPublicThreadsByUser(id, { first, after: lastThreadIndex }) | |
| : // $FlowIssue | |
| getPublicParticipantThreadsByUser(id, { | |
| first, | |
| after: lastThreadIndex, | |
| }); | |
| } | |
| return getThreads.then(result => ({ | |
| pageInfo: { | |
| // $FlowFixMe => super weird | |
| hasNextPage: result && result.length >= first, | |
| }, | |
| edges: result.map((thread, index) => ({ | |
| cursor: encode(`${thread.id}-${lastThreadIndex + index + 1}`), | |
| node: thread, | |
| })), | |
| })); | |
| }; | |