Creating animated menu

Hello everyone,

I should begin by telling you that i’m really not a professional of code.

I would like to create an amount of point on my header that the user can see (his points), but only when he is connected.

Those points, i want to get them back from one of my database.

When he is not connected, the header only ask him to get connected.

IIs this possible ? Can i do it in JS ? Can you give me some code or tracks that could help me ?

I seek for a similar topic but found nothing.

Thank you all :slight_smile:

Hello Yoan,

yes it is surely possible to realize it.

You will need a ready configured database for it.
Then you take a text or an Textfield where you later will be able to show your points (score).

You can solve your issue in 2-different ways.

  1. By using a dataset, which will connect your DATABASE with your TEXT/Textfield.

  2. Or by using a Data-Query.

  3. And you will need to get the currentUser-ID, so that you are able to identify the user who is current on your site.

  4. Get user-details (user-ID)

import wixUsers from 'wix-users';

5let user = wixUsers.currentUser;
6
7let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11  .then( (email) => {
12    let userEmail = email;      // "user@something.com"
13  } );


  1. DATA-QUERY:
import wixData from 'wix-data';
2
3// ...
4
5wixData.query("myCollection")
6  .find()
7  .then( (results) => {
8    if(results.items.length > 0) {
9      let firstItem = results.items[0]; //see item below
10    } else {
11      // handle case where no matching items found
12    }
13  } )
14  .catch( (err) => {
15    let errorMsg = err;
16  } );
  1. DATASET
$w.onReady( () => {
2  $w("#myDataset").onReady( () => {
3    $w("#myDataset").getItems(3, 2)
4      .then( (result) => {
5        let items = result.items;
6        let totalCount = result.totalCount;
7        let offset = result.offset;
8      } )
9      .catch( (err) => {
10        let errMsg = err.message;
11        let errCode = err.code;
12      } );
13
14  } );
15
16} );