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. 36
      squarenotsquare/src/realm/dbAPI.js
  17. 90
      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. 104
      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';
function SquareNotSquare(props){
return (
<Provider store={props.squareStore}>
<SquareStack />
</Provider>
)
return (
<Provider store={props.squareStore}>
<SquareStack />
</Provider>
)
}
export default SquareNotSquare;

2
squarenotsquare/__mock__/mockDB.js

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

4
squarenotsquare/__mock__/mockKeyStore.js

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

226
squarenotsquare/__mock__/mockRealm.js

@ -1,135 +1,135 @@
// https://github.com/realm/realm-js/issues/370#issuecomment-270849466
export default class MockRealm {
constructor(params) {
this.schema = {};
this.schemaVersion = params.schemaVersion;
this.callbackList = [];
this.data = {};
this.schemaCallbackList = {};
params.schema.forEach((schema) => {
this.data[schema.name] = {};
});
params.schema.forEach((schema) => {
this.schema[schema.name] = schema;
});
this.lastLookedUpModel = null;
}
constructor(params) {
this.schema = {};
this.schemaVersion = params.schemaVersion;
this.callbackList = [];
this.data = {};
this.schemaCallbackList = {};
params.schema.forEach((schema) => {
this.data[schema.name] = {};
});
params.schema.forEach((schema) => {
this.schema[schema.name] = schema;
});
this.lastLookedUpModel = null;
}
objects(schemaName) {
this.lastLookedUpModel = schemaName;
const objects = Object.values(this.data[schemaName]);
objects.values = () => objects;
objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort();
objects.addListener = (cb) => {
if (this.schemaCallbackList[schemaName]) {
this.schemaCallbackList[schemaName].push(cb);
} else {
this.schemaCallbackList[schemaName] = [cb];
}
};
objects.removeListener = () => {};
objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects;
return objects;
objects(schemaName) {
this.lastLookedUpModel = schemaName;
const objects = Object.values(this.data[schemaName]);
objects.values = () => objects;
objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort();
objects.addListener = (cb) => {
if (this.schemaCallbackList[schemaName]) {
this.schemaCallbackList[schemaName].push(cb);
} else {
this.schemaCallbackList[schemaName] = [cb];
}
};
objects.removeListener = () => {};
objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects;
return objects;
}
write(fn) {
this.writing = true;
fn();
this.writing = false;
}
write(fn) {
this.writing = true;
fn();
this.writing = false;
}
create(schemaName, object) {
const modelObject = object;
const properties = this.schema[schemaName].schema.properties;
Object.keys(properties).forEach((key) => {
if (modelObject[key] && modelObject[key].model) {
this.data[modelObject[key].model][modelObject[key].id] = this.create(
modelObject[key].model, modelObject[key],
);
} else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) {
modelObject[key].forEach((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 = () => [];
}
}
create(schemaName, object) {
const modelObject = object;
const properties = this.schema[schemaName].schema.properties;
Object.keys(properties).forEach((key) => {
if (modelObject[key] && modelObject[key].model) {
this.data[modelObject[key].model][modelObject[key].id] = this.create(
modelObject[key].model, modelObject[key],
);
} else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) {
modelObject[key].forEach((obj) => {
this.data[modelObject[key][0].model][obj.id] = obj;
});
this.data[schemaName][modelObject.id] = modelObject;
if (this.writing) {
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(); });
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 = () => [];
}
return modelObject;
}
});
objectForPrimaryKey(model, id) {
this.lastLookedUpModel = model;
return this.data[model][id];
this.data[schemaName][modelObject.id] = modelObject;
if (this.writing) {
if (this.schemaCallbackList[schemaName]) {
this.schemaCallbackList[schemaName].forEach(cb => cb(schemaName, {
insertions: { length: 1 },
modifications: { length: 0 },
deletions: { length: 0 },
}));
}
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(); });
}
}
this.callbackList.forEach((cb) => { cb(); });
}
return modelObject;
}
deleteAll() {
Object.keys(this.schema).forEach((key) => {
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] = {};
objectForPrimaryKey(model, id) {
this.lastLookedUpModel = model;
return this.data[model][id];
}
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];
});
if (this.writing) this.callbackList.forEach((cb) => { cb(); });
}
addListener(event, callback) {
this.callbackList.push(callback);
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(); });
}
}
}
prepareData(schemaName, objects) {
objects.forEach((object) => {
this.create(schemaName, object);
});
deleteAll() {
Object.keys(this.schema).forEach((key) => {
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 {
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{
constructor(schemaVersion){
this.schemaVersion = schemaVersion;
this[System.name] = [];
this[Score.name] = [];
this[User.name] = [];
this.deletedKeys = [];
}
constructor(schemaVersion){
this.schemaVersion = schemaVersion;
this[System.name] = [];
this[Score.name] = [];
this[User.name] = [];
this.deletedKeys = [];
}
create(repoName, entity){
this[repoName].push(entity);
}
create(repoName, entity){
this[repoName].push(entity);
}
objects(repoName){
let objects = this[repoName];
objects.filtered = this.filtered ? this.filtered.bind(this, repoName) : () => objects;
return objects;
}
objects(repoName){
let objects = this[repoName];
objects.filtered = this.filtered ? this.filtered.bind(this, repoName) : () => objects;
return objects;
}
write(callback){
callback();
}
write(callback){
callback();
}
delete(key){
this.deletedKeys.push(key);
}
delete(key){
this.deletedKeys.push(key);
}
}

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

@ -8,10 +8,10 @@ const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
test('starts redux store', () => {
const localStore = mockStore();
return localStore.dispatch(appInit())
.then( () => {
const actualAction = localStore.getActions()[0];
expect(actualAction.type).toEqual(APP_INIT);
})
const localStore = mockStore();
return localStore.dispatch(appInit())
.then( () => {
const actualAction = localStore.getActions()[0];
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";
test('Realm migrates to V0', () => {
let oldRealm = new MockRealm(0);
let newRealm = new MockRealm(0);
migratev0(oldRealm, newRealm);
expect(newRealm.schemaVersion).toBe(0);
let oldRealm = new MockRealm(0);
let newRealm = new MockRealm(0);
migratev0(oldRealm, newRealm);
expect(newRealm.schemaVersion).toBe(0);
})
test('Realm migrates to V1', () => {
let oldRealm = new MockRealm(0);
let newRealm = new MockRealm(0);
migratev0(oldRealm, newRealm);
let oldRealm = new MockRealm(0);
let newRealm = new MockRealm(0);
migratev0(oldRealm, newRealm);
oldRealm = newRealm;
newRealm = new MockRealm(1);
migratev1(oldRealm, newRealm);
oldRealm = newRealm;
newRealm = new MockRealm(1);
migratev1(oldRealm, newRealm);
expect(newRealm[System.name][0].key).toBe('username');
expect(newRealm[System.name][0].value).toBe('changeme');
expect(newRealm[System.name][0].key).toBe('username');
expect(newRealm[System.name][0].value).toBe('changeme');
})
test('Realm halts V1 migration when schema is V2+', () => {
let oldRealm = new MockRealm(2);
newRealm = new MockRealm(1);
migratev1(oldRealm, newRealm);
oldRealm.create(System.name, {key: 'key1', value: 'value'})
let oldRealm = new MockRealm(2);
newRealm = new MockRealm(1);
migratev1(oldRealm, newRealm);
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';
test('ScoreRepo inits', () => {
let testRepo = new ScoreRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true);
let testRepo = new ScoreRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true);
})
test('SystemRepo inits', () => {
let testRepo = new SystemRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true);
let testRepo = new SystemRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true);
})
test('UserRepo inits', () => {
let testRepo = new UserRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true);
let testRepo = new UserRepo({fakeRealm: true});
expect(testRepo.realmDB.fakeRealm).toEqual(true);
})
test('SystemRepo gets all values', () => {
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let systemKey1 = {
id: uuidv4(),
key: 'key1',
value: 'val1'
};
let systemKey2 = {
id: uuidv4(),
key: 'key2',
value: 'val2'
};
mockRealm.create(System.name, systemKey1);
mockRealm.create(System.name, systemKey2);
let queried = testRepo.getAllSystemValues();
expect(queried[systemKey1.key]).toEqual('val1');
expect(queried[systemKey2.key]).toEqual('val2');
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let systemKey1 = {
id: uuidv4(),
key: 'key1',
value: 'val1'
};
let systemKey2 = {
id: uuidv4(),
key: 'key2',
value: 'val2'
};
mockRealm.create(System.name, systemKey1);
mockRealm.create(System.name, systemKey2);
let queried = testRepo.getAllSystemValues();
expect(queried[systemKey1.key]).toEqual('val1');
expect(queried[systemKey2.key]).toEqual('val2');
})
test('SystemRepo creates system value', () => {
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let newSystemKey = {
key: 'newKey',
value: 'isNew'
};
let newSystemKey = {
key: 'newKey',
value: 'isNew'
};
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
let object = mockRealm[System.name][0];
expect(object.value).toEqual('isNew');
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
let object = mockRealm[System.name][0];
expect(object.value).toEqual('isNew');
})
test('SystemRepo handles creation of existing system value', () => {
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let newSystemKey = {
key: 'newKey',
value: 'isNew'
};
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
let object = mockRealm[System.name][0];
expect(object.value).toEqual('isNew');
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let newSystemKey = {
key: 'newKey',
value: 'isNew'
};
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
let object = mockRealm[System.name][0];
expect(object.value).toEqual('isNew');
})
test('SystemRepo deletes existing system value', () => {
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let newSystemKey = {
key: 'newKey',
value: 'isNew'
};
let newSystemKey = {
key: 'newKey',
value: 'isNew'
};
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
testRepo.deleteSystemValue(newSystemKey.key);
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
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', () => {
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
testRepo.deleteSystemValue('key');
expect(mockRealm.deletedKeys.length).toEqual(0);
testRepo.deleteSystemValue('key');
expect(mockRealm.deletedKeys.length).toEqual(0);
})
test('SystemRepo gets multiple system values', () => {
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let systemKey1 = {
id: uuidv4(),
key: 'key1',
value: 'val1'
};
let systemKey2 = {
id: uuidv4(),
key: 'key1',
value: 'val1'
};
mockRealm.create(System.name, systemKey1);
mockRealm.create(System.name, systemKey2);
let response = testRepo.getSystemKeyValue(systemKey1.key);
expect(response).toEqual('Multiple system keys found for key1');
let mockRealm = new MockRealm(0);
let testRepo = new SystemRepo(mockRealm);
let systemKey1 = {
id: uuidv4(),
key: 'key1',
value: 'val1'
};
let systemKey2 = {
id: uuidv4(),
key: 'key1',
value: 'val1'
};
mockRealm.create(System.name, systemKey1);
mockRealm.create(System.name, systemKey2);
let response = testRepo.getSystemKeyValue(systemKey1.key);
expect(response).toEqual('Multiple system keys found for key1');
})

2
squarenotsquare/index.js

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

28
squarenotsquare/jest.config.js

@ -1,16 +1,16 @@
module.exports = {
// setupFiles: ['./jestSetup.js'],
preset: 'react-native',
verbose: true,
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'],
moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: {
// '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.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'
},
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
}
// setupFiles: ['./jestSetup.js'],
preset: 'react-native',
verbose: true,
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'],
moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: {
// '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.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'
},
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
}
}

12
squarenotsquare/metro.config.js

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

18
squarenotsquare/src/libs/Random.js

@ -1,13 +1,13 @@
export function generateKey() {
let result = [];
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length;
let result = [];
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length;
for (let i = 0; i < 64; i++) {
result.push(
characters.charAt(Math.floor(Math.random() * charactersLength)),
);
}
for (let i = 0; i < 64; i++) {
result.push(
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 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();
function SquareStack() {
let noHeader = {headerShown: false};
let noHeader = {headerShown: false};
return (
<NavigationContainer ref={squareRef}>
<SquareNav.Navigator initialRouteName="Splash">
<SquareNav.Screen
name="Splash"
component={Splash}
options={noHeader}
/>
<SquareNav.Screen
name="Home"
component={Home}
options={noHeader}
/>
<SquareNav.Screen
name="HighScore"
component={HighScore}
options={noHeader}
/>
<SquareNav.Screen
name="Settings"
component={Settings}
options={noHeader}
/>
<SquareNav.Screen
name="Game"
component={Game}
options={noHeader}
/>
</SquareNav.Navigator>
</NavigationContainer>
)
return (
<NavigationContainer ref={squareRef}>
<SquareNav.Navigator initialRouteName="Splash">
<SquareNav.Screen
name="Splash"
component={Splash}
options={noHeader}
/>
<SquareNav.Screen
name="Home"
component={Home}
options={noHeader}
/>
<SquareNav.Screen
name="HighScore"
component={HighScore}
options={noHeader}
/>
<SquareNav.Screen
name="Settings"
component={Settings}
options={noHeader}
/>
<SquareNav.Screen
name="Game"
component={Game}
options={noHeader}
/>
</SquareNav.Navigator>
</NavigationContainer>
)
}
export default SquareStack;

36
squarenotsquare/src/realm/dbAPI.js

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

90
squarenotsquare/src/realm/dbInit.js

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

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

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

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

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

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

@ -1,3 +1,3 @@
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';
export function migratev1(oldRealm, newRealm) {
if (oldRealm.schemaVersion === 0) {
newRealm.create(System.name, {
id: uuidv4(),
key: 'username',
value: 'changeme'
});
}
if (oldRealm.schemaVersion === 0) {
newRealm.create(System.name, {
id: uuidv4(),
key: 'username',
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';
export default class ScoreRepo {
realmDB = null;
realmDB = null;
constructor(db) {
this.realmDB = db;
}
constructor(db) {
this.realmDB = db;
}
}

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

@ -3,63 +3,63 @@ import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
export default class SystemRepo {
realmDB = null;
realmDB = null;
constructor(db) {
this.realmDB = db;
}
constructor(db) {
this.realmDB = db;
}
getAllSystemValues = () => {
let system = this.realmDB.objects(System.name);
let systemValues = {};
system.forEach((row) => {
systemValues[row.key] = row.value;
});
return systemValues;
};
getAllSystemValues = () => {
let system = this.realmDB.objects(System.name);
let systemValues = {};
system.forEach((row) => {
systemValues[row.key] = row.value;
});
return systemValues;
};
createSystemValue = (key, value) => {
let sysID = null;
let sysKey = key;
let sysValue = value;
createSystemValue = (key, value) => {
let sysID = null;
let sysKey = key;
let sysValue = value;
let existing = this.getSystemKeyValue(key);
let existing = this.getSystemKeyValue(key);
if (existing.id === null) {
sysID = uuidv4();
} else {
sysID = existing.id;
}
this.realmDB.write(() => {
this.realmDB.create(
System.name,
{
id: sysID,
key: sysKey,
value: sysValue,
},
true,
);
});
};
if (existing.id === null) {
sysID = uuidv4();
} else {
sysID = existing.id;
}
this.realmDB.write(() => {
this.realmDB.create(
System.name,
{
id: sysID,
key: sysKey,
value: sysValue,
},
true,
);
});
};
deleteSystemValue = (key) => {
let existingKey = this.getSystemKeyValue(key);
if (existingKey.id !== null) {
this.realmDB.write(() => {
this.realmDB.delete(existingKey);
});
}
};
deleteSystemValue = (key) => {
let existingKey = this.getSystemKeyValue(key);
if (existingKey.id !== null) {
this.realmDB.write(() => {
this.realmDB.delete(existingKey);
});
}
};
getSystemKeyValue = (key) => {
let row = this.realmDB.objects(System.name).filtered('key = $0', key);
if (row.length === 1) {
return {id: row[0].id, value: row[0].value};
} else if (row.length > 1) {
return 'Multiple system keys found for ' + key;
} else {
return {id: null, value: null};
}
};
getSystemKeyValue = (key) => {
let row = this.realmDB.objects(System.name).filtered('key = $0', key);
if (row.length === 1) {
return {id: row[0].id, value: row[0].value};
} else if (row.length > 1) {
return 'Multiple system keys found for ' + key;
} else {
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';
export default class UserRepo {
realmDB = null;
realmDB = null;
constructor(db) {
this.realmDB = db;
}
constructor(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";
export function appInit() {
return async (dispatch) => {
await initDB();
dispatch(onInit());
}
return async (dispatch) => {
await initDB();
dispatch(onInit());
}
}
function onInit() {
return (dispatch) => {
dispatch({
type: APP_INIT
//system: system
//user: user
//score: score
});
}
return (dispatch) => {
dispatch({
type: APP_INIT
//system: system
//user: user
//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';
export function navReducer(state = {}, action){
switch (action.type) {
case APP_INIT:
//SquareNav.navigate('Home');
break;
default:
break;
}
switch (action.type) {
case APP_INIT:
//SquareNav.navigate('Home');
break;
default:
break;
}
return state;
return state;
}

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

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

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

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

10
squarenotsquare/src/screens/Game.js

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

10
squarenotsquare/src/screens/HighScore.js

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

10
squarenotsquare/src/screens/Home.js

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

10
squarenotsquare/src/screens/Settings.js

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

10
squarenotsquare/src/screens/Splash.js

@ -4,11 +4,11 @@ import { useState } from "react";
function Splash(props){
return (
<View>
<Text style={{color: 'black'}}>test</Text>
</View>
);
return (
<View>
<Text style={{color: 'black'}}>test</Text>
</View>
);
}
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';
export const styles = StyleSheet.create({
flex: {flex: 1},
flexDouble: {flex: 2},
flexTriple: {flex: 3},
flexHalf: {flex: 0.5},
flexThird: {flex: 0.33},
flexTwoThirds: {flex: 0.67},
flexRow: {flexDirection: 'row'},
flexColumn: {flexDirection: 'column'},
flexWrap: {flexWrap: 'wrap'},
flexShrink: {flexShrink: 1},
flex: {flex: 1},
flexDouble: {flex: 2},
flexTriple: {flex: 3},
flexHalf: {flex: 0.5},
flexThird: {flex: 0.33},
flexTwoThirds: {flex: 0.67},
flexRow: {flexDirection: 'row'},
flexColumn: {flexDirection: 'column'},
flexWrap: {flexWrap: 'wrap'},
flexShrink: {flexShrink: 1},
centeredJustify: {justifyContent: 'center'},
centeredItems: {alignItems: 'center'},
centeredContent: {alignContent: 'center'},
centeredSelf: {alignSelf: 'center'},
centeredJustify: {justifyContent: 'center'},
centeredItems: {alignItems: 'center'},
centeredContent: {alignContent: 'center'},
centeredSelf: {alignSelf: 'center'},
startAlign: {alignSelf: 'flex-start'},
endAlign: {alignSelf: 'flex-end'},
startJustify: {justifyContent: 'flex-start'},
endJustify: {justifyContent: 'flex-end'},
startAlign: {alignSelf: 'flex-start'},
endAlign: {alignSelf: 'flex-end'},
startJustify: {justifyContent: 'flex-start'},
endJustify: {justifyContent: 'flex-end'},
stretch: {alignSelf: 'stretch'},
absolute: {
position: 'absolute',
top: metrics.screenSections.headerHeight,
bottom: 0,
left: 0,
right: 0,
},
stretch: {alignSelf: 'stretch'},
absolute: {
position: 'absolute',
top: metrics.screenSections.headerHeight,
bottom: 0,
left: 0,
right: 0,
},
spaceBetween: {justifyContent: 'space-between'},
spaceEvenly: {justifyContent: 'space-evenly'},
spaceAround: {justifyContent: 'space-around'},
spaceBetween: {justifyContent: 'space-between'},
spaceEvenly: {justifyContent: 'space-evenly'},
spaceAround: {justifyContent: 'space-around'},
centeredText: {textAlign: 'center'},
rightText: {textAlign: 'right'},
leftText: {textAlign: 'left'},
centeredText: {textAlign: 'center'},
rightText: {textAlign: 'right'},
leftText: {textAlign: 'left'},
headerTitleFont: {fontSize: fonts.headerTitle.size},
largeFont: {fontSize: fonts.large.size},
mediumFont: {fontSize: fonts.medium.size},
smallFont: {fontSize: fonts.small.size},
tinyFont: {fontSize: fonts.tiny.size},
subFont: {fontSize: fonts.subFont.size},
tickFont: {fontSize: fonts.tickFont.size},
headerTitleFont: {fontSize: fonts.headerTitle.size},
largeFont: {fontSize: fonts.large.size},
mediumFont: {fontSize: fonts.medium.size},
smallFont: {fontSize: fonts.small.size},
tinyFont: {fontSize: fonts.tiny.size},
subFont: {fontSize: fonts.subFont.size},
tickFont: {fontSize: fonts.tickFont.size},
italic: {fontStyle: 'italic'},
greyText: {color: colors.material.grey600},
redText: {color: colors.material.red800},
blueText: {color: colors.material.blue400},
boldText: {fontWeight: 'bold'},
italic: {fontStyle: 'italic'},
greyText: {color: colors.material.grey600},
redText: {color: colors.material.red800},
blueText: {color: colors.material.blue400},
boldText: {fontWeight: 'bold'},
lightText: {color: colors.impulseColors.lightText},
darkText: {color: colors.impulseColors.black},
lightText: {color: colors.impulseColors.lightText},
darkText: {color: colors.impulseColors.black},
body: {
backgroundColor: colors.material.light,
}
body: {
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) {
await RNSecureKeyStore.remove(key).then(
(res) => {
console.log('Removed key ' + res);
},
(err) => {
console.log(err.message);
},
(res) => {
console.log('Removed key ' + res);
},
(err) => {
console.log(err.message);
},
);
}
export async function setKey(key, value) {
await RNSecureKeyStore.set(key, value, {
accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
}).then(
(res) => {
console.log('Set key ' + res);
},
(err) => {
console.log(err.message);
},
(res) => {
console.log('Set key ' + res);
},
(err) => {
console.log(err.message);
},
);
}
export async function getKey(key) {
let value = null;
await RNSecureKeyStore.get(key).then(
(res) => {
value = res;
},
(err) => {
console.log(err.message);
},
(res) => {
value = res;
},
(err) => {
console.log(err.message);
},
);
return value;
}

42
squarenotsquare/src/themes/Colors.js

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

80
squarenotsquare/src/themes/Fonts.js

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

6
squarenotsquare/src/themes/Icons.js

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

10
squarenotsquare/src/themes/Metrics.js

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