Browse Source

double space lines

pull/1/head
Tim Glasgow 2 years ago
parent
commit
f99c2188a6
  1. 10
      squarenotsquare/Launcher.js
  2. 2
      squarenotsquare/__mock__/mockDB.js
  3. 4
      squarenotsquare/__mock__/mockKeyStore.js
  4. 226
      squarenotsquare/__mock__/mockRealm.js
  5. 42
      squarenotsquare/__mock__/mockRealmObject.js
  6. 12
      squarenotsquare/__tests__/Action-Creators-test.js
  7. 7
      squarenotsquare/__tests__/DB-Setup-test.js
  8. 34
      squarenotsquare/__tests__/Migration-test.js
  9. 160
      squarenotsquare/__tests__/Repo-test.js
  10. 2
      squarenotsquare/index.js
  11. 28
      squarenotsquare/jest.config.js
  12. 12
      squarenotsquare/metro.config.js
  13. 18
      squarenotsquare/src/libs/Random.js
  14. 2
      squarenotsquare/src/navigation/SquareNav.js
  15. 64
      squarenotsquare/src/navigation/SquareStack.js
  16. 38
      squarenotsquare/src/realm/dbAPI.js
  17. 100
      squarenotsquare/src/realm/dbInit.js
  18. 14
      squarenotsquare/src/realm/entities/Score.js
  19. 14
      squarenotsquare/src/realm/entities/System.js
  20. 12
      squarenotsquare/src/realm/entities/User.js
  21. 2
      squarenotsquare/src/realm/migrations/MigrateV0.js
  22. 14
      squarenotsquare/src/realm/migrations/MigrateV1.js
  23. 8
      squarenotsquare/src/realm/repos/ScoreRepo.js
  24. 108
      squarenotsquare/src/realm/repos/SystemRepo.js
  25. 8
      squarenotsquare/src/realm/repos/UserRepo.js
  26. 24
      squarenotsquare/src/redux/actions/SystemActions.js
  27. 16
      squarenotsquare/src/redux/reducers/NavReducer.js
  28. 4
      squarenotsquare/src/redux/reducers/RootReducer.js
  29. 14
      squarenotsquare/src/redux/reducers/SystemReducer.js
  30. 10
      squarenotsquare/src/screens/Game.js
  31. 10
      squarenotsquare/src/screens/HighScore.js
  32. 10
      squarenotsquare/src/screens/Home.js
  33. 10
      squarenotsquare/src/screens/Settings.js
  34. 10
      squarenotsquare/src/screens/Splash.js
  35. 98
      squarenotsquare/src/screens/styles/AppStyles.js
  36. 38
      squarenotsquare/src/services/Keystore.js
  37. 42
      squarenotsquare/src/themes/Colors.js
  38. 80
      squarenotsquare/src/themes/Fonts.js
  39. 6
      squarenotsquare/src/themes/Icons.js
  40. 10
      squarenotsquare/src/themes/Metrics.js

10
squarenotsquare/Launcher.js

@ -3,11 +3,11 @@ import {Provider} from 'react-redux';
import SquareStack from './src/navigation/SquareStack'; import SquareStack from './src/navigation/SquareStack';
function SquareNotSquare(props){ function SquareNotSquare(props){
return ( return (
<Provider store={props.squareStore}> <Provider store={props.squareStore}>
<SquareStack /> <SquareStack />
</Provider> </Provider>
) )
} }
export default SquareNotSquare; export default SquareNotSquare;

2
squarenotsquare/__mock__/mockDB.js

@ -1,3 +1,3 @@
export async function initDB() { export async function initDB() {
return null; return null;
} }

4
squarenotsquare/__mock__/mockKeyStore.js

@ -1,9 +1,9 @@
export async function removeKey(key) { export async function removeKey(key) {
return true; return true;
} }
export async function setKey(key, value) { export async function setKey(key, value) {
return true; return true;
} }
export async function getKey(key) { export async function getKey(key) {

226
squarenotsquare/__mock__/mockRealm.js

@ -1,135 +1,135 @@
// https://github.com/realm/realm-js/issues/370#issuecomment-270849466 // https://github.com/realm/realm-js/issues/370#issuecomment-270849466
export default class MockRealm { export default class MockRealm {
constructor(params) { constructor(params) {
this.schema = {}; this.schema = {};
this.schemaVersion = params.schemaVersion; this.schemaVersion = params.schemaVersion;
this.callbackList = []; this.callbackList = [];
this.data = {}; this.data = {};
this.schemaCallbackList = {}; this.schemaCallbackList = {};
params.schema.forEach((schema) => { params.schema.forEach((schema) => {
this.data[schema.name] = {}; this.data[schema.name] = {};
}); });
params.schema.forEach((schema) => { params.schema.forEach((schema) => {
this.schema[schema.name] = schema; this.schema[schema.name] = schema;
}); });
this.lastLookedUpModel = null; this.lastLookedUpModel = null;
} }
objects(schemaName) { objects(schemaName) {
this.lastLookedUpModel = schemaName; this.lastLookedUpModel = schemaName;
const objects = Object.values(this.data[schemaName]); const objects = Object.values(this.data[schemaName]);
objects.values = () => objects; objects.values = () => objects;
objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort(); objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort();
objects.addListener = (cb) => { objects.addListener = (cb) => {
if (this.schemaCallbackList[schemaName]) { if (this.schemaCallbackList[schemaName]) {
this.schemaCallbackList[schemaName].push(cb); this.schemaCallbackList[schemaName].push(cb);
} else { } else {
this.schemaCallbackList[schemaName] = [cb]; this.schemaCallbackList[schemaName] = [cb];
}
};
objects.removeListener = () => {};
objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects;
return objects;
} }
};
objects.removeListener = () => {};
objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects;
return objects;
}
write(fn) { write(fn) {
this.writing = true; this.writing = true;
fn(); fn();
this.writing = false; this.writing = false;
} }
create(schemaName, object) { create(schemaName, object) {
const modelObject = object; const modelObject = object;
const properties = this.schema[schemaName].schema.properties; const properties = this.schema[schemaName].schema.properties;
Object.keys(properties).forEach((key) => { Object.keys(properties).forEach((key) => {
if (modelObject[key] && modelObject[key].model) { if (modelObject[key] && modelObject[key].model) {
this.data[modelObject[key].model][modelObject[key].id] = this.create( this.data[modelObject[key].model][modelObject[key].id] = this.create(
modelObject[key].model, modelObject[key], modelObject[key].model, modelObject[key],
); );
} else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) { } else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) {
modelObject[key].forEach((obj) => { modelObject[key].forEach((obj) => {
this.data[modelObject[key][0].model][obj.id] = obj; this.data[modelObject[key][0].model][obj.id] = obj;
});
modelObject[key].filtered = this.filtered ? this.filtered : () => modelObject[key];
modelObject[key].sorted = () => modelObject[key].sort();
} else if (modelObject[key] === undefined) {
if (typeof properties[key] === 'object' && properties[key].optional) {
modelObject[key] = null;
}
if (typeof properties[key] === 'object' && ['list', 'linkingObjects'].includes(properties[key].type)) {
modelObject[key] = [];
modelObject[key].filtered = () => [];
modelObject[key].sorted = () => [];
}
}
}); });
modelObject[key].filtered = this.filtered ? this.filtered : () => modelObject[key];
this.data[schemaName][modelObject.id] = modelObject; modelObject[key].sorted = () => modelObject[key].sort();
if (this.writing) { } else if (modelObject[key] === undefined) {
if (this.schemaCallbackList[schemaName]) { if (typeof properties[key] === 'object' && properties[key].optional) {
this.schemaCallbackList[schemaName].forEach(cb => cb(schemaName, { modelObject[key] = null;
insertions: { length: 1 }, }
modifications: { length: 0 }, if (typeof properties[key] === 'object' && ['list', 'linkingObjects'].includes(properties[key].type)) {
deletions: { length: 0 }, modelObject[key] = [];
})); modelObject[key].filtered = () => [];
} modelObject[key].sorted = () => [];
this.callbackList.forEach((cb) => { cb(); });
} }
return modelObject;
} }
});
objectForPrimaryKey(model, id) { this.data[schemaName][modelObject.id] = modelObject;
this.lastLookedUpModel = model; if (this.writing) {
return this.data[model][id]; if (this.schemaCallbackList[schemaName]) {
this.schemaCallbackList[schemaName].forEach(cb => cb(schemaName, {
insertions: { length: 1 },
modifications: { length: 0 },
deletions: { length: 0 },
}));
} }
this.callbackList.forEach((cb) => { cb(); });
delete(object) {
if (this.lastLookedUpModel || object.model) {
const model = object.model ? object.model : this.lastLookedUpModel
if (Array.isArray(object)) {
object.forEach((item) => {
delete this.data[model][item.id];
});
}
delete this.data[model][object.id];
if (this.writing) {
if (this.schemaCallbackList[model]) {
this.schemaCallbackList[model].forEach(cb => cb(model, {
insertions: { length: 0 },
modifications: { length: 0 },
deletions: { length: 1 },
}));
}
this.callbackList.forEach((cb) => { cb(); });
}
}
} }
return modelObject;
}
deleteAll() { objectForPrimaryKey(model, id) {
Object.keys(this.schema).forEach((key) => { this.lastLookedUpModel = model;
if (this.writing && this.schemaCallbackList[this.schema[key].name]) { return this.data[model][id];
this.schemaCallbackList[this.schema[key].name].forEach(cb => cb(key, { }
insertions: { length: 0 },
modifications: { length: 0 }, delete(object) {
deletions: { length: Object.values(this.data[this.schema[key].name]).length }, if (this.lastLookedUpModel || object.model) {
})); const model = object.model ? object.model : this.lastLookedUpModel
} if (Array.isArray(object)) {
this.data[this.schema[key].name] = {}; object.forEach((item) => {
delete this.data[model][item.id];
}); });
if (this.writing) this.callbackList.forEach((cb) => { cb(); });
} }
delete this.data[model][object.id];
addListener(event, callback) { if (this.writing) {
this.callbackList.push(callback); if (this.schemaCallbackList[model]) {
this.schemaCallbackList[model].forEach(cb => cb(model, {
insertions: { length: 0 },
modifications: { length: 0 },
deletions: { length: 1 },
}));
}
this.callbackList.forEach((cb) => { cb(); });
}
} }
}
prepareData(schemaName, objects) { deleteAll() {
objects.forEach((object) => { Object.keys(this.schema).forEach((key) => {
this.create(schemaName, object); if (this.writing && this.schemaCallbackList[this.schema[key].name]) {
}); this.schemaCallbackList[this.schema[key].name].forEach(cb => cb(key, {
insertions: { length: 0 },
modifications: { length: 0 },
deletions: { length: Object.values(this.data[this.schema[key].name]).length },
}));
} }
this.data[this.schema[key].name] = {};
});
if (this.writing) this.callbackList.forEach((cb) => { cb(); });
}
addListener(event, callback) {
this.callbackList.push(callback);
}
prepareData(schemaName, objects) {
objects.forEach((object) => {
this.create(schemaName, object);
});
}
} }
MockRealm.Object = class Object { MockRealm.Object = class Object {
isValid() { return true; } isValid() { return true; }
}; };

42
squarenotsquare/__mock__/mockRealmObject.js

@ -4,29 +4,29 @@ import { User } from "../src/realm/entities/User";
export class MockRealm{ export class MockRealm{
constructor(schemaVersion){ constructor(schemaVersion){
this.schemaVersion = schemaVersion; this.schemaVersion = schemaVersion;
this[System.name] = []; this[System.name] = [];
this[Score.name] = []; this[Score.name] = [];
this[User.name] = []; this[User.name] = [];
this.deletedKeys = []; this.deletedKeys = [];
} }
create(repoName, entity){ create(repoName, entity){
this[repoName].push(entity); this[repoName].push(entity);
} }
objects(repoName){ objects(repoName){
let objects = this[repoName]; let objects = this[repoName];
objects.filtered = this.filtered ? this.filtered.bind(this, repoName) : () => objects; objects.filtered = this.filtered ? this.filtered.bind(this, repoName) : () => objects;
return objects; return objects;
} }
write(callback){ write(callback){
callback(); callback();
} }
delete(key){ delete(key){
this.deletedKeys.push(key); this.deletedKeys.push(key);
} }
} }

12
squarenotsquare/__tests__/Action-Creators-test.js

@ -8,10 +8,10 @@ const middlewares = [thunk];
const mockStore = configureMockStore(middlewares); const mockStore = configureMockStore(middlewares);
test('starts redux store', () => { test('starts redux store', () => {
const localStore = mockStore(); const localStore = mockStore();
return localStore.dispatch(appInit()) return localStore.dispatch(appInit())
.then( () => { .then( () => {
const actualAction = localStore.getActions()[0]; const actualAction = localStore.getActions()[0];
expect(actualAction.type).toEqual(APP_INIT); expect(actualAction.type).toEqual(APP_INIT);
}) })
}); });

7
squarenotsquare/__tests__/DB-Setup-test.js

@ -0,0 +1,7 @@
import { initDB } from "../src/realm/dbInit";
test('Realm DB inits', async () => {
let realmDB = await initDB();
expect
});

34
squarenotsquare/__tests__/Migration-test.js

@ -4,30 +4,30 @@ import { migratev1 } from "../src/realm/migrations/MigrateV1";
import { MockRealm } from "../__mock__/mockRealmObject"; import { MockRealm } from "../__mock__/mockRealmObject";
test('Realm migrates to V0', () => { test('Realm migrates to V0', () => {
let oldRealm = new MockRealm(0); let oldRealm = new MockRealm(0);
let newRealm = new MockRealm(0); let newRealm = new MockRealm(0);
migratev0(oldRealm, newRealm); migratev0(oldRealm, newRealm);
expect(newRealm.schemaVersion).toBe(0); expect(newRealm.schemaVersion).toBe(0);
}) })
test('Realm migrates to V1', () => { test('Realm migrates to V1', () => {
let oldRealm = new MockRealm(0); let oldRealm = new MockRealm(0);
let newRealm = new MockRealm(0); let newRealm = new MockRealm(0);
migratev0(oldRealm, newRealm); migratev0(oldRealm, newRealm);
oldRealm = newRealm; oldRealm = newRealm;
newRealm = new MockRealm(1); newRealm = new MockRealm(1);
migratev1(oldRealm, newRealm); migratev1(oldRealm, newRealm);
expect(newRealm[System.name][0].key).toBe('username'); expect(newRealm[System.name][0].key).toBe('username');
expect(newRealm[System.name][0].value).toBe('changeme'); expect(newRealm[System.name][0].value).toBe('changeme');
}) })
test('Realm halts V1 migration when schema is V2+', () => { test('Realm halts V1 migration when schema is V2+', () => {
let oldRealm = new MockRealm(2); let oldRealm = new MockRealm(2);
newRealm = new MockRealm(1); newRealm = new MockRealm(1);
migratev1(oldRealm, newRealm); migratev1(oldRealm, newRealm);
oldRealm.create(System.name, {key: 'key1', value: 'value'}) oldRealm.create(System.name, {key: 'key1', value: 'value'})
expect(oldRealm[System.name].length).toBe(1); expect(oldRealm[System.name].length).toBe(1);
}) })

160
squarenotsquare/__tests__/Repo-test.js

@ -7,114 +7,114 @@ import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
test('ScoreRepo inits', () => { test('ScoreRepo inits', () => {
let testRepo = new ScoreRepo({fakeRealm: true}); let testRepo = new ScoreRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true); expect(testRepo.realmDB.fakeRealm).toEqual(true);
}) })
test('SystemRepo inits', () => { test('SystemRepo inits', () => {
let testRepo = new SystemRepo({fakeRealm: true}); let testRepo = new SystemRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true); expect(testRepo.realmDB.fakeRealm).toEqual(true);
}) })
test('UserRepo inits', () => { test('UserRepo inits', () => {
let testRepo = new UserRepo({fakeRealm: true}); let testRepo = new UserRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true); expect(testRepo.realmDB.fakeRealm).toEqual(true);
}) })
test('SystemRepo gets all values', () => { test('SystemRepo gets all values', () => {
let mockRealm = new MockRealm(0); let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm); let testRepo = new SystemRepo(mockRealm);
let systemKey1 = { let systemKey1 = {
id: uuidv4(), id: uuidv4(),
key: 'key1', key: 'key1',
value: 'val1' value: 'val1'
}; };
let systemKey2 = { let systemKey2 = {
id: uuidv4(), id: uuidv4(),
key: 'key2', key: 'key2',
value: 'val2' value: 'val2'
}; };
mockRealm.create(System.name, systemKey1); mockRealm.create(System.name, systemKey1);
mockRealm.create(System.name, systemKey2); mockRealm.create(System.name, systemKey2);
let queried = testRepo.getAllSystemValues(); let queried = testRepo.getAllSystemValues();
expect(queried[systemKey1.key]).toEqual('val1'); expect(queried[systemKey1.key]).toEqual('val1');
expect(queried[systemKey2.key]).toEqual('val2'); expect(queried[systemKey2.key]).toEqual('val2');
}) })
test('SystemRepo creates system value', () => { test('SystemRepo creates system value', () => {
let mockRealm = new MockRealm(0); let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm); let testRepo = new SystemRepo(mockRealm);
let newSystemKey = { let newSystemKey = {
key: 'newKey', key: 'newKey',
value: 'isNew' value: 'isNew'
}; };
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value); testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
let object = mockRealm[System.name][0]; let object = mockRealm[System.name][0];
expect(object.value).toEqual('isNew'); expect(object.value).toEqual('isNew');
}) })
test('SystemRepo handles creation of existing system value', () => { test('SystemRepo handles creation of existing system value', () => {
let mockRealm = new MockRealm(0); let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm); let testRepo = new SystemRepo(mockRealm);
let newSystemKey = { let newSystemKey = {
key: 'newKey', key: 'newKey',
value: 'isNew' value: 'isNew'
}; };
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value); testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value); testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
let object = mockRealm[System.name][0]; let object = mockRealm[System.name][0];
expect(object.value).toEqual('isNew'); expect(object.value).toEqual('isNew');
}) })
test('SystemRepo deletes existing system value', () => { test('SystemRepo deletes existing system value', () => {
let mockRealm = new MockRealm(0); let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm); let testRepo = new SystemRepo(mockRealm);
let newSystemKey = { let newSystemKey = {
key: 'newKey', key: 'newKey',
value: 'isNew' value: 'isNew'
}; };
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value); testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
testRepo.deleteSystemValue(newSystemKey.key); testRepo.deleteSystemValue(newSystemKey.key);
expect(mockRealm.deletedKeys[0].value).toEqual(newSystemKey.value); expect(mockRealm.deletedKeys[0].value).toEqual(newSystemKey.value);
}) })
test('SystemRepo deletes non-existing system value', () => { test('SystemRepo deletes non-existing system value', () => {
let mockRealm = new MockRealm(0); let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm); let testRepo = new SystemRepo(mockRealm);
testRepo.deleteSystemValue('key'); testRepo.deleteSystemValue('key');
expect(mockRealm.deletedKeys.length).toEqual(0); expect(mockRealm.deletedKeys.length).toEqual(0);
}) })
test('SystemRepo gets multiple system values', () => { test('SystemRepo gets multiple system values', () => {
let mockRealm = new MockRealm(0); let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm); let testRepo = new SystemRepo(mockRealm);
let systemKey1 = { let systemKey1 = {
id: uuidv4(), id: uuidv4(),
key: 'key1', key: 'key1',
value: 'val1' value: 'val1'
}; };
let systemKey2 = { let systemKey2 = {
id: uuidv4(), id: uuidv4(),
key: 'key1', key: 'key1',
value: 'val1' value: 'val1'
}; };
mockRealm.create(System.name, systemKey1); mockRealm.create(System.name, systemKey1);
mockRealm.create(System.name, systemKey2); mockRealm.create(System.name, systemKey2);
let response = testRepo.getSystemKeyValue(systemKey1.key); let response = testRepo.getSystemKeyValue(systemKey1.key);
expect(response).toEqual('Multiple system keys found for key1'); expect(response).toEqual('Multiple system keys found for key1');
}) })

2
squarenotsquare/index.js

@ -9,7 +9,7 @@ const squareStore = configStore;
squareStore.dispatch(appInit()); squareStore.dispatch(appInit());
const ProppedContainer = () => { const ProppedContainer = () => {
return <SquareNotSquare {...{squareStore: squareStore}} />; return <SquareNotSquare {...{squareStore: squareStore}} />;
}; };
AppRegistry.registerComponent(appName, () => ProppedContainer); AppRegistry.registerComponent(appName, () => ProppedContainer);

28
squarenotsquare/jest.config.js

@ -1,16 +1,16 @@
module.exports = { module.exports = {
// setupFiles: ['./jestSetup.js'], // setupFiles: ['./jestSetup.js'],
preset: 'react-native', preset: 'react-native',
verbose: true, verbose: true,
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'], setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'],
moduleDirectories: ['node_modules', 'src'], moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: { moduleNameMapper: {
// '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.js', // '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.js',
'../services/Keystore': '<rootDir>/__mock__/mockKeyStore.js', '../services/Keystore': '<rootDir>/__mock__/mockKeyStore.js',
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mock__/file.js' '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mock__/file.js'
}, },
transform: { transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest', '^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest', '^.+\\.(js|jsx)$': 'babel-jest',
} }
} }

12
squarenotsquare/metro.config.js

@ -7,11 +7,11 @@
module.exports = { module.exports = {
transformer: { transformer: {
getTransformOptions: async () => ({ getTransformOptions: async () => ({
transform: { transform: {
experimentalImportSupport: false, experimentalImportSupport: false,
inlineRequires: true, inlineRequires: true,
}, },
}), }),
}, },
}; };

18
squarenotsquare/src/libs/Random.js

@ -1,13 +1,13 @@
export function generateKey() { export function generateKey() {
let result = []; let result = [];
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length; let charactersLength = characters.length;
for (let i = 0; i < 64; i++) { for (let i = 0; i < 64; i++) {
result.push( result.push(
characters.charAt(Math.floor(Math.random() * charactersLength)), characters.charAt(Math.floor(Math.random() * charactersLength)),
); );
} }
return result.join(''); return result.join('');
} }

2
squarenotsquare/src/navigation/SquareNav.js

@ -3,5 +3,5 @@ import { createRef } from "react";
export const squareRef = createRef(); export const squareRef = createRef();
export function navigate(name, params) { export function navigate(name, params) {
squareRef.current?.navigate(name, params); squareRef.current?.navigate(name, params);
} }

64
squarenotsquare/src/navigation/SquareStack.js

@ -12,39 +12,39 @@ import Splash from '../screens/Splash';
const SquareNav = createStackNavigator(); const SquareNav = createStackNavigator();
function SquareStack() { function SquareStack() {
let noHeader = {headerShown: false}; let noHeader = {headerShown: false};
return ( return (
<NavigationContainer ref={squareRef}> <NavigationContainer ref={squareRef}>
<SquareNav.Navigator initialRouteName="Splash"> <SquareNav.Navigator initialRouteName="Splash">
<SquareNav.Screen <SquareNav.Screen
name="Splash" name="Splash"
component={Splash} component={Splash}
options={noHeader} options={noHeader}
/> />
<SquareNav.Screen <SquareNav.Screen
name="Home" name="Home"
component={Home} component={Home}
options={noHeader} options={noHeader}
/> />
<SquareNav.Screen <SquareNav.Screen
name="HighScore" name="HighScore"
component={HighScore} component={HighScore}
options={noHeader} options={noHeader}
/> />
<SquareNav.Screen <SquareNav.Screen
name="Settings" name="Settings"
component={Settings} component={Settings}
options={noHeader} options={noHeader}
/> />
<SquareNav.Screen <SquareNav.Screen
name="Game" name="Game"
component={Game} component={Game}
options={noHeader} options={noHeader}
/> />
</SquareNav.Navigator> </SquareNav.Navigator>
</NavigationContainer> </NavigationContainer>
) )
} }
export default SquareStack; export default SquareStack;

38
squarenotsquare/src/realm/dbAPI.js

@ -1,29 +1,29 @@
import {systemRepo, userRepo, scoreRepo} from './dbInit'; import {systemRepo, userRepo, scoreRepo} from './dbInit';
class realmAPI { class realmAPI {
constructor(){ constructor(){
if (realmDB === null) { if (realmDB === null) {
realmDB = this; realmDB = this;
}
return realmDB;
} }
getAllSystemValues() { return realmDB;
return systemRepo.getAllSystemValues(); }
}
createSystemValue(key, value) {
systemRepo.createSystemValue(key, value);
}
deleteSystemValue(key) { getAllSystemValues() {
systemRepo.deleteSystemValue(key); return systemRepo.getAllSystemValues();
} }
createSystemValue(key, value) {
systemRepo.createSystemValue(key, value);
}
getSystemValue(key) { deleteSystemValue(key) {
return systemRepo.getSystemKeyValue(key); systemRepo.deleteSystemValue(key);
} }
getSystemValue(key) {
return systemRepo.getSystemKeyValue(key);
}
} }
export let realmDB = new realmAPI(); export let realmDB = new realmAPI();

100
squarenotsquare/src/realm/dbInit.js

@ -22,61 +22,59 @@ let systemRepo = null;
let scoreRepo = null; let scoreRepo = null;
let userRepo = null; let userRepo = null;
let realmDB = null;
export async function initDB(){ export async function initDB(){
try { try {
const dbKeyRef = 'squareDB'; const dbKeyRef = 'squareDB';
let fromStore = await KeyStore.getKey(dbKeyRef); let fromStore = await KeyStore.getKey(dbKeyRef);
if (fromStore === null) { if (fromStore === null) {
let newKey = generateKey(); let newKey = generateKey();
await KeyStore.setKey(dbKeyRef, newKey); await KeyStore.setKey(dbKeyRef, newKey);
fromStore = await KeyStore.getKey(dbKeyRef); fromStore = await KeyStore.getKey(dbKeyRef);
} }
let dbKey = new Uint8Array(64); let dbKey = new Uint8Array(64);
if (fromStore !== null){ if (fromStore !== null){
for (let i = 0; i < 64; ++i){ for (let i = 0; i < 64; ++i){
dbKey[i] = fromStore.charAt(i); dbKey[i] = fromStore.charAt(i);
} }
} }
let dbRef = realmDB; let dbRef = null;
if (dbRef === null){ if (dbRef === null){
let schemaList = [ let schemaList = [
{schemaVersion: 0, schema: [System, User, Score], migration: migratev0, encryptionKey: dbKey}, {schemaVersion: 0, schema: [System, User, Score], migration: migratev0, encryptionKey: dbKey},
{schemaVersion: 1, schema: [System, User, Score], migration: migratev1, encryptionKey: dbKey} {schemaVersion: 1, schema: [System, User, Score], migration: migratev1, encryptionKey: dbKey}
] ]
let currentSchema = Realm.schemaVersion(Realm.defaultPath, dbKey); let currentSchema = Realm.schemaVersion(Realm.defaultPath, dbKey);
if (currentSchema === -1) { if (currentSchema === -1) {
currentSchema = 0; currentSchema = 0;
} }
while (currentSchema < schemaList.length) {
if (dbRef !== null) {
dbRef.close();
}
dbRef = new Realm(schemaList[currentSchema]); while (currentSchema < schemaList.length) {
currentSchema += 1; if (dbRef !== null) {
} dbRef.close();
if (dbRef === null) {
dbRef = new Realm(schemaList[schemaList.length - 1]);
}
systemRepo = new SystemRepo(dbRef);
userRepo = new UserRepo(dbRef);
scoreRepo = new ScoreRepo(dbRef)
} }
let realmDB = dbRef; dbRef = new Realm(schemaList[currentSchema]);
return realmDB; currentSchema += 1;
} catch (err) { }
console.log(err);
if (dbRef === null) {
dbRef = new Realm(schemaList[schemaList.length - 1]);
}
systemRepo = new SystemRepo(dbRef);
userRepo = new UserRepo(dbRef);
scoreRepo = new ScoreRepo(dbRef)
} }
return dbRef;
} catch (err) {
console.log(err);
return null;
}
} }

14
squarenotsquare/src/realm/entities/Score.js

@ -1,9 +1,9 @@
export const Score = { export const Score = {
name: 'Score', name: 'Score',
primaryKey: 'id', primaryKey: 'id',
properties: { properties: {
id: 'string', id: 'string',
user: 'string', user: 'string',
value: 'string' value: 'string'
} }
}; };

14
squarenotsquare/src/realm/entities/System.js

@ -1,9 +1,9 @@
export const System = { export const System = {
name: 'System', name: 'System',
primaryKey: 'id', primaryKey: 'id',
properties: { properties: {
id: 'string', id: 'string',
key: 'string', key: 'string',
value: 'string' value: 'string'
} }
}; };

12
squarenotsquare/src/realm/entities/User.js

@ -1,8 +1,8 @@
export const User = { export const User = {
name: 'User', name: 'User',
primaryKey: 'id', primaryKey: 'id',
properties: { properties: {
id: 'string', id: 'string',
name: 'string' name: 'string'
} }
} }

2
squarenotsquare/src/realm/migrations/MigrateV0.js

@ -1,3 +1,3 @@
export function migratev0(oldRealm, newRealm) { export function migratev0(oldRealm, newRealm) {
Function.prototype Function.prototype
} }

14
squarenotsquare/src/realm/migrations/MigrateV1.js

@ -3,11 +3,11 @@ import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export function migratev1(oldRealm, newRealm) { export function migratev1(oldRealm, newRealm) {
if (oldRealm.schemaVersion === 0) { if (oldRealm.schemaVersion === 0) {
newRealm.create(System.name, { newRealm.create(System.name, {
id: uuidv4(), id: uuidv4(),
key: 'username', key: 'username',
value: 'changeme' value: 'changeme'
}); });
} }
} }

8
squarenotsquare/src/realm/repos/ScoreRepo.js

@ -3,9 +3,9 @@ import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export default class ScoreRepo { export default class ScoreRepo {
realmDB = null; realmDB = null;
constructor(db) { constructor(db) {
this.realmDB = db; this.realmDB = db;
} }
} }

108
squarenotsquare/src/realm/repos/SystemRepo.js

@ -3,63 +3,63 @@ import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export default class SystemRepo { export default class SystemRepo {
realmDB = null; realmDB = null;
constructor(db) { constructor(db) {
this.realmDB = db; this.realmDB = db;
} }
getAllSystemValues = () => { getAllSystemValues = () => {
let system = this.realmDB.objects(System.name); let system = this.realmDB.objects(System.name);
let systemValues = {}; let systemValues = {};
system.forEach((row) => { system.forEach((row) => {
systemValues[row.key] = row.value; systemValues[row.key] = row.value;
}); });
return systemValues; return systemValues;
}; };
createSystemValue = (key, value) => { createSystemValue = (key, value) => {
let sysID = null; let sysID = null;
let sysKey = key; let sysKey = key;
let sysValue = value; let sysValue = value;
let existing = this.getSystemKeyValue(key); let existing = this.getSystemKeyValue(key);
if (existing.id === null) { if (existing.id === null) {
sysID = uuidv4(); sysID = uuidv4();
} else { } else {
sysID = existing.id; sysID = existing.id;
} }
this.realmDB.write(() => { this.realmDB.write(() => {
this.realmDB.create( this.realmDB.create(
System.name, System.name,
{ {
id: sysID, id: sysID,
key: sysKey, key: sysKey,
value: sysValue, value: sysValue,
}, },
true, true,
); );
}); });
}; };
deleteSystemValue = (key) => { deleteSystemValue = (key) => {
let existingKey = this.getSystemKeyValue(key); let existingKey = this.getSystemKeyValue(key);
if (existingKey.id !== null) { if (existingKey.id !== null) {
this.realmDB.write(() => { this.realmDB.write(() => {
this.realmDB.delete(existingKey); this.realmDB.delete(existingKey);
}); });
} }
}; };
getSystemKeyValue = (key) => { getSystemKeyValue = (key) => {
let row = this.realmDB.objects(System.name).filtered('key = $0', key); let row = this.realmDB.objects(System.name).filtered('key = $0', key);
if (row.length === 1) { if (row.length === 1) {
return {id: row[0].id, value: row[0].value}; return {id: row[0].id, value: row[0].value};
} else if (row.length > 1) { } else if (row.length > 1) {
return 'Multiple system keys found for ' + key; return 'Multiple system keys found for ' + key;
} else { } else {
return {id: null, value: null}; return {id: null, value: null};
} }
}; };
} }

8
squarenotsquare/src/realm/repos/UserRepo.js

@ -3,9 +3,9 @@ import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export default class UserRepo { export default class UserRepo {
realmDB = null; realmDB = null;
constructor(db) { constructor(db) {
this.realmDB = db; this.realmDB = db;
} }
} }

24
squarenotsquare/src/redux/actions/SystemActions.js

@ -3,19 +3,19 @@ import { realmDB } from "../../realm/dbAPI";
import { APP_INIT } from "../types/SystemTypes"; import { APP_INIT } from "../types/SystemTypes";
export function appInit() { export function appInit() {
return async (dispatch) => { return async (dispatch) => {
await initDB(); await initDB();
dispatch(onInit()); dispatch(onInit());
} }
} }
function onInit() { function onInit() {
return (dispatch) => { return (dispatch) => {
dispatch({ dispatch({
type: APP_INIT type: APP_INIT
//system: system //system: system
//user: user //user: user
//score: score //score: score
}); });
} }
} }

16
squarenotsquare/src/redux/reducers/NavReducer.js

@ -3,13 +3,13 @@ import * as SquareNav from '../../navigation/SquareNav';
import { APP_INIT } from '../types/SystemTypes'; import { APP_INIT } from '../types/SystemTypes';
export function navReducer(state = {}, action){ export function navReducer(state = {}, action){
switch (action.type) { switch (action.type) {
case APP_INIT: case APP_INIT:
//SquareNav.navigate('Home'); //SquareNav.navigate('Home');
break; break;
default: default:
break; break;
} }
return state; return state;
} }

4
squarenotsquare/src/redux/reducers/RootReducer.js

@ -3,8 +3,8 @@ import { systemReducer } from './SystemReducer';
import { navReducer } from './NavReducer'; import { navReducer } from './NavReducer';
const rootReducer = combineReducers({ const rootReducer = combineReducers({
...systemReducer, ...systemReducer,
navReducer navReducer
}); });
export default rootReducer; export default rootReducer;

14
squarenotsquare/src/redux/reducers/SystemReducer.js

@ -1,14 +1,14 @@
import { APP_INIT } from "../types/SystemTypes"; import { APP_INIT } from "../types/SystemTypes";
function sys(state = {}, action) { function sys(state = {}, action) {
switch (action.type) { switch (action.type) {
case APP_INIT: case APP_INIT:
return {...state, ...action.system}; return {...state, ...action.system};
default: default:
return state; return state;
} }
} }
export const systemReducer = { export const systemReducer = {
system: sys system: sys
}; };

10
squarenotsquare/src/screens/Game.js

@ -4,11 +4,11 @@ import { useState } from "react";
function Game(props){ function Game(props){
return ( return (
<View> <View>
<Text style={{color: 'black'}}>test</Text> <Text style={{color: 'black'}}>test</Text>
</View> </View>
); );
} }
export default Game; export default Game;

10
squarenotsquare/src/screens/HighScore.js

@ -4,11 +4,11 @@ import { useState } from "react";
function HighScore(props){ function HighScore(props){
return ( return (
<View> <View>
<Text style={{color: 'black'}}>test</Text> <Text style={{color: 'black'}}>test</Text>
</View> </View>
); );
} }
export default HighScore; export default HighScore;

10
squarenotsquare/src/screens/Home.js

@ -4,11 +4,11 @@ import { useState } from "react";
function Home(props){ function Home(props){
return ( return (
<View> <View>
<Text style={{color: 'black'}}>test</Text> <Text style={{color: 'black'}}>test</Text>
</View> </View>
); );
} }
export default Home; export default Home;

10
squarenotsquare/src/screens/Settings.js

@ -4,11 +4,11 @@ import { useState } from "react";
function Settings(props){ function Settings(props){
return ( return (
<View> <View>
<Text style={{color: 'black'}}>test</Text> <Text style={{color: 'black'}}>test</Text>
</View> </View>
); );
} }
export default Settings; export default Settings;

10
squarenotsquare/src/screens/Splash.js

@ -4,11 +4,11 @@ import { useState } from "react";
function Splash(props){ function Splash(props){
return ( return (
<View> <View>
<Text style={{color: 'black'}}>test</Text> <Text style={{color: 'black'}}>test</Text>
</View> </View>
); );
} }
export default Splash; export default Splash;

98
squarenotsquare/src/screens/styles/AppStyles.js

@ -4,62 +4,62 @@ import * as fonts from '../../themes/Fonts';
import * as metrics from '../../themes/Metrics'; import * as metrics from '../../themes/Metrics';
export const styles = StyleSheet.create({ export const styles = StyleSheet.create({
flex: {flex: 1}, flex: {flex: 1},
flexDouble: {flex: 2}, flexDouble: {flex: 2},
flexTriple: {flex: 3}, flexTriple: {flex: 3},
flexHalf: {flex: 0.5}, flexHalf: {flex: 0.5},
flexThird: {flex: 0.33}, flexThird: {flex: 0.33},
flexTwoThirds: {flex: 0.67}, flexTwoThirds: {flex: 0.67},
flexRow: {flexDirection: 'row'}, flexRow: {flexDirection: 'row'},
flexColumn: {flexDirection: 'column'}, flexColumn: {flexDirection: 'column'},
flexWrap: {flexWrap: 'wrap'}, flexWrap: {flexWrap: 'wrap'},
flexShrink: {flexShrink: 1}, flexShrink: {flexShrink: 1},
centeredJustify: {justifyContent: 'center'}, centeredJustify: {justifyContent: 'center'},
centeredItems: {alignItems: 'center'}, centeredItems: {alignItems: 'center'},
centeredContent: {alignContent: 'center'}, centeredContent: {alignContent: 'center'},
centeredSelf: {alignSelf: 'center'}, centeredSelf: {alignSelf: 'center'},
startAlign: {alignSelf: 'flex-start'}, startAlign: {alignSelf: 'flex-start'},
endAlign: {alignSelf: 'flex-end'}, endAlign: {alignSelf: 'flex-end'},
startJustify: {justifyContent: 'flex-start'}, startJustify: {justifyContent: 'flex-start'},
endJustify: {justifyContent: 'flex-end'}, endJustify: {justifyContent: 'flex-end'},
stretch: {alignSelf: 'stretch'}, stretch: {alignSelf: 'stretch'},
absolute: { absolute: {
position: 'absolute', position: 'absolute',
top: metrics.screenSections.headerHeight, top: metrics.screenSections.headerHeight,
bottom: 0, bottom: 0,
left: 0, left: 0,
right: 0, right: 0,
}, },
spaceBetween: {justifyContent: 'space-between'}, spaceBetween: {justifyContent: 'space-between'},
spaceEvenly: {justifyContent: 'space-evenly'}, spaceEvenly: {justifyContent: 'space-evenly'},
spaceAround: {justifyContent: 'space-around'}, spaceAround: {justifyContent: 'space-around'},
centeredText: {textAlign: 'center'}, centeredText: {textAlign: 'center'},
rightText: {textAlign: 'right'}, rightText: {textAlign: 'right'},
leftText: {textAlign: 'left'}, leftText: {textAlign: 'left'},
headerTitleFont: {fontSize: fonts.headerTitle.size}, headerTitleFont: {fontSize: fonts.headerTitle.size},
largeFont: {fontSize: fonts.large.size}, largeFont: {fontSize: fonts.large.size},
mediumFont: {fontSize: fonts.medium.size}, mediumFont: {fontSize: fonts.medium.size},
smallFont: {fontSize: fonts.small.size}, smallFont: {fontSize: fonts.small.size},
tinyFont: {fontSize: fonts.tiny.size}, tinyFont: {fontSize: fonts.tiny.size},
subFont: {fontSize: fonts.subFont.size}, subFont: {fontSize: fonts.subFont.size},
tickFont: {fontSize: fonts.tickFont.size}, tickFont: {fontSize: fonts.tickFont.size},
italic: {fontStyle: 'italic'}, italic: {fontStyle: 'italic'},
greyText: {color: colors.material.grey600}, greyText: {color: colors.material.grey600},
redText: {color: colors.material.red800}, redText: {color: colors.material.red800},
blueText: {color: colors.material.blue400}, blueText: {color: colors.material.blue400},
boldText: {fontWeight: 'bold'}, boldText: {fontWeight: 'bold'},
lightText: {color: colors.impulseColors.lightText}, lightText: {color: colors.impulseColors.lightText},
darkText: {color: colors.impulseColors.black}, darkText: {color: colors.impulseColors.black},
body: { body: {
backgroundColor: colors.material.light, backgroundColor: colors.material.light,
} }
}) })

38
squarenotsquare/src/services/Keystore.js

@ -2,37 +2,37 @@ import RNSecureKeyStore, {ACCESSIBLE} from 'react-native-secure-key-store';
export async function removeKey(key) { export async function removeKey(key) {
await RNSecureKeyStore.remove(key).then( await RNSecureKeyStore.remove(key).then(
(res) => { (res) => {
console.log('Removed key ' + res); console.log('Removed key ' + res);
}, },
(err) => { (err) => {
console.log(err.message); console.log(err.message);
}, },
); );
} }
export async function setKey(key, value) { export async function setKey(key, value) {
await RNSecureKeyStore.set(key, value, { await RNSecureKeyStore.set(key, value, {
accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY, accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
}).then( }).then(
(res) => { (res) => {
console.log('Set key ' + res); console.log('Set key ' + res);
}, },
(err) => { (err) => {
console.log(err.message); console.log(err.message);
}, },
); );
} }
export async function getKey(key) { export async function getKey(key) {
let value = null; let value = null;
await RNSecureKeyStore.get(key).then( await RNSecureKeyStore.get(key).then(
(res) => { (res) => {
value = res; value = res;
}, },
(err) => { (err) => {
console.log(err.message); console.log(err.message);
}, },
); );
return value; return value;
} }

42
squarenotsquare/src/themes/Colors.js

@ -1,31 +1,31 @@
export const material = { export const material = {
dark: '#212121', dark: '#212121',
light: '#ffffff', light: '#ffffff',
//200 //200
blue200: '#90caf9', blue200: '#90caf9',
//400 //400
blue400: '#5c6bc0', blue400: '#5c6bc0',
grey400: '#bdbdbd', grey400: '#bdbdbd',
//600 //600
grey600: '#757575', grey600: '#757575',
//700 //700
grey700: '#616161', grey700: '#616161',
//800 //800
amber800: '#ff8f00', amber800: '#ff8f00',
blue800: '#1565c0', blue800: '#1565c0',
red800: '#c62828', red800: '#c62828',
red800dark: '#7f0000', red800dark: '#7f0000',
grey800: '#424242', grey800: '#424242',
grey800dark: '#1b1b1b', grey800dark: '#1b1b1b',
green800: '#2e7d32', green800: '#2e7d32',
} }
export const fonts = { export const fonts = {
dark: '#000000', dark: '#000000',
light: '#ffffff' light: '#ffffff'
}; };

80
squarenotsquare/src/themes/Fonts.js

@ -3,47 +3,47 @@ import {PixelRatio} from 'react-native';
const scalar = PixelRatio.getFontScale(); const scalar = PixelRatio.getFontScale();
function normalizeFont(size) { function normalizeFont(size) {
return size * scalar return size * scalar
}; };
export const fonts = { export const fonts = {
headerTitle: { headerTitle: {
fam: 'arial', fam: 'arial',
size: normalizeFont(30), size: normalizeFont(30),
}, },
sectionHeader: { sectionHeader: {
fam: 'arial', fam: 'arial',
size: normalizeFont(26), size: normalizeFont(26),
}, },
large: { large: {
fam: 'arial', fam: 'arial',
size: normalizeFont(22), size: normalizeFont(22),
}, },
medium: { medium: {
fam: 'arial', fam: 'arial',
size: normalizeFont(20), size: normalizeFont(20),
}, },
small: { small: {
fam: 'arial', fam: 'arial',
size: normalizeFont(16), size: normalizeFont(16),
}, },
tiny: { tiny: {
fam: 'arial', fam: 'arial',
size: normalizeFont(14), size: normalizeFont(14),
}, },
mini: { mini: {
fam: 'arial', fam: 'arial',
size: normalizeFont(10), size: normalizeFont(10),
}, },
subFont: { subFont: {
fam: 'arial', fam: 'arial',
size: normalizeFont(8), size: normalizeFont(8),
}, },
} }

6
squarenotsquare/src/themes/Icons.js

@ -1,5 +1,5 @@
export const squareIcons = { export const squareIcons = {
settings: 'cog-outline', settings: 'cog-outline',
toggleOn: 'toggle-switch-on', toggleOn: 'toggle-switch-on',
toggleOfff: 'toggle-switch-off' toggleOfff: 'toggle-switch-off'
}; };

10
squarenotsquare/src/themes/Metrics.js

@ -3,7 +3,7 @@ import { PixelRatio, Dimensions } from "react-native";
let scalar = PixelRatio.get(); let scalar = PixelRatio.get();
function normalize(size){ function normalize(size){
return (size * scalar); return (size * scalar);
} }
let dimensions = Dimensions.get('window'); let dimensions = Dimensions.get('window');
@ -15,11 +15,11 @@ let screenWidth = width;
let screenHeight = height; let screenHeight = height;
if (width > height) { if (width > height) {
screenHeight = width; screenHeight = width;
screenWidth = height; screenWidth = height;
} }
export const screenSections = { export const screenSections = {
headerHeight: normalize(20), headerHeight: normalize(20),
sectionWidth: screenWidth sectionWidth: screenWidth
} }
Loading…
Cancel
Save