fix: add check for when notifications is empty
This commit is contained in:
parent
799d7f3ad0
commit
de6fe78004
@ -427,7 +427,7 @@ const NotificationPopup: React.FC = ({ children }) => {
|
|||||||
onCompleted: (d) => {
|
onCompleted: (d) => {
|
||||||
setData((prev) => ({
|
setData((prev) => ({
|
||||||
hasNextPage: d.notified.pageInfo.hasNextPage,
|
hasNextPage: d.notified.pageInfo.hasNextPage,
|
||||||
cursor: d.notified.pageInfo.endCursor,
|
cursor: d.notified.pageInfo.endCursor ?? '',
|
||||||
nodes: [...prev.nodes, ...d.notified.notified],
|
nodes: [...prev.nodes, ...d.notified.notified],
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
@ -482,7 +482,7 @@ const NotificationPopup: React.FC = ({ children }) => {
|
|||||||
updateQuery: (prev, { fetchMoreResult }) => {
|
updateQuery: (prev, { fetchMoreResult }) => {
|
||||||
if (!fetchMoreResult) return prev;
|
if (!fetchMoreResult) return prev;
|
||||||
setData((d) => ({
|
setData((d) => ({
|
||||||
cursor: fetchMoreResult.notified.pageInfo.endCursor,
|
cursor: fetchMoreResult.notified.pageInfo.endCursor ?? '',
|
||||||
hasNextPage: fetchMoreResult.notified.pageInfo.hasNextPage,
|
hasNextPage: fetchMoreResult.notified.pageInfo.hasNextPage,
|
||||||
nodes: [...d.nodes, ...fetchMoreResult.notified.notified],
|
nodes: [...d.nodes, ...fetchMoreResult.notified.notified],
|
||||||
}));
|
}));
|
||||||
|
@ -894,7 +894,7 @@ export type OwnersList = {
|
|||||||
|
|
||||||
export type PageInfo = {
|
export type PageInfo = {
|
||||||
__typename?: 'PageInfo';
|
__typename?: 'PageInfo';
|
||||||
endCursor: Scalars['String'];
|
endCursor?: Maybe<Scalars['String']>;
|
||||||
hasNextPage: Scalars['Boolean'];
|
hasNextPage: Scalars['Boolean'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,15 +149,20 @@ SELECT notified_id, nn.notification_id, nn.user_id, read, read_at, n.notificatio
|
|||||||
LEFT JOIN user_account ON user_account.user_id = n.caused_by
|
LEFT JOIN user_account ON user_account.user_id = n.caused_by
|
||||||
WHERE (n.created_on, n.notification_id) < ($1::timestamptz, $2::uuid)
|
WHERE (n.created_on, n.notification_id) < ($1::timestamptz, $2::uuid)
|
||||||
AND nn.user_id = $3::uuid
|
AND nn.user_id = $3::uuid
|
||||||
|
AND ($4::boolean = false OR nn.read = false)
|
||||||
|
AND ($5::boolean = false OR n.action_type = ANY($6::text[]))
|
||||||
ORDER BY n.created_on DESC
|
ORDER BY n.created_on DESC
|
||||||
LIMIT $4::int
|
LIMIT $7::int
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetNotificationsForUserIDCursorParams struct {
|
type GetNotificationsForUserIDCursorParams struct {
|
||||||
CreatedOn time.Time `json:"created_on"`
|
CreatedOn time.Time `json:"created_on"`
|
||||||
NotificationID uuid.UUID `json:"notification_id"`
|
NotificationID uuid.UUID `json:"notification_id"`
|
||||||
UserID uuid.UUID `json:"user_id"`
|
UserID uuid.UUID `json:"user_id"`
|
||||||
LimitRows int32 `json:"limit_rows"`
|
EnableUnread bool `json:"enable_unread"`
|
||||||
|
EnableActionType bool `json:"enable_action_type"`
|
||||||
|
ActionType []string `json:"action_type"`
|
||||||
|
LimitRows int32 `json:"limit_rows"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetNotificationsForUserIDCursorRow struct {
|
type GetNotificationsForUserIDCursorRow struct {
|
||||||
@ -190,6 +195,9 @@ func (q *Queries) GetNotificationsForUserIDCursor(ctx context.Context, arg GetNo
|
|||||||
arg.CreatedOn,
|
arg.CreatedOn,
|
||||||
arg.NotificationID,
|
arg.NotificationID,
|
||||||
arg.UserID,
|
arg.UserID,
|
||||||
|
arg.EnableUnread,
|
||||||
|
arg.EnableActionType,
|
||||||
|
pq.Array(arg.ActionType),
|
||||||
arg.LimitRows,
|
arg.LimitRows,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -39,5 +39,7 @@ SELECT * FROM notification_notified AS nn
|
|||||||
LEFT JOIN user_account ON user_account.user_id = n.caused_by
|
LEFT JOIN user_account ON user_account.user_id = n.caused_by
|
||||||
WHERE (n.created_on, n.notification_id) < (@created_on::timestamptz, @notification_id::uuid)
|
WHERE (n.created_on, n.notification_id) < (@created_on::timestamptz, @notification_id::uuid)
|
||||||
AND nn.user_id = @user_id::uuid
|
AND nn.user_id = @user_id::uuid
|
||||||
|
AND (@enable_unread::boolean = false OR nn.read = false)
|
||||||
|
AND (@enable_action_type::boolean = false OR n.action_type = ANY(@action_type::text[]))
|
||||||
ORDER BY n.created_on DESC
|
ORDER BY n.created_on DESC
|
||||||
LIMIT @limit_rows::int;
|
LIMIT @limit_rows::int;
|
||||||
|
@ -3295,7 +3295,7 @@ input NotifiedInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PageInfo {
|
type PageInfo {
|
||||||
endCursor: String!
|
endCursor: String
|
||||||
hasNextPage: Boolean!
|
hasNextPage: Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13127,14 +13127,11 @@ func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graph
|
|||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
if resTmp == nil {
|
if resTmp == nil {
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(string)
|
res := resTmp.(*string)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *PageInfo) (ret graphql.Marshaler) {
|
func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *PageInfo) (ret graphql.Marshaler) {
|
||||||
@ -22809,9 +22806,6 @@ func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet,
|
|||||||
out.Values[i] = graphql.MarshalString("PageInfo")
|
out.Values[i] = graphql.MarshalString("PageInfo")
|
||||||
case "endCursor":
|
case "endCursor":
|
||||||
out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj)
|
out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj)
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
invalids++
|
|
||||||
}
|
|
||||||
case "hasNextPage":
|
case "hasNextPage":
|
||||||
out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj)
|
out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj)
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
|
@ -405,8 +405,8 @@ type OwnersList struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PageInfo struct {
|
type PageInfo struct {
|
||||||
EndCursor string `json:"endCursor"`
|
EndCursor *string `json:"endCursor"`
|
||||||
HasNextPage bool `json:"hasNextPage"`
|
HasNextPage bool `json:"hasNextPage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfileIcon struct {
|
type ProfileIcon struct {
|
||||||
|
@ -163,11 +163,30 @@ func (r *queryResolver) Notified(ctx context.Context, input NotifiedInput) (*Not
|
|||||||
log.WithError(err).Error("error decoding cursor")
|
log.WithError(err).Error("error decoding cursor")
|
||||||
return &NotifiedResult{}, err
|
return &NotifiedResult{}, err
|
||||||
}
|
}
|
||||||
|
enableRead := false
|
||||||
|
enableActionType := false
|
||||||
|
actionTypes := []string{}
|
||||||
|
switch input.Filter {
|
||||||
|
case NotificationFilterUnread:
|
||||||
|
enableRead = true
|
||||||
|
break
|
||||||
|
case NotificationFilterMentioned:
|
||||||
|
enableActionType = true
|
||||||
|
actionTypes = []string{"COMMENT_MENTIONED"}
|
||||||
|
break
|
||||||
|
case NotificationFilterAssigned:
|
||||||
|
enableActionType = true
|
||||||
|
actionTypes = []string{"TASK_ASSIGNED"}
|
||||||
|
break
|
||||||
|
}
|
||||||
n, err := r.Repository.GetNotificationsForUserIDCursor(ctx, db.GetNotificationsForUserIDCursorParams{
|
n, err := r.Repository.GetNotificationsForUserIDCursor(ctx, db.GetNotificationsForUserIDCursorParams{
|
||||||
CreatedOn: t,
|
CreatedOn: t,
|
||||||
NotificationID: id,
|
NotificationID: id,
|
||||||
LimitRows: int32(input.Limit + 1),
|
LimitRows: int32(input.Limit + 1),
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
EnableUnread: enableRead,
|
||||||
|
EnableActionType: enableActionType,
|
||||||
|
ActionType: actionTypes,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("error decoding fetching notifications")
|
log.WithError(err).Error("error decoding fetching notifications")
|
||||||
@ -180,11 +199,14 @@ func (r *queryResolver) Notified(ctx context.Context, input NotifiedInput) (*Not
|
|||||||
"cursorId": id,
|
"cursorId": id,
|
||||||
"limit": input.Limit,
|
"limit": input.Limit,
|
||||||
}).Info("fetched notified")
|
}).Info("fetched notified")
|
||||||
endCursor := n[len(n)-1]
|
var endCursor *db.GetNotificationsForUserIDCursorRow
|
||||||
if len(n) == input.Limit+1 {
|
if len(n) != 0 {
|
||||||
hasNextPage = true
|
endCursor = &n[len(n)-1]
|
||||||
n = n[:len(n)-1]
|
if len(n) == input.Limit+1 {
|
||||||
endCursor = n[len(n)-1]
|
hasNextPage = true
|
||||||
|
n = n[:len(n)-1]
|
||||||
|
endCursor = &n[len(n)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
userNotifications := []Notified{}
|
userNotifications := []Notified{}
|
||||||
for _, notified := range n {
|
for _, notified := range n {
|
||||||
@ -206,9 +228,14 @@ func (r *queryResolver) Notified(ctx context.Context, input NotifiedInput) (*Not
|
|||||||
}
|
}
|
||||||
userNotifications = append(userNotifications, n)
|
userNotifications = append(userNotifications, n)
|
||||||
}
|
}
|
||||||
|
var endCursorEncoded *string
|
||||||
|
if endCursor != nil {
|
||||||
|
eCur := utils.EncodeCursor(endCursor.CreatedOn, endCursor.NotificationID)
|
||||||
|
endCursorEncoded = &eCur
|
||||||
|
}
|
||||||
pageInfo := &PageInfo{
|
pageInfo := &PageInfo{
|
||||||
HasNextPage: hasNextPage,
|
HasNextPage: hasNextPage,
|
||||||
EndCursor: utils.EncodeCursor(endCursor.CreatedOn, endCursor.NotificationID),
|
EndCursor: endCursorEncoded,
|
||||||
}
|
}
|
||||||
log.WithField("pageInfo", pageInfo).Info("created page info")
|
log.WithField("pageInfo", pageInfo).Info("created page info")
|
||||||
return &NotifiedResult{
|
return &NotifiedResult{
|
||||||
@ -249,11 +276,14 @@ func (r *queryResolver) Notified(ctx context.Context, input NotifiedInput) (*Not
|
|||||||
"nLen": len(n),
|
"nLen": len(n),
|
||||||
"limit": input.Limit,
|
"limit": input.Limit,
|
||||||
}).Info("fetched notified")
|
}).Info("fetched notified")
|
||||||
endCursor := n[len(n)-1]
|
var endCursor *db.GetNotificationsForUserIDPagedRow
|
||||||
if len(n) == input.Limit+1 {
|
if len(n) != 0 {
|
||||||
hasNextPage = true
|
endCursor = &n[len(n)-1]
|
||||||
n = n[:len(n)-1]
|
if len(n) == input.Limit+1 {
|
||||||
endCursor = n[len(n)-1]
|
hasNextPage = true
|
||||||
|
n = n[:len(n)-1]
|
||||||
|
endCursor = &n[len(n)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
userNotifications := []Notified{}
|
userNotifications := []Notified{}
|
||||||
for _, notified := range n {
|
for _, notified := range n {
|
||||||
@ -275,9 +305,14 @@ func (r *queryResolver) Notified(ctx context.Context, input NotifiedInput) (*Not
|
|||||||
}
|
}
|
||||||
userNotifications = append(userNotifications, n)
|
userNotifications = append(userNotifications, n)
|
||||||
}
|
}
|
||||||
|
var endCursorEncoded *string
|
||||||
|
if endCursor != nil {
|
||||||
|
eCur := utils.EncodeCursor(endCursor.CreatedOn, endCursor.NotificationID)
|
||||||
|
endCursorEncoded = &eCur
|
||||||
|
}
|
||||||
pageInfo := &PageInfo{
|
pageInfo := &PageInfo{
|
||||||
HasNextPage: hasNextPage,
|
HasNextPage: hasNextPage,
|
||||||
EndCursor: utils.EncodeCursor(endCursor.CreatedOn, endCursor.NotificationID),
|
EndCursor: endCursorEncoded,
|
||||||
}
|
}
|
||||||
log.WithField("pageInfo", pageInfo).Info("created page info")
|
log.WithField("pageInfo", pageInfo).Info("created page info")
|
||||||
return &NotifiedResult{
|
return &NotifiedResult{
|
||||||
|
@ -26,7 +26,7 @@ input NotifiedInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PageInfo {
|
type PageInfo {
|
||||||
endCursor: String!
|
endCursor: String
|
||||||
hasNextPage: Boolean!
|
hasNextPage: Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ input NotifiedInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PageInfo {
|
type PageInfo {
|
||||||
endCursor: String!
|
endCursor: String
|
||||||
hasNextPage: Boolean!
|
hasNextPage: Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user