created storage
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user