Skip to content

Commit

Permalink
Merge branch 'dev' to release [1.1.0]
Browse files Browse the repository at this point in the history
  • Loading branch information
lucka-me committed May 31, 2021
2 parents 4eea4be + 13d82ce commit a1cb72c
Show file tree
Hide file tree
Showing 13 changed files with 1,575 additions and 2,738 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
Noteable changes of Potori will be documented here.

## [1.1.0](https://github.com/lucka-me/potori/releases/tag/1.1.0) - 2021-05-31
Update dependencies

## Changed
- Update dependencies

## [1.0.0](https://github.com/lucka-me/potori/releases/tag/1.0.0) - 2021-04-08
Rebuild with Vue

Expand Down
4,014 changes: 1,450 additions & 2,564 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "potori",
"version": "1.0.0",
"version": "1.1.0",
"description": "Web App to Visualize Ingress Nominations",
"scripts": {
"postinstall": "ts-node --project scripts/tsconfig.json ./scripts/prepare.ts && tsc -m commonjs --esModuleInterop vue.config.ts",
"prestart": "ts-node --project scripts/tsconfig.json ./scripts/prepare.ts",
"prebuild": "ts-node --project scripts/tsconfig.json ./scripts/prepare.ts",
"postinstall": "ts-node ./scripts/prepare.ts && tsc -m commonjs --esModuleInterop vue.config.ts",
"prestart": "ts-node ./scripts/prepare.ts",
"prebuild": "ts-node ./scripts/prepare.ts",
"build-config": "tsc -m commonjs --esModuleInterop vue.config.ts",
"start": "vue-cli-service serve",
"build": "vue-cli-service build"
Expand All @@ -17,40 +17,40 @@
"author": "lucka-me",
"license": "MIT",
"dependencies": {
"@firebase/app": "^0.6.17",
"@firebase/database": "^0.9.6",
"@firebase/app": "^0.6.22",
"@firebase/database": "^0.10.2",
"@fortawesome/fontawesome-free": "^5.15.3",
"@lucka-labs/eli": "^0.1.2",
"chart.js": "^3.0.2",
"chart.js": "^3.3.1",
"chartjs-adapter-luxon": "^1.0.0",
"luxon": "^1.26.0",
"mapbox-gl": "^2.2.0",
"luxon": "^1.27.0",
"mapbox-gl": "^2.3.0",
"material-components-web": "^10.0.0",
"register-service-worker": "^1.7.2",
"vue": "^3.0.11",
"vue-class-component": "^8.0.0-rc.1",
"vue-i18n": "^9.0.0",
"vue-i18n": "^9.1.6",
"vue-property-decorator": "^10.0.0-rc.3",
"vue-router": "^4.0.4",
"vuex": "^4.0.0"
"vue-router": "^4.0.8",
"vuex": "^4.0.1"
},
"devDependencies": {
"@types/gapi.auth2": "^0.0.54",
"@types/gapi.client.drive": "^3.0.13",
"@types/gapi.client.gmail": "^1.0.3",
"@types/luxon": "^1.26.2",
"@types/mapbox-gl": "^2.1.1",
"@types/luxon": "^1.26.5",
"@types/mapbox-gl": "^2.1.2",
"@types/webpack-bundle-analyzer": "^3.9.2",
"@vue/cli-plugin-pwa": "^4.5.12",
"@vue/cli-plugin-pwa": "^4.5.13",
"@vue/cli-plugin-router": "^4.5.12",
"@vue/cli-plugin-typescript": "^4.5.12",
"@vue/cli-plugin-typescript": "^4.5.13",
"@vue/cli-plugin-vuex": "^4.5.12",
"@vue/cli-service": "^4.5.12",
"@vue/cli-service": "^4.5.13",
"@vue/compiler-sfc": "^3.0.11",
"sass": "^1.30.0",
"sass": "^1.34.0",
"sass-loader": "^10.1.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"webpack-bundle-analyzer": "^4.4.0"
"ts-node": "^10.0.0",
"typescript": "^4.3.2",
"webpack-bundle-analyzer": "^4.4.2"
}
}
2 changes: 1 addition & 1 deletion src/data/umi
26 changes: 6 additions & 20 deletions src/service/brainstorming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,7 @@ import type { Reference } from '@firebase/database-types';
import { umi } from '@/service/umi';
import { util } from '../utils';
import { ProgressCallback } from '../types';
import Nomination, { NominationData } from '@/service/nomination';

/**
* Result for {@link BrainstormingKit.analyse}
*/
interface BrainstormingStats {
review: number, // Review count
nomination: number, // Count of nominations containing reviews
rate: Map<string, Array<number>>, // Map of rate lists
reviewTimes: Array<number>, // List of review timestamps
synch: {
total: number, // Count of reviews of resulted nominations
synched: number // Count of reviews matches the result
},
}
import Nomination, { NominationRAW } from '@/service/nomination';

/**
* Host Brainstorming data and handle tasks related to Brainstorming
Expand Down Expand Up @@ -92,7 +78,7 @@ export namespace brainstorming {
* @param succeed Triggered when succeed to query data
* @param failed Triggered when Failed to query data
*/
export async function query(nomination: NominationData): Promise<Record> {
export async function query(nomination: NominationRAW): Promise<Record> {
if (beforeCreate(nomination)) {
throw new Error(FailReason.EARLY);
}
Expand All @@ -108,7 +94,7 @@ export namespace brainstorming {
* @param nominations Nomination list
* @param finish Triggered when all query finishes
*/
export async function update(nominations: Array<NominationData>, callback: ProgressCallback): Promise<number> {
export async function update(nominations: Array<NominationRAW>, callback: ProgressCallback): Promise<number> {
let succeed = 0;
let processed = 0;
const total = nominations.length;
Expand All @@ -132,12 +118,12 @@ export namespace brainstorming {
return succeed;
}

export async function getFromLocal(nomination: NominationData) {
export async function getFromLocal(nomination: NominationRAW) {
if (beforeCreate(nomination)) return undefined;
return await queryDatabase(nomination.id);
}

export async function contains(nomination: NominationData) {
export async function contains(nomination: NominationRAW) {
if (beforeCreate(nomination)) return false;
const record = await queryDatabase(nomination.id);
return typeof record !== 'undefined';
Expand Down Expand Up @@ -180,7 +166,7 @@ export namespace brainstorming {
* Check if the nomination got result before creation of firebase, should skip query if true
* @param nomination The nomination
*/
export function beforeCreate(nomination: NominationData): boolean {
export function beforeCreate(nomination: NominationRAW): boolean {
return nomination.status !== umi.StatusCode.Pending && nomination.resultTime < 1518796800000;
}

Expand Down
10 changes: 5 additions & 5 deletions src/service/dia/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Store } from 'vuex';
import { State } from '@/store/state';

import { NominationData, Predicator } from '@/service/nomination';
import { NominationRAW, Predicator } from '@/service/nomination';

export namespace dia {

Expand Down Expand Up @@ -39,28 +39,28 @@ export namespace dia {
return list.filter(predicator).length;
}

export async function get(id: string): Promise<NominationData | undefined> {
export async function get(id: string): Promise<NominationRAW | undefined> {
const store = getStore('readonly');
if (!store) return;
return await settled(store.get(id));
}

export async function getAll(predicator?: Predicator): Promise<Array<NominationData>> {
export async function getAll(predicator?: Predicator): Promise<Array<NominationRAW>> {
const store = getStore('readonly');
if (!store) return [];
let list = await settled(store.getAll()) ?? [];
if (predicator) list = list.filter(predicator);
return list;
}

export async function save(nomination: NominationData) {
export async function save(nomination: NominationRAW) {
const store = getStore('readwrite');
if (!store) return;
const result = await settled(store.put(nomination));
if (typeof result !== 'undefined') saved();
}

export async function saveAll(nominations: Array<NominationData>) {
export async function saveAll(nominations: Array<NominationRAW>) {
await Promise.allSettled(nominations.map(nomination => save(nomination)));
saved();
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/google/drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class GoogleDriveKit {
* next one or not by return a boolean
*
* @param filename Name of the file to download
* @param callback Triggered when a file is downloaded
* @param validator Triggered when a file is downloaded
*/
async download(filename: string, validator: FileValidator) {
const listResponse = await gapi.client.drive.files.list({
Expand Down
23 changes: 13 additions & 10 deletions src/service/google/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Store } from 'vuex'

import type { State } from '@/store/state';
import { util } from '@/service/utils';
import AuthKit from './auth';
import GoogleDriveKit from './drive';

type BasicCallback = () => void;

export default class GoogleKit {
export namespace google {

auth = new AuthKit();
drive = new GoogleDriveKit();
export const auth = new AuthKit();
export const drive = new GoogleDriveKit();

init(callback: BasicCallback) {
util.loadScript('https://apis.google.com/js/api.js')
.then(() => {
callback();
});
export async function init(store: Store<State>) {
await util.loadScript('https://apis.google.com/js/api.js');
auth.events.authStatusChanged = (authed) => {
store.commit('google/setAuthed', authed);
store.commit('google/loaded');
};
auth.init();
}
}
60 changes: 22 additions & 38 deletions src/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import type { VueI18n } from 'vue-i18n';
import { Store } from 'vuex'
import { toRaw } from '@vue/reactivity';

import type { State } from '@/store/state';
import { brainstorming } from './brainstorming';
import { delibird } from './delibird';
import { dia } from './dia';
import { google } from './google';
import { mari } from './mari';
import { preferences } from './preferences';
import { umi } from './umi';
import { util } from './utils';
import { CountCallback } from './types';
import GoogleKit from './google';
import Mari from './mari';
import Nomination, { NominationData, NominationJSON } from './nomination';
import Nomination, { NominationRAW, NominationJSON } from './nomination';

export enum ServiceStatus {
idle,
Expand Down Expand Up @@ -44,8 +42,6 @@ export namespace service {

const mimeJSON = 'application/json';

const google = new GoogleKit();
const mari = new Mari();
let _store: Store<State>;

export const matchData: MatchData = {
Expand All @@ -66,22 +62,7 @@ export namespace service {
dia.init(_store);
brainstorming.init();
umi.init(i18n);

google.init(() => {
google.auth.events.authStatusChanged = (authed) => {
_store.commit('google/setAuthed', authed);
_store.commit('google/loaded');
};
google.auth.init();

mari.events.alert = (message) => {
delibird.alert(message);
}
mari.events.progress = (progress, max) => {
setProgress(progress, max);
};
mari.init();
});
google.init(_store);
}

export function signIn() {
Expand All @@ -96,8 +77,8 @@ export namespace service {
if (preferences.google.sync()) await download(Filename.nominations);
setProgress(0, 0);
setStatus(Status.processingMails);
const raws = await dia.getAll()
await mari.start(raws);
const raws = await dia.getAll();
await mari.start(raws, setProgress);
const matchTargets: Array<Nomination> = [];
const reduced = raws.reduce((list, raw) => {
if (raw.id.length < 1) {
Expand Down Expand Up @@ -165,7 +146,7 @@ export namespace service {
export async function importNominationsFile(): Promise<number> {
const content = await util.importFile();
try {
const list = JSON.parse(content) as Array<NominationData>;
const list = JSON.parse(content) as Array<NominationRAW>;
const count = await importNominations(list);
return count;
} catch (error) {
Expand Down Expand Up @@ -204,7 +185,7 @@ export namespace service {
const mapNomination = nominations.reduce((map, nomination) => {
map.set(nomination.id, nomination);
return map;
}, new Map<string, NominationData>());
}, new Map<string, NominationRAW>());

let count = 0;
for (const data of parsed.result) {
Expand Down Expand Up @@ -272,22 +253,25 @@ export namespace service {
async function queryBrainstorming(list: Array<Nomination>) {
setStatus(Status.queryingBrainstorming);
let count = 0;
const queries: Array<Promise<void>> = [];
for (const nomination of list) {
count++;
if (nomination.lngLat) {
count++;
setProgress(count, list.length);
continue;
}
const record = await brainstorming.query(nomination).catch(_ => undefined);
if (!record) {
setProgress(count, list.length);
continue;
}
nomination.lngLat = {
lng: parseFloat(record.lng), lat: parseFloat(record.lat)
};
setProgress(count, list.length);
const query = brainstorming.query(nomination)
.then(record => {
nomination.lngLat = { lng: parseFloat(record.lng), lat: parseFloat(record.lat) };
})
.catch()
.finally(() => {
count++;
setProgress(count, list.length);
});
queries.push(query);
}
await Promise.allSettled(queries);
}

function setStatus(status: Status) {
Expand Down Expand Up @@ -332,7 +316,7 @@ export namespace service {
if (merged) continue;
nominations.push(nomination);
}
await dia.saveAll(nominations.map(nomination => nomination.data));
await dia.saveAll(nominations.map(nomination => nomination.raw));
} catch (error) {
count = 0;
}
Expand Down
Loading

0 comments on commit a1cb72c

Please sign in to comment.