created storage
This commit is contained in:
parent
86efbce55e
commit
0c38be47b9
45
AuthentesApp/package-lock.json
generated
45
AuthentesApp/package-lock.json
generated
@ -1889,6 +1889,30 @@
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"@ionic/storage": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz",
|
||||
"integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==",
|
||||
"requires": {
|
||||
"localforage": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"@ionic/storage-angular": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@ionic/storage-angular/-/storage-angular-3.0.6.tgz",
|
||||
"integrity": "sha512-ZXlIFWGU27aCxVFgZb0KFJFtWwnn6+HK6v0rMGzjN8f7oV2ewXaQ2dl1gTw/A8YoozTVPOFxwfFHCjhWLFR1Fw==",
|
||||
"requires": {
|
||||
"@ionic/storage": "^3.0.4",
|
||||
"tslib": "^1.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
|
||||
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@istanbuljs/schema": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz",
|
||||
@ -7165,8 +7189,7 @@
|
||||
"immediate": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
|
||||
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=",
|
||||
"dev": true
|
||||
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps="
|
||||
},
|
||||
"import-fresh": {
|
||||
"version": "3.3.0",
|
||||
@ -8462,6 +8485,24 @@
|
||||
"json5": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"localforage": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz",
|
||||
"integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==",
|
||||
"requires": {
|
||||
"lie": "3.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"lie": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
|
||||
"integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=",
|
||||
"requires": {
|
||||
"immediate": "~3.0.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"locate-path": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
|
||||
|
@ -22,6 +22,7 @@
|
||||
"@ionic-native/core": "^5.36.0",
|
||||
"@ionic-native/status-bar": "^5.36.0",
|
||||
"@ionic/angular": "^5.5.2",
|
||||
"@ionic/storage-angular": "^3.0.6",
|
||||
"cordova-android": "9.1.0",
|
||||
"rxjs": "~6.6.0",
|
||||
"tslib": "^2.2.0",
|
||||
|
@ -8,11 +8,12 @@ import { AppComponent } from './app.component';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
||||
import { StatusBar } from '@ionic-native/status-bar/ngx';
|
||||
import { IonicStorageModule } from '@ionic/storage-angular';
|
||||
|
||||
@NgModule({
|
||||
declarations: [AppComponent],
|
||||
entryComponents: [],
|
||||
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
|
||||
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, IonicStorageModule.forRoot()],
|
||||
providers: [
|
||||
StatusBar,
|
||||
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Component, Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { GameService } from '../services/game.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -13,7 +14,7 @@ import { ModalController } from '@ionic/angular';
|
||||
})
|
||||
export class ModalsGamePage {
|
||||
|
||||
constructor(private router: Router, public modalController: ModalController) {}
|
||||
constructor(private router: Router, public modalController: ModalController, private game: GameService) {}
|
||||
|
||||
async presentModal(game: string) {
|
||||
const modal = await this.modalController.create({
|
||||
@ -34,11 +35,12 @@ export class ModalsGamePage {
|
||||
});
|
||||
}
|
||||
|
||||
play(game: string) {
|
||||
async play(game: string) {
|
||||
// check if game cookie exists
|
||||
// create cookie with data if non existing
|
||||
// continue or restart with cookie
|
||||
|
||||
await console.log(this.game.checkGameStorage(game));
|
||||
console.log("pardon?");
|
||||
// when all the steps are done and clicked on play, dismiss modal and open page
|
||||
this.dismiss();
|
||||
// routing is in lowercase, set text to lower
|
||||
|
23
AuthentesApp/src/app/services/game.service.ts
Normal file
23
AuthentesApp/src/app/services/game.service.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { AlertService } from './alert.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GameService {
|
||||
|
||||
constructor(private storage: StorageService, private alert: AlertService) {}
|
||||
|
||||
public async checkGameStorage(game: string){
|
||||
|
||||
if(await this.storage.get(`${game.toUpperCase()}GAME_TOKEN`)){
|
||||
// continue or restart
|
||||
console.log(await this.alert.presentAlertConfirm("Game found", "Do u want to continue or restart?", "restart", "continue"));
|
||||
return "storage found";
|
||||
}
|
||||
// standard create new
|
||||
return "no storage";
|
||||
|
||||
}
|
||||
}
|
33
AuthentesApp/src/app/services/storage.service.ts
Normal file
33
AuthentesApp/src/app/services/storage.service.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Storage } from '@ionic/storage-angular';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StorageService {
|
||||
|
||||
private _storage: Storage | null = null;
|
||||
|
||||
constructor(private storage: Storage) {}
|
||||
|
||||
async init() {
|
||||
console.log("[StorageService] Initializing storage...");
|
||||
const storage = await this.storage.create();
|
||||
this._storage = storage;
|
||||
}
|
||||
|
||||
public async set(key: string, value: any) {
|
||||
console.log("[StorageService] Setting value in storage:", key, value);
|
||||
await this._storage?.set(key, value);
|
||||
}
|
||||
|
||||
public async get(key: string) {
|
||||
console.log("[StorageService] Getting value from storage:", key);
|
||||
return await this._storage?.get(key);
|
||||
}
|
||||
public async remove(key: string){
|
||||
console.log("[StorageService] removing value from storage:", key);
|
||||
return await this._storage?.remove(key);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user