Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RefreshItem to refresh an element in list #124

Conversation

GalihFajar
Copy link

@GalihFajar GalihFajar commented Oct 26, 2023

Description:

Fixes #99

I think only two places that Refresh should be replaced with RefreshItem, otherwise the other Refreshes logics are used as intended.

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

@GalihFajar GalihFajar changed the base branch from main to next October 26, 2023 08:47
Copy link
Owner

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I am however not sure that this is the right solution. The change to d.list.RefreshItem(i) in this case breaks removal of items. The refresh calls on lines 28 to 42 in recv.go and line 34 in send.go are the ones that need to be updated. However, it would require keeping track of the index so it is a bit complicated to get right (especially with indexes changing when we remove items).

Comment on lines +196 to +208
func (d *SendData) OnMultiFilesSelect(file fyne.URIReadCloser, err error) {
if err != nil {
fyne.LogError("Error on selecting file to send", err)
dialog.ShowError(err, d.Window)
return
} else if file == nil {
return
}

fmt.Println("uris before:", d.Uris)
d.Uris = append(d.Uris, file.URI())
fmt.Println("uris after:", d.Uris)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this supposed to be here?

@@ -43,6 +44,7 @@ type SendData struct {
Client *transport.Client
Window fyne.Window
Canvas fyne.Canvas
Uris []fyne.URI
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems like it shouldn't be here.

@@ -93,7 +93,7 @@ func (d *RecvData) OnSelected(i int) {
d.items[len(d.items)-1] = nil // Allow the GC to reclaim memory.
d.items = d.items[:len(d.items)-1]

d.list.Refresh()
d.list.RefreshItem(i)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but this doesn't work. In this case we are changing the whole slice due to deletion and want to refresh everything.

@@ -119,7 +121,7 @@ func (d *SendData) OnSelected(i int) {
d.items[len(d.items)-1] = nil // Allow the GC to reclaim memory.
d.items = d.items[:len(d.items)-1]

d.list.Refresh()
d.list.RefreshItem(i)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here. We can't use RefreshItem() because we modify the whole slice.

@GalihFajar
Copy link
Author

Closing this PR

@GalihFajar GalihFajar closed this Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make use of new List widget item refresh
2 participants