ground-db icon indicating copy to clipboard operation
ground-db copied to clipboard

Question: best way to advise users of successful update/inserts?

Open proehlen opened this issue 9 years ago • 3 comments

Hello, thank you for your excellent package.

My app is using autoform quite extensively to provide document insert/update functionality. I added GroundMeteor/db and it works beautifully. However, I noticed that the success messages I had coded only appear to the user after the app had reconnected to the server the changes have been synced. I'm doing collection inserts/updates via allow/deny rules rather than server methods.

This is the code I was using to provide feedback on update/insert success:

AutoForm.addHooks('updateDocument',
    {
        onSuccess: function(formType, result) {
            toastr.success('Changes saved.');
        },
    }
);

I've also tried Collection Hooks but it exhibits the exact same symptom: the user is informed of multiple update/insert success messages only after the app has reconnected to the server:

tasks.after.update(function(userId, doc, fieldNames, modifier, options){
    if (Meteor.isClient){
        toastr.success("Update sucess!");
    }
});

Would someone be able to advise me how I should be handling this?

Thanks.

proehlen avatar Jul 18 '15 07:07 proehlen

I am trying to solve the same problem. The issue is that the collection hooks and the autoform hooks are designed to inform you about confirmed success. So what we need to do is try to anticipate any errors on the client that we can, but ultimately assume that the operation will succeed.

The AutoForm before hook seems to be the thing that we want. In the notes at the bottom of the linked section, it says

The before hooks are called after the form is deemed valid but before the submission operation happens.

With the form validated, we have to assume that the update will succeed.

If there is a better way to do this, I'd love to hear it!

BudgieInWA avatar Jul 27 '15 05:07 BudgieInWA

please try creating a simple app, adding ground db - then use the regular collection.insert({}, function() {}); callback pattern to see if this works

raix avatar Jul 30 '15 17:07 raix

It also emits an event when a method have been sent/resumed https://github.com/GroundMeteor/db/blob/connection-driver/groundDB.client.js#L725

raix avatar Jul 30 '15 17:07 raix