davidhealey / waistline

Libre calorie counter app for Android. Built with Cordova.
568 stars 67 forks source link

filtering in food item list stops working #89

Closed corngood closed 5 years ago

corngood commented 5 years ago

I'm using 2.3.7.

Some time today, the food item list stopped filtering when I enter text into the search box. If I remove all user data and start a new food list it works. In that case the list refreshes (check boxes flicker, and it filters) on every key press.

With my full food items list (~80 items) the only time the list updates is when I delete the last character from the search box. I can enter any text, but nothing happens to the list until I delete all of it. When I delete the last character, the order of the items sometimes changes and duplicate items occasionally show up. Filtering on recipes still works.

I tried clearing the cache.

I tried reinstalling the app and restoring data with titanium backup.

I tried removing some recently added items from the food list.

None of those things changed the behaviour.

I wanted to try restoring from an export, but nothing happens when I click the import button.

Do you think it would be useful to look in the ADB log?

davidhealey commented 5 years ago

Hi,

This sounds like a strange one. Do any of your food items have unusual characters in their name?

The import not working is a big problem. I haven't tested it for a while so I'll check it out.

Yes a look at the log might reveal the source of the problem.

corngood commented 5 years ago

Here's what I get in logcat each time I enter a character into the search box:

11-10 09:24:22.190 31218 31218 D SystemWebChromeClient: file:///android_asset/www/activities/food-list/js/food-list.js: Line 56 : Uncaught TypeError: Cannot read property 'match' of undefined
11-10 09:24:22.190 31218 31218 I chromium: [INFO:CONSOLE(56)] "Uncaught TypeError: Cannot read property 'match' of undefined", source: file:///android_asset/www/activities/food-list/js/food-list.js (56)

I thought about food items with special characters. I tried deleting the items I had recently added, but it didn't help. I still think it's a possibility.

I'll get myself set up so I can build and test this on a simulator.

davidhealey commented 5 years ago

Well that pinpoints the problem. I'll have to see if I can recreate it, it's weird that it was working and now it isn't. I suspect it's not a problem with the search box as such but something going wrong with the list of foods, like an unescaped character or a blank entry. I'm really busy at the moment but I'll try and get around to looking into this soon.

corngood commented 5 years ago

Ok, I got waistline building and running on the emulator. Turns out 'import data' actually works if you double click it. ¯\_(ツ)_/¯

I guess it's probably still a bug, but at least that should let me import my data into the emulator.

davidhealey commented 5 years ago

Ah that's interesting, i must have put the wrong action in

corngood commented 5 years ago

Ok, I found a broken item in foodList:

        {
            "dateTime": "2018-11-09T22:24:15.909Z",
            "id": 17
        },

It appears to be a previously valid item because I have some diary entries and recipes referencing it, for example:

        {
            "brand": "",
            "category": "2",
            "category_name": "Dinner",
            "dateTime": "2018-10-25T23:00:39.087Z",
            "foodId": 17,
            "id": 34,
            "name": "Lean%20Ground%20Beef",
            "nutrition": {
                "calories": 60.8,
                "carbs": 0,
                "fat": 2.84,
                "fiber": 0,
                "protein": 8.2,
                "salt": 0.08,
                "saturated-fat": 1.08,
                "sugar": 0
            },
            "portion": "40g",
            "quantity": 1
        },

I'm guessing it had something to do with editing it, because the dateTime field is right around when I noticed it breaking, and the entries referencing it are earlier.

I reconstructed the missing fields from one of the diary entries, reimported the db, and it's working again.

I'll play around a bit and see if I can reproduce it.

davidhealey commented 5 years ago

Good catch. It'll be good if you can find out how it was caused and I'll also try and introduce some safe guards in the search box code if it finds an undefined value.

davidhealey commented 5 years ago

Was this issue resolved?

corngood commented 5 years ago

No, I haven't gone out of my way to reproduce it, but it hasn't happened to me since. I suspect it might be a timing thing around editing food items. Like if you submit during an asynchronous load or something?

davidhealey commented 5 years ago

Ok, I'll leave this issue open for now then and I'll have a go at reproducing it at some point. Glad it seems like an edge case though.

davidhealey commented 5 years ago

I noticed sometimes when searching for food I get a console message

el.name is undefined

This could perhaps be related

davidhealey commented 5 years ago

I fixed the el.name issue. I'm going to close this thread now, reopen it if the problem is repeatable :)