Skip to content

Commit 225254d

Browse files
committed
copilot feedback
1 parent 802b089 commit 225254d

7 files changed

Lines changed: 30 additions & 17 deletions

File tree

android/app/src/main/java/com/dkhalife/tasks/ui/screen/TaskListScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Spacer
1212
import androidx.compose.foundation.layout.fillMaxSize
1313
import androidx.compose.foundation.layout.fillMaxWidth
1414
import androidx.compose.foundation.layout.height
15+
import androidx.compose.foundation.layout.width
1516
import androidx.compose.foundation.layout.padding
1617
import androidx.compose.foundation.layout.size
1718
import androidx.compose.foundation.lazy.LazyColumn
@@ -107,7 +108,7 @@ fun TaskListScreen(
107108
tint = MaterialTheme.colorScheme.onErrorContainer,
108109
modifier = Modifier.size(18.dp)
109110
)
110-
Spacer(modifier = Modifier.height(8.dp))
111+
Spacer(modifier = Modifier.width(8.dp))
111112
Text(
112113
text = stringResource(R.string.settings_section_account_deletion),
113114
style = MaterialTheme.typography.bodySmall,

apiserver/internal/repos/user/user.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
)
1313

1414
var ErrDisabledUser = errors.New("account is disabled")
15-
var ErrPendingDeletion = errors.New("account is pending deletion")
1615

1716
type IUserRepo interface {
1817
CreateUser(c context.Context, user *models.User) error

apiserver/internal/repos/user/user_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ func (s *UserTestSuite) TestDeleteUser_CascadesAllUserData() {
404404

405405
func (s *UserTestSuite) assertRowCount(table string, userID int, expected int) {
406406
var count int64
407-
s.DB.Table(table).Where("id = ?", userID).Count(&count)
407+
column := "id"
408+
if table == "labels" {
409+
column = "created_by"
410+
}
411+
s.DB.Table(table).Where(column+" = ?", userID).Count(&count)
408412
s.Equal(int64(expected), count, "expected %d row(s) in %s for user %d", expected, table, userID)
409413
}
410414

apiserver/internal/services/users/user.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package users
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"time"
78

@@ -67,6 +68,7 @@ func (s *UserService) RequestDeletion(ctx context.Context, userID int) (int, int
6768
}
6869
}
6970

71+
s.ws.SetPendingDeletionForUser(userID, true)
7072
s.ws.BroadcastToUser(userID, ws.WSResponse{
7173
Action: "account_deletion_requested",
7274
Data: gin.H{},
@@ -85,6 +87,7 @@ func (s *UserService) CancelDeletion(ctx context.Context, userID int) (int, inte
8587
}
8688
}
8789

90+
s.ws.SetPendingDeletionForUser(userID, false)
8891
s.ws.BroadcastToUser(userID, ws.WSResponse{
8992
Action: "account_deletion_cancelled",
9093
Data: gin.H{},
@@ -102,11 +105,11 @@ func (s *UserService) ProcessDeletions(ctx context.Context) error {
102105
}
103106

104107
for _, user := range users {
105-
log.Infof("deleting account for user %d (requested at %s)", user.ID, user.DeletionRequestedAt)
108+
log.Infof("deleting account for user %d (requested at %v)", user.ID, user.DeletionRequestedAt)
106109
if err := s.r.DeleteUser(ctx, user.ID); err != nil {
107110
log.Errorf("failed to delete user %d: %s", user.ID, err.Error())
108111
telemetry.TrackError(ctx, "account_deletion_failed", "user-service", err, map[string]string{
109-
"user_id": string(rune(user.ID)),
112+
"user_id": fmt.Sprint(user.ID),
110113
})
111114
}
112115
}

apiserver/internal/ws/server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,16 @@ func (s *WSServer) BroadcastToUser(userID int, resp WSResponse) {
296296
}
297297
}()
298298
}
299+
300+
// SetPendingDeletionForUser updates the PendingDeletion flag on all active
301+
// connections for a user so the WS write-guard reflects current deletion state
302+
// without requiring a reconnect.
303+
func (s *WSServer) SetPendingDeletionForUser(userID int, pending bool) {
304+
s.mu.RLock()
305+
conns := s.userConnections[userID]
306+
s.mu.RUnlock()
307+
308+
for _, c := range conns {
309+
c.identity.PendingDeletion = pending
310+
}
311+
}

frontend/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AppDispatch, store } from './store/store'
1111
import { connect } from 'react-redux'
1212
import { fetchUser } from './store/userSlice'
1313
import { StatusList } from './components/StatusList'
14-
import { DeletionBannerWrapper } from './components/DeletionBanner'
14+
import { DeletionBanner } from './components/DeletionBanner'
1515
import { fetchTasks, initGroups } from './store/tasksSlice'
1616
import { FIVE_MINUTES_MS } from '@/constants/time'
1717

@@ -126,7 +126,7 @@ class AppImpl extends React.Component<AppProps> {
126126
<NavBar
127127
pathname={pathname}
128128
/>
129-
<DeletionBannerWrapper />
129+
<DeletionBanner />
130130
<Outlet />
131131
<StatusList />
132132
</CssVarsProvider>

frontend/src/components/DeletionBanner.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React from 'react'
22
import { Alert, Button, Typography } from '@mui/joy'
33
import { WarningAmberRounded } from '@mui/icons-material'
44
import { connect } from 'react-redux'
5+
import { Link } from 'react-router-dom'
56
import { AppDispatch, RootState } from '@/store/store'
67
import { cancelAccountDeletion } from '@/store/userSlice'
78
import { NavigationPaths } from '@/utils/navigation'
8-
import { useNavigate } from 'react-router-dom'
99

1010
type DeletionBannerProps = {
1111
deletionRequestedAt: string | null
@@ -46,9 +46,9 @@ class DeletionBannerImpl extends React.Component<DeletionBannerProps> {
4646
Your account is scheduled for deletion on{' '}
4747
<strong>{this.formatDeletionTime(deletionRequestedAt)}</strong>.
4848
Writes are disabled. Visit{' '}
49-
<a href={NavigationPaths.Settings} style={{ color: 'inherit' }}>
49+
<Link to={NavigationPaths.Settings} style={{ color: 'inherit' }}>
5050
Settings
51-
</a>{' '}
51+
</Link>{' '}
5252
to manage this.
5353
</Typography>
5454
</Alert>
@@ -69,10 +69,3 @@ export const DeletionBanner = connect(
6969
mapStateToProps,
7070
mapDispatchToProps,
7171
)(DeletionBannerImpl)
72-
73-
// Functional wrapper needed to access useNavigate hook
74-
export const DeletionBannerWrapper: React.FC = () => {
75-
const navigate = useNavigate()
76-
void navigate // referenced to avoid unused warning
77-
return <DeletionBanner />
78-
}

0 commit comments

Comments
 (0)