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

Add country flags at username #972

Closed
davehakkens opened this issue Jun 2, 2020 · 17 comments · Fixed by #1041
Closed

Add country flags at username #972

davehakkens opened this issue Jun 2, 2020 · 17 comments · Fixed by #1041

Comments

@davehakkens
Copy link
Contributor

Component infos

Description

Show the diversity of the worldwide community more, by adding locations flags to usernames. Based on the location selected by the user.

Page related

Will be used in :
How-to overview
Single How to

Mockup

profile-flag
flag_howto

@BenGamma
Copy link
Contributor

BenGamma commented Jun 6, 2020

This one is a bit in the same veine as #974. We'll probably have to add a field on the how-to model creatorCountry when howto is created, to be able to easily get this info.

@Daniel-Davies
Copy link
Contributor

Hello- I'd love to help out your platform and contribute to this issue, if possible. Could I take this issue? (Or would you recommend another?)

@davehakkens
Copy link
Contributor Author

Thanks for wanting to help @Daniel-Davies, however @alromh87 is currently working on this one.
What do you like to work on/ what are your skills? We have quite some SEO improvement we need to make, optimise backend, and bugfixes.

We are working on some new features but are currently still in design stage.

@Daniel-Davies
Copy link
Contributor

Hello- I've had a look at other issues. Is #989 available?

@alromh87
Copy link
Collaborator

alromh87 commented Sep 6, 2020

@BenGamma @chrismclarke I have some doubts about the cache for howto list:

Flag in howto list gets updated if I edit the howto from the browser but not when i trigger from DB

Flag in Detail its updated every time (from browser or DB)

@BenGamma
Copy link
Contributor

@alromh87 yes it would be preferable to update from the browser. Otherwise we have to update the cache of all the user and that's a lot of data 😬
Can you describe the procedure to update from the browser ? I'm not sure to understand

@alromh87
Copy link
Collaborator

alromh87 commented Sep 10, 2020

When a user updates a howto, the fag gets correctly updated in the HowToList.

But if a user changes his location all of his how-tos should reflect the change, that its achived with a firestore function.
After change the new flag will display in how-to detail(edit, view) but not on how to list.

Im unsure if this has to do with my dev environment or some web cache

@BenGamma
Copy link
Contributor

When a user is updates a howto, the fag gets correctly updated in the HowToList.

Ok and #1033 is updating the flag in the howto list but it doesn't update the location of the how-to if the user changes it.

But if a user changes his location all of his how-tos should reflect the change, that its achived with a firestore function.
After change the new flag will display in how-to detail(edit, view) but not on how to list.

Is it something you are planning to had to #1033 before merge ?

Im unsure if this has to do with my dev environment or some web cache

It's hard to tell for your problem since I don't see the code

@alromh87
Copy link
Collaborator

When a user updates a howto, the fag gets correctly updated in the HowToList.

Ok and #1033 is updating the flag in the howto list but it doesn't update the location of the how-to if the user changes it.

Not sure I understod this, If a user changes his location his howTo don't reflect the change, will fix that with next commit

But if a user changes his location all of his how-tos should reflect the change, that its achived with a firestore function.
After change the new flag will display in how-to detail(edit, view) but not on how to list.

Is it something you are planning to had to #1033 before merge ?

Yes I will update the PR

Im unsure if this has to do with my dev environment or some web cache

It's hard to tell for your problem since I don't see the code

The database is updated correctly its just the howTo list that doesn't reflect the change

@alromh87
Copy link
Collaborator

Firestore Trigger added
b287bcc

BenGamma added a commit that referenced this issue Sep 16, 2020
BenGamma added a commit that referenced this issue Sep 20, 2020
Fix #972 Add country flags at username - Fix deployment
@BenGamma BenGamma reopened this Oct 14, 2020
@BenGamma
Copy link
Contributor

BenGamma commented Oct 14, 2020

Reopen because we need to add creatorCountry field to existing how-tos before it's fully completed.

We could do a similar operation as in the how-to count/event migration script

For now only new how-to's are saved with the creatorCountry field

@alromh87
Copy link
Collaborator

Following script will populate the fields as needed, has been run on dev environment already showing all available flags

Captura de pantalla de 2020-10-14 10-08-56

const functions = require('firebase-functions')
const request = require('request')

const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();

// Change for prod:
// import { db } from '../Firebase/firestoreDB'

// Set all user flags
async function updateAllFlags() {

  console.log('Updating all flags ...')

  try {
    const querySnapshot = await db.collection('v3_users').get();

    if(querySnapshot  && !querySnapshot.empty){
      querySnapshot.forEach(async user => {
        const country = (user.data().location && user.data().location.countryCode) ? user.data().location.countryCode : (user.data().country ? user.data().country.toLowerCase() : '')
        if(country !== ''){

          console.log('Procesing', user.data()._id, 'flags');

          const querySnapshotHowTo = await db.collection('v3_howtos').where("_createdBy", "==", user.data()._id).get()
          if(querySnapshotHowTo){
            querySnapshotHowTo.forEach(doc => {
              console.log('updating', user.data()._id, 'doc', doc.data()._id, 'to', country);
              doc.ref.update({
                'creatorCountry': country,
                '_modified': new Date().toISOString()
              })
              .then( () => {
                console.log("Document successfully updated!");
                return null
              }).catch( error => {
                console.error("Error updating HowToCountry: ", error);
                return null
              });
            });
          } else {
            console.error('Error getting user howTos');
          }
        }else{
          console.log('No info for ', user.data()._id, 'flags');
        }
      })
    }
  }catch(e) {
    console.log('Error updating flags:', e)
  }
}

// Cant trigger from url, fix permissions or use google cloud console  https://console.cloud.google.com/functions/list?project=precious-plastics-v4-dev&folder=&organizationId=

exports.migrationFeat972Flags = functions.https.onRequest(async (req, res) => {
  await updateAllFlags();
  res.status(200).send('Finished');
});

@BenGamma
Copy link
Contributor

Ok cool, @chrismclarke since it's a one shoot script, do you prefer we run it from the console or like the userStats, create a dedicated folder/migration file for it ?

@davehakkens
Copy link
Contributor Author

Following script will populate the fields as needed, has been run on dev environment already showing all available flags

Captura de pantalla de 2020-10-14 10-08-56

What is up with your tag selection box @alromh87, you always see it like that?

@alromh87
Copy link
Collaborator

Haha yep, when I use one version of chrome, I'm not on my computer now but will tell you specific version when I'm back

@alromh87
Copy link
Collaborator

@davehakkens I see it like that with chrome Versión 69.0.3497.81 (Build oficial) (64 bits) on Debian Jessie

If I use Versión 80.0.3987.16 (Build oficial) beta (64 bits) int he same computer tag selection is smaller
Captura de pantalla de 2020-10-16 23-37-21

@chrismclarke
Copy link
Member

I think this discussion moved over to slack, but if there's still anything missing from my side feel free to reach out to me over on slack (I don't check github as regularly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants