FEATURE: improve typeahead. add previous search history.

This commit is contained in:
walljm 2019-01-02 22:57:12 -05:00
parent f93817a8fc
commit c15c5988aa
7 changed files with 193 additions and 159 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="302000" id="walljm.dynamicbible" version="3.2.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <widget android-versionCode="302002" id="walljm.dynamicbible" version="3.2.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Dynamic Bible</name> <name>Dynamic Bible</name>
<description>A bible app designed for bible study</description> <description>A bible app designed for bible study</description>
<author email="jason@walljm.com" href="http://dynamicbible.com/">Jason Wall</author> <author email="jason@walljm.com" href="http://dynamicbible.com/">Jason Wall</author>

View File

@ -16,7 +16,9 @@
"start": "ionic serve", "start": "ionic serve",
"lab": "ionic serve --lab", "lab": "ionic serve --lab",
"test": "ng test", "test": "ng test",
"test-coverage": "ng test --code-coverage" "test-coverage": "ng test --code-coverage",
"release-android": "ionic cordova build android --release -- --buildConfig=./build.json",
"android": "ionic cordova run android"
}, },
"dependencies": { "dependencies": {
"@angular/common": "5.0.0", "@angular/common": "5.0.0",

View File

@ -6,10 +6,6 @@
<ion-label>Show Strongs as Modal</ion-label> <ion-label>Show Strongs as Modal</ion-label>
<ion-toggle color='dark' [(ngModel)]='profileService.profile().strongs_modal' (ionChange)='profileService.localSave()'></ion-toggle> <ion-toggle color='dark' [(ngModel)]='profileService.profile().strongs_modal' (ionChange)='profileService.localSave()'></ion-toggle>
</ion-item> </ion-item>
<ion-item>
<ion-label>Clear Search after Query</ion-label>
<ion-toggle color='dark' [(ngModel)]='profileService.profile().clear_search_after_query' (ionChange)='profileService.localSave()'></ion-toggle>
</ion-item>
<ion-item> <ion-item>
<ion-label>Append Results Below</ion-label> <ion-label>Append Results Below</ion-label>
<ion-toggle color='dark' [(ngModel)]='profileService.profile().append_to_bottom' (ionChange)='profileService.localSave()'></ion-toggle> <ion-toggle color='dark' [(ngModel)]='profileService.profile().append_to_bottom' (ionChange)='profileService.localSave()'></ion-toggle>

View File

@ -27,8 +27,11 @@
<button ion-button icon-only menuToggle left> <button ion-button icon-only menuToggle left>
<ion-icon name='menu' large></ion-icon> <ion-icon name='menu' large></ion-icon>
</button> </button>
<ion-auto-complete [dataProvider]='autocompleteService' (search)='getQuery($event)' (input)='setQuery($event)' <ion-auto-complete [dataProvider]='autocompleteService'
(itemSelected)='itemSelected($event)' [options]='{ showCancelButton : "true" }' #searchbar></ion-auto-complete> [(keyword)]='searchQuery'
(search)='getQuery($event)' (input)='setQuery($event)'
(itemSelected)='itemSelected($event)' [options]='{ showCancelButton : "true" }'
(autoFocus)='showHistory($event)' #searchbar></ion-auto-complete>
<ion-buttons right> <ion-buttons right>
<button ion-button icon-only secondary (click)='versePicker()'> <button ion-button icon-only secondary (click)='versePicker()'>
<ion-icon name='albums' large></ion-icon> <ion-icon name='albums' large></ion-icon>

View File

@ -1,61 +1,55 @@
import { Type, Component, OnInit, ViewChild } from '@angular/core'; import { Type, Component, OnInit, ViewChild } from "@angular/core";
import { Loading, LoadingController, ModalController, NavParams, AlertController, MenuController } from 'ionic-angular'; import { Loading, LoadingController, ModalController, NavParams, AlertController, MenuController, TextInput, Searchbar } from "ionic-angular";
import { AutoCompleteComponent } from 'ionic2-auto-complete'; import { AutoCompleteComponent } from "ionic2-auto-complete";
import { StrongsModal } from '../../components/strongs-modal/strongs-modal'; import { StrongsModal } from "../../components/strongs-modal/strongs-modal";
import { VersePickerModal } from '../../components/verse-picker/verse-picker'; import { VersePickerModal } from "../../components/verse-picker/verse-picker";
import { Settings } from '../../components/settings/settings';
import { PagesService } from '../../services/pages-service'; import { PagesService } from "../../services/pages-service";
import { ProfileService, User } from './../../services/profile-service'; import { ProfileService, User } from "./../../services/profile-service";
import { SearchAutoCompleteService } from '../../services/search-autocomplete-service'; import { SearchAutoCompleteService } from "../../services/search-autocomplete-service";
import { Reference } from '../../libs/Reference';
import { Reference } from "../../libs/Reference";
@Component({ @Component({
templateUrl: 'search.html', templateUrl: "search.html",
providers: [SearchAutoCompleteService] providers: [SearchAutoCompleteService]
}) })
export class SearchPage implements OnInit { export class SearchPage implements OnInit {
searchQuery = ''; searchQuery = "";
loader: Loading; loader: Loading;
@ViewChild('searchbar') @ViewChild("searchbar")
searchbar: AutoCompleteComponent; searchbar: AutoCompleteComponent;
constructor( constructor(
private pagesService: PagesService private pagesService: PagesService,
, private alertCtrl: AlertController private alertCtrl: AlertController,
, private menu: MenuController private menu: MenuController,
, public loadingCtrl: LoadingController public loadingCtrl: LoadingController,
, public modalCtrl: ModalController public modalCtrl: ModalController,
, public profileService: ProfileService public profileService: ProfileService,
, public params: NavParams public params: NavParams,
, public autocompleteService: SearchAutoCompleteService public autocompleteService: SearchAutoCompleteService
) { ) {}
}
ngOnInit(): void { ngOnInit(): void {
if (this.profileService.localIsLoaded) { if (this.profileService.localIsLoaded) {
this.loader = this.loadingCtrl.create({ content: 'Loading Page...' }); this.loader = this.loadingCtrl.create({ content: "Loading Page..." });
this.loader.present().then(() => { this.loader.present().then(() => {
let t = this.profileService.profile(); let t = this.profileService.profile();
this.initializeItems(t); this.initializeItems(t);
this.loader.dismiss(); this.loader.dismiss();
}); });
} } else {
else {
this.profileService.onLocalStorageLoaded.subscribe(t => { this.profileService.onLocalStorageLoaded.subscribe(t => {
// Check if there is a profile saved in local storage // Check if there is a profile saved in local storage
this.loader = this.loadingCtrl.create({ content: 'Loading Page...' }); this.loader = this.loadingCtrl.create({ content: "Loading Page..." });
this.loader.present().then(() => { this.loader.present().then(() => {
this.initializeItems(t); this.initializeItems(t);
this.loader.dismiss(); this.loader.dismiss();
this.pagesService.initializePages(this.profileService.profile().saved_pages); this.pagesService.initializePages(this.profileService.profile().saved_pages);
}); });
}); });
this.profileService.onSavedPagesChanged.subscribe(sp => { this.profileService.onSavedPagesChanged.subscribe(sp => {
this.pagesService.initializePages(sp); this.pagesService.initializePages(sp);
@ -69,17 +63,17 @@ export class SearchPage implements OnInit {
for (let i in u.items) { for (let i in u.items) {
if (u.items.hasOwnProperty(i)) { if (u.items.hasOwnProperty(i)) {
let ci = u.items[i]; let ci = u.items[i];
if (ci['data'] !== undefined) { if (ci["data"] !== undefined) {
if (ci['data'].qry !== undefined) if (ci["data"].qry !== undefined)
u.items[i] = { qry: ci['data'].qry, dict: ci.dict, type: ci.type }; u.items[i] = { qry: ci["data"].qry, dict: ci.dict, type: ci.type };
else if (ci['data'].ref !== undefined) else if (ci["data"].ref !== undefined)
u.items[i] = { qry: ci['data'].ref, dict: ci.dict, type: ci.type }; u.items[i] = { qry: ci["data"].ref, dict: ci.dict, type: ci.type };
else if (ci['data'].word !== undefined) else if (ci["data"].word !== undefined)
u.items[i] = { qry: ci['data'].word, dict: ci.dict, type: ci.type }; u.items[i] = { qry: ci["data"].word, dict: ci.dict, type: ci.type };
else if (ci['data'].sn !== undefined) else if (ci["data"].sn !== undefined)
u.items[i] = { u.items[i] = {
qry: ci['data'].sn, qry: ci["data"].sn,
dict: ci['prefix'] === 'G' ? 'grk' : 'heb', dict: ci["prefix"] === "G" ? "grk" : "heb",
type: ci.type type: ci.type
}; };
@ -92,17 +86,17 @@ export class SearchPage implements OnInit {
for (let i in pg.queries) { for (let i in pg.queries) {
if (pg.queries.hasOwnProperty(i)) { if (pg.queries.hasOwnProperty(i)) {
let ci = pg.queries[i]; let ci = pg.queries[i];
if (ci['data'] !== undefined) { if (ci["data"] !== undefined) {
if (ci['data'].qry !== undefined) if (ci["data"].qry !== undefined)
pg.queries[i] = { qry: ci['data'].qry, dict: ci.dict, type: ci.type }; pg.queries[i] = { qry: ci["data"].qry, dict: ci.dict, type: ci.type };
else if (ci['data'].ref !== undefined) else if (ci["data"].ref !== undefined)
pg.queries[i] = { qry: ci['data'].ref, dict: ci.dict, type: ci.type }; pg.queries[i] = { qry: ci["data"].ref, dict: ci.dict, type: ci.type };
else if (ci['data'].word !== undefined) else if (ci["data"].word !== undefined)
pg.queries[i] = { qry: ci['data'].word, dict: ci.dict, type: ci.type }; pg.queries[i] = { qry: ci["data"].word, dict: ci.dict, type: ci.type };
else if (ci['data'].sn !== undefined) else if (ci["data"].sn !== undefined)
pg.queries[i] = { pg.queries[i] = {
qry: ci['data'].sn, qry: ci["data"].sn,
dict: ci['prefix'] === 'G' ? 'grk' : 'heb', dict: ci["prefix"] === "G" ? "grk" : "heb",
type: ci.type type: ci.type
}; };
@ -119,18 +113,14 @@ export class SearchPage implements OnInit {
if (this.params.data.queries !== undefined) if (this.params.data.queries !== undefined)
this.profileService.profile().items = JSON.parse(JSON.stringify(this.params.data.queries)); this.profileService.profile().items = JSON.parse(JSON.stringify(this.params.data.queries));
if (this.params.data.title === undefined) if (this.params.data.title === undefined) this.profileService.title = "Search";
this.profileService.title = 'Search'; else this.profileService.title = this.params.data.title;
else
this.profileService.title = this.params.data.title;
if (has_migrated) if (has_migrated) this.profileService.save();
this.profileService.save();
if (this.profileService.profile().items === undefined) { if (this.profileService.profile().items === undefined) {
this.profileService.profile().items = []; // sometimes, maybe because of all the weirdness with the remote syncing, this gets set to undefined, and it needs to be reset. this.profileService.profile().items = []; // sometimes, maybe because of all the weirdness with the remote syncing, this gets set to undefined, and it needs to be reset.
} }
} }
textSizeChanged() { textSizeChanged() {
@ -142,28 +132,28 @@ export class SearchPage implements OnInit {
this.profileService.localSave(); this.profileService.localSave();
} }
actionsMenu() { actionsMenu() {
this.menu.open('actions'); this.menu.open("actions");
} }
addPage() { addPage() {
const alert = this.alertCtrl.create({ const alert = this.alertCtrl.create({
title: 'Save Search as Page', title: "Save Search as Page",
inputs: [ inputs: [
{ {
name: 'title', name: "title",
placeholder: 'Page Title' placeholder: "Page Title"
} }
], ],
buttons: [ buttons: [
{ {
text: 'Cancel', text: "Cancel",
role: 'cancel', role: "cancel",
handler: (): void => { handler: (): void => {
console.log('Cancel clicked'); console.log("Cancel clicked");
} }
}, },
{ {
text: 'Save', text: "Save",
handler: data => { handler: data => {
const p = { queries: this.profileService.profile().items.slice(), title: data.title }; const p = { queries: this.profileService.profile().items.slice(), title: data.title };
this.profileService.profile().saved_pages.push(p); this.profileService.profile().saved_pages.push(p);
@ -177,30 +167,28 @@ export class SearchPage implements OnInit {
} }
updatePage() { updatePage() {
const page = this.profileService.profile().saved_pages.find( const page = this.profileService.profile().saved_pages.find(i => i.title === this.params.data.title);
i =>
i.title === this.params.data.title
);
page.queries = this.profileService.profile().items.slice(); page.queries = this.profileService.profile().items.slice();
this.profileService.save(); this.profileService.save();
} }
itemSelected(autocomplete: string) { itemSelected(autocomplete: string) {
let qry = autocomplete; let qry = autocomplete;
let idx = qry.lastIndexOf(';'); let idx = qry.lastIndexOf(";");
let prefix = ''; let prefix = "";
let words = [];
if (idx > -1) { if (idx > -1) {
qry = autocomplete.substr(idx + 1).trim(); qry = autocomplete.substr(idx + 1).trim();
prefix = autocomplete.substr(0, idx).trim() + '; '; prefix = autocomplete.substr(0, idx).trim() + "; ";
} }
if (qry.startsWith('Book:')) {
this.searchQuery = prefix + qry.substr(qry.indexOf('Book:')+5).trim(); const bk = Reference.parseBook(qry);
autocomplete = this.searchQuery; if (bk.book_number > 0) {
} this.searchQuery = prefix + qry.trim() + " ";
else { this.searchbar.setFocus();
this.searchQuery = autocomplete; } else {
this.searchQuery = prefix + autocomplete;
this.getQuery();
} }
} }
@ -208,21 +196,36 @@ export class SearchPage implements OnInit {
this.searchQuery = searchbar.target.value; this.searchQuery = searchbar.target.value;
} }
getQuery(searchbar) { getQuery() {
this.updateUIwithItems(this.searchQuery, true); const qry = this.searchQuery;
this.searchQuery = "";
this.searchbar.setValue("");
this.profileService.addSearchRequestToHistory(qry);
this.updateUIwithItems(qry, true);
}
showHistory() {
if (
this.searchQuery.trim().length === 0 &&
this.profileService.searchHistory !== null &&
this.profileService.searchHistory.length > 0
) {
this.searchbar.suggestions = this.profileService.searchHistory;
this.searchbar.showItemList();
}
} }
isError(t: string) { isError(t: string) {
return t === 'Error'; return t === "Error";
} }
isPassage(t: string) { isPassage(t: string) {
return t === 'Passage'; return t === "Passage";
} }
isStrongs(t: string) { isStrongs(t: string) {
return t === 'Strongs'; return t === "Strongs";
} }
isWords(t: string) { isWords(t: string) {
return t === 'Words'; return t === "Words";
} }
versePicker() { versePicker() {
@ -238,47 +241,44 @@ export class SearchPage implements OnInit {
getItemList(search: string): Promise<CardItem[]> { getItemList(search: string): Promise<CardItem[]> {
this.searchbar.hideItemList(); this.searchbar.hideItemList();
return new Promise((resolve) => { return new Promise(resolve => {
const list: CardItem[] = []; const list: CardItem[] = [];
try { try {
const qs = search.split(';'); const qs = search.split(";");
for (let x in qs) { for (let x in qs) {
if (qs.hasOwnProperty(x)) { if (qs.hasOwnProperty(x)) {
let q = qs[x].trim(); let q = qs[x].trim();
if (q !== '') { if (q !== "") {
// its a search term. // its a search term.
if (q.search(/[0-9]/i) === -1) if (q.search(/[0-9]/i) === -1) list.push({ qry: q, dict: "na", type: "Words" });
list.push({ qry: q, dict: 'na', type: 'Words' });
else if (q.search(/(H|G)[0-9]/i) !== -1) { else if (q.search(/(H|G)[0-9]/i) !== -1) {
// its a strongs lookup // its a strongs lookup
let dict = q.substring(0, 1); let dict = q.substring(0, 1);
if (dict.search(/h/i) !== -1) if (dict.search(/h/i) !== -1) dict = "heb";
dict = 'heb'; else dict = "grk";
else
dict = 'grk';
q = q.substring(1, q.length); q = q.substring(1, q.length);
list.push({ qry: q, dict: dict, type: 'Strongs' }); list.push({ qry: q, dict: dict, type: "Strongs" });
} } else {
else {
// its a verse reference. // its a verse reference.
if (q.trim() !== '') { if (q.trim() !== "") {
const myref = new Reference(q.trim()); const myref = new Reference(q.trim());
list.push({ qry: myref.toString(), dict: myref.Section.start.book.book_number > 39 ? 'G' : 'H', type: 'Passage' }); list.push({
qry: myref.toString(),
dict: myref.Section.start.book.book_number > 39 ? "G" : "H",
type: "Passage"
});
} }
} }
} }
} }
} }
if (this.profileService.profile().clear_search_after_query)
$('.searchbar-input').val('');
this.profileService.save(); this.profileService.save();
} } catch (error) {
catch (error) { list.push({ qry: error, type: "Error", dict: "na" });
list.push({ qry: error, type: 'Error', dict: 'na' });
console.log(error); console.log(error);
} }
@ -287,27 +287,32 @@ export class SearchPage implements OnInit {
} }
updateUIwithItems(search: string, from_search_bar: boolean) { updateUIwithItems(search: string, from_search_bar: boolean) {
// clear search box.
this.searchQuery = "";
this.searchbar.setValue("");
this.getItemList(search).then(lst => { this.getItemList(search).then(lst => {
this.loader = this.loadingCtrl.create({ content: 'Looking up Query...' }); this.loader = this.loadingCtrl.create({ content: "Looking up Query..." });
this.loader.present().then( this.loader.present().then(() => {
() => { for (let item of lst) {
for (let item of lst) { if (item.type === "Strongs" && this.profileService.profile().strongs_modal && !from_search_bar) {
if (item.type === 'Strongs' && this.profileService.profile().strongs_modal && !from_search_bar) { const modal = this.modalCtrl.create(StrongsModal, {
const modal = this.modalCtrl.create(StrongsModal, { sn: parseInt(item.qry), dict: item.dict, onItemClicked: this }); sn: parseInt(item.qry),
modal.present(); dict: item.dict,
} else onItemClicked: this
this.profileService.addItemToList(item); });
} modal.present();
this.loader.dismiss(); } else this.profileService.addItemToList(item);
} }
); this.loader.dismiss();
});
}); });
} }
} }
export type OpenData = { card: CardItem, qry: string, from_search_bar: boolean } export type OpenData = { card: CardItem; qry: string; from_search_bar: boolean };
export type CardItem = { qry: string, type: string, dict: string } export type CardItem = { qry: string; type: string; dict: string };
class Item { class Item {
id: number; id: number;

View File

@ -1,19 +1,19 @@
/// <reference path='../../typings/globals/jquery/index.d.ts' /> /// <reference path='../../typings/globals/jquery/index.d.ts' />
import { Injectable } from '@angular/core'; import { Injectable } from "@angular/core";
import { AngularFireDatabase, AngularFireObject } from 'angularfire2/database'; import { AngularFireDatabase, AngularFireObject } from "angularfire2/database";
import { AngularFireAuth } from 'angularfire2/auth'; import { AngularFireAuth } from "angularfire2/auth";
import * as firebase from 'firebase/app'; import * as firebase from "firebase/app";
import { Observable } from 'rxjs/Observable'; import { Observable } from "rxjs/Observable";
import { Catch } from 'rxjs/add/operator'; import { Catch } from "rxjs/add/operator";
import { Storage } from '@ionic/storage'; import { Storage } from "@ionic/storage";
import { CardItem } from '../pages/search/search'; import { CardItem } from "../pages/search/search";
import { Promise } from 'q'; import { Promise } from "q";
import { setTimeout } from 'timers'; import { setTimeout } from "timers";
import { Output, EventEmitter } from '@angular/core'; import { Output, EventEmitter } from "@angular/core";
export const DEFAULT_USER_NAME = 'john_doe'; export const DEFAULT_USER_NAME = "john_doe";
@Injectable() @Injectable()
export class ProfileService { export class ProfileService {
@ -34,11 +34,21 @@ export class ProfileService {
last: CardItem; last: CardItem;
title: string; title: string;
searchHistory: string[] = [];
constructor(private local: Storage, private db: AngularFireDatabase, public firebaseAuth: AngularFireAuth) { constructor(private local: Storage, private db: AngularFireDatabase, public firebaseAuth: AngularFireAuth) {
this.url = document.URL; this.url = document.URL;
this.isWeb = document.URL.startsWith('http') && !document.URL.startsWith('http://localhost:8080'); this.isWeb = document.URL.startsWith("http") && !document.URL.startsWith("http://localhost:8080");
this.localIsLoaded = false; this.localIsLoaded = false;
this.local.get("searchHistory").then(v => {
if (v === null) {
this.searchHistory = [];
} else {
this.searchHistory = v;
}
});
// asyncrounosly kick off a poller that does the work of syncing remotely when the // asyncrounosly kick off a poller that does the work of syncing remotely when the
// profile needs to be synced. // profile needs to be synced.
(function poll(self) { (function poll(self) {
@ -49,9 +59,9 @@ export class ProfileService {
// If we have a remote profile then save it there too // If we have a remote profile then save it there too
if (self.remoteProfile && self.localProfile.uid) { if (self.remoteProfile && self.localProfile.uid) {
let st = new Date(); let st = new Date();
console.log('Saving the remote profile...'); console.log("Saving the remote profile...");
self.remoteProfile.ref.set(self.localProfile); self.remoteProfile.ref.set(self.localProfile);
console.log(' Finished saving remote profile. ' + self.elapsed(st, new Date()) + 'ms'); console.log(" Finished saving remote profile. " + self.elapsed(st, new Date()) + "ms");
} }
self.needsSync = false; self.needsSync = false;
} }
@ -60,7 +70,7 @@ export class ProfileService {
}, 2000); }, 2000);
})(this); })(this);
this.local.get('profile').then(json_profile => { this.local.get("profile").then(json_profile => {
let t = this.profile(); let t = this.profile();
if (json_profile !== null) t = JSON.parse(json_profile); if (json_profile !== null) t = JSON.parse(json_profile);
@ -73,6 +83,27 @@ export class ProfileService {
this.firebaseAuth.authState.subscribe(state => this.subscribeToRemoteProfile(this.db, state)); this.firebaseAuth.authState.subscribe(state => this.subscribeToRemoteProfile(this.db, state));
} }
addSearchRequestToHistory(qry: string) {
if (this.searchHistory === null) {
this.searchHistory = [];
}
// if the query already exists, remove it so it will be unique
this.searchHistory = this.searchHistory.filter( v => v === qry);
// put it at the top.
this.searchHistory.unshift(qry);
// no more than 5.
if (this.searchHistory.length > 5)
{
this.searchHistory = this.searchHistory.slice(0, 5);
}
// save it to storage.
this.local.set("searchHistory", this.searchHistory);
}
//#region Profile //#region Profile
removeItem(item) { removeItem(item) {
@ -99,7 +130,7 @@ export class ProfileService {
} }
isOnSearchPage() { isOnSearchPage() {
return this.title !== 'Search'; return this.title !== "Search";
} }
profile(): User { profile(): User {
@ -111,10 +142,10 @@ export class ProfileService {
} }
subscribeToRemoteProfile(db: AngularFireDatabase, user: firebase.User) { subscribeToRemoteProfile(db: AngularFireDatabase, user: firebase.User) {
console.log('subscribeToRemoteProfile'); console.log("subscribeToRemoteProfile");
if (!user || this.firebaseUser) return; if (!user || this.firebaseUser) return;
console.log('You got the firebase user.'); console.log("You got the firebase user.");
let obj = db.object('/settings/' + user.uid); let obj = db.object("/settings/" + user.uid);
this.remoteProfile = { this.remoteProfile = {
ref: obj as AngularFireObject<User>, ref: obj as AngularFireObject<User>,
stream: obj.valueChanges() as Observable<User> stream: obj.valueChanges() as Observable<User>
@ -136,7 +167,7 @@ export class ProfileService {
} }
handleRemotePreferenceChange(user: User) { handleRemotePreferenceChange(user: User) {
console.log('handleRemotePreferenceChange'); console.log("handleRemotePreferenceChange");
if (user) { if (user) {
let changed = false; let changed = false;
if (user.saved_pages !== undefined) { if (user.saved_pages !== undefined) {
@ -177,7 +208,7 @@ export class ProfileService {
} }
authenticate() { authenticate() {
console.log('Authenticating to remote...'); console.log("Authenticating to remote...");
let self = this; let self = this;
let provider = new firebase.auth.GoogleAuthProvider(); let provider = new firebase.auth.GoogleAuthProvider();
@ -200,13 +231,13 @@ export class ProfileService {
} }
refresh() { refresh() {
console.log('refresh'); console.log("refresh");
this.logout(); this.logout();
this.authenticate(); this.authenticate();
} }
logout() { logout() {
console.log('logout'); console.log("logout");
this.firebaseAuth.auth.signOut(); // sign out this.firebaseAuth.auth.signOut(); // sign out
this.remoteProfile = null; // inform the profile service not to bother this.remoteProfile = null; // inform the profile service not to bother
this.remoteLoggedIn = false; this.remoteLoggedIn = false;
@ -218,8 +249,8 @@ export class ProfileService {
} }
localSave() { localSave() {
console.log('saving local'); console.log("saving local");
this.local.set('profile', JSON.stringify(this.profile())); this.local.set("profile", JSON.stringify(this.profile()));
} }
private elapsed(start: Date, finish: Date) { private elapsed(start: Date, finish: Date) {
@ -252,7 +283,6 @@ export class ProfileService {
private resetUser() { private resetUser() {
this.profile().strongs_modal = true; this.profile().strongs_modal = true;
this.profile().clear_search_after_query = false;
this.profile().items = []; this.profile().items = [];
this.profile().append_to_bottom = false; this.profile().append_to_bottom = false;
this.profile().insert_next_to_item = false; this.profile().insert_next_to_item = false;
@ -282,11 +312,11 @@ export class ProfileService {
// TODO(jwall): This belongs somewhere else. // TODO(jwall): This belongs somewhere else.
textSizeChanged() { textSizeChanged() {
$('html').css('font-size', this.profile().font_size + 'px'); $("html").css("font-size", this.profile().font_size + "px");
} }
fontFamilyChanged() { fontFamilyChanged() {
document.querySelector('html').style.cssText = '--card-font: ' + this.profile().font_family; document.querySelector("html").style.cssText = "--card-font: " + this.profile().font_family;
this.textSizeChanged(); this.textSizeChanged();
} }
@ -295,11 +325,10 @@ export class ProfileService {
username: DEFAULT_USER_NAME, username: DEFAULT_USER_NAME,
uid: null, uid: null,
font_size: 10, font_size: 10,
font_family: 'roboto, helvetica, arial, sans-serif', font_family: "roboto, helvetica, arial, sans-serif",
saved_pages: [], saved_pages: [],
items: [], items: [],
strongs_modal: true, strongs_modal: true,
clear_search_after_query: false,
append_to_bottom: false, append_to_bottom: false,
insert_next_to_item: false, insert_next_to_item: false,
@ -322,7 +351,6 @@ export type User = {
username: string; username: string;
uid: string | null; uid: string | null;
strongs_modal: boolean; strongs_modal: boolean;
clear_search_after_query: boolean;
items: CardItem[]; items: CardItem[];
append_to_bottom: boolean; append_to_bottom: boolean;
insert_next_to_item: boolean; insert_next_to_item: boolean;