Skip to content

Commit

Permalink
uber rough first pass at mention autocompletes
Browse files Browse the repository at this point in the history
* support custom limit on topUsers query

* hot keys for selecting user suggestion in markdown input

* query top stackers for mentions with no search query

* refactor UserSuggestion to help with reusability

textarea-caret for placing the user suggest dropdown appropriately

other various code cleanup items to make it easier to use

off by one errors are fun!

various code cleanup and reuse the UserSuggest component in InputUserSuggest to reduce duplication
  • Loading branch information
SatsAllDay committed Oct 4, 2023
1 parent 362f95a commit bc39ec4
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 93 deletions.
18 changes: 9 additions & 9 deletions api/resolvers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default {
users
}
},
topUsers: async (parent, { cursor, when, by }, { models, me }) => {
topUsers: async (parent, { cursor, when, by, limit = LIMIT }, { models, me }) => {
const decodedCursor = decodeCursor(cursor)
let users

Expand Down Expand Up @@ -179,10 +179,10 @@ export default {
)
SELECT * FROM u WHERE ${column} > 0
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
LIMIT ${limit}`, decodedCursor.time, decodedCursor.offset)

return {
cursor: users.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
cursor: users.length === limit ? nextCursorEncoded(decodedCursor, limit) : null,
users
}
}
Expand All @@ -206,7 +206,7 @@ export default {
GROUP BY users.id, users.name
ORDER BY spent DESC NULLS LAST, users.created_at DESC
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
LIMIT ${limit}`, decodedCursor.time, decodedCursor.offset)
} else if (by === 'posts') {
users = await models.$queryRawUnsafe(`
SELECT users.*, count(*)::INTEGER as nposts
Expand All @@ -218,7 +218,7 @@ export default {
GROUP BY users.id
ORDER BY nposts DESC NULLS LAST, users.created_at DESC
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
LIMIT ${limit}`, decodedCursor.time, decodedCursor.offset)
} else if (by === 'comments') {
users = await models.$queryRawUnsafe(`
SELECT users.*, count(*)::INTEGER as ncomments
Expand All @@ -230,7 +230,7 @@ export default {
GROUP BY users.id
ORDER BY ncomments DESC NULLS LAST, users.created_at DESC
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
LIMIT ${limit}`, decodedCursor.time, decodedCursor.offset)
} else if (by === 'referrals') {
users = await models.$queryRawUnsafe(`
SELECT users.*, count(*)::INTEGER as referrals
Expand All @@ -242,7 +242,7 @@ export default {
GROUP BY users.id
ORDER BY referrals DESC NULLS LAST, users.created_at DESC
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
LIMIT ${limit}`, decodedCursor.time, decodedCursor.offset)
} else {
users = await models.$queryRawUnsafe(`
SELECT u.id, u.name, u.streak, u."photoId", u."hideCowboyHat", floor(sum(amount)/1000) as stacked
Expand All @@ -269,11 +269,11 @@ export default {
GROUP BY u.id, u.name, u.created_at, u."photoId", u.streak, u."hideCowboyHat"
ORDER BY stacked DESC NULLS LAST, created_at DESC
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
LIMIT ${limit}`, decodedCursor.time, decodedCursor.offset)
}

return {
cursor: users.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
cursor: users.length === limit ? nextCursorEncoded(decodedCursor, limit) : null,
users
}
},
Expand Down
2 changes: 1 addition & 1 deletion api/typeDefs/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default gql`
user(name: String!): User
users: [User!]
nameAvailable(name: String!): Boolean!
topUsers(cursor: String, when: String, by: String): Users
topUsers(cursor: String, when: String, by: String, limit: Int): Users
topCowboys(cursor: String): Users
searchUsers(q: String!, limit: Int, similarity: Float): [User!]!
hasNewNotes: Boolean!
Expand Down
Loading

0 comments on commit bc39ec4

Please sign in to comment.