Skip to content

Commit

Permalink
show local only matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Manwe-777 committed Nov 26, 2023
1 parent b664b92 commit 2409dbe
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 40 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"lodash": "^4.17.21",
"match-sorter": "^6.3.0",
"mathjs": "^9.3.0",
"mtgatool-db": "^2.1.9",
"mtgatool-db": "^2.1.10",
"mtgatool-shared": "^2.2.0",
"qrcode": "^1.5.1",
"queue": "^6.0.2",
Expand Down Expand Up @@ -201,4 +201,4 @@
"type": "git",
"url": "https://github.com/mtgatool/mtgatool-desktop.git"
}
}
}
25 changes: 15 additions & 10 deletions public/tooldb-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function afterLogin() {
(0, reduxAction_1.default)("SET_LOCAL_MATCHES_INDEX", matches);
});
self.toolDb
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`)
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true)
.then(handleMatchesIndex_1.default);
self.toolDb
.queryKeys(`:${self.toolDb.user.pubKey}.draft-`)
Expand Down Expand Up @@ -626,7 +626,7 @@ const getMatchesData_1 = require("./getMatchesData");
const reduxAction_1 = __importDefault(require("./reduxAction"));
function handleMatchesIndex(matchesIds) {
if (matchesIds) {
(0, reduxAction_1.default)("SET_MATCHES_INDEX", matchesIds);
(0, reduxAction_1.default)("SET_REMOTE_MATCHES_INDEX", matchesIds);
(0, getMatchesData_1.getMatchesData)("MATCHES_DATA", matchesIds, self.globalData.currentUUID, (total, saved) => {
(0, reduxAction_1.default)("SET_MATCHES_FETCH_STATE", {
total,
Expand Down Expand Up @@ -1022,7 +1022,7 @@ self.onmessage = (e) => {
case "REFRESH_MATCHES":
if (self.toolDb.user) {
self.toolDb
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000)
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true)
.then(handleMatchesIndex_1.default);
}
break;
Expand Down Expand Up @@ -66510,12 +66510,15 @@ var _1 = require(".");
* Triggers a QUERY request to other peers.
* @param key start of the key
* @param userNamespaced If this key bolongs to a user or its public.
* @param timeout Max time to wait for remote.
* @param remoteOnly Only query remote peers, do not query local store.
* @returns Promise<Data>
*/
function toolDbQueryKeys(key, userNamespaced, timeoutMs) {
function toolDbQueryKeys(key, userNamespaced, timeoutMs, remoteOnly) {
var _this = this;
if (userNamespaced === void 0) { userNamespaced = false; }
if (timeoutMs === void 0) { timeoutMs = 1000; }
if (remoteOnly === void 0) { remoteOnly = false; }
return new Promise(function (resolve, reject) {
var _a, _b;
if (userNamespaced && ((_a = _this.user) === null || _a === void 0 ? void 0 : _a.pubKey) === undefined) {
Expand All @@ -66539,12 +66542,14 @@ function toolDbQueryKeys(key, userNamespaced, timeoutMs) {
var msgId = (0, _1.textRandom)(10);
var foundKeys = [];
var timeout;
var gotLocalKeys = false;
_this.store.query(finalKey).then(function (localKeys) {
gotLocalKeys = true;
foundKeys = __spreadArray(__spreadArray([], foundKeys, true), localKeys, true);
timeout = setTimeout(finishListening, timeoutMs);
});
var gotLocalKeys = remoteOnly;
if (remoteOnly === false) {
_this.store.query(finalKey).then(function (localKeys) {
gotLocalKeys = true;
foundKeys = __spreadArray(__spreadArray([], foundKeys, true), localKeys, true);
timeout = setTimeout(finishListening, timeoutMs);
});
}
var finishListening = function () {
resolve(lodash_1.default.uniq(foundKeys));
};
Expand Down
12 changes: 8 additions & 4 deletions src/components/views/history/ListItemMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default function ListItemMatch({
}: ListItemMatchProps): JSX.Element {
const { internalMatch } = match;

const matchesIndex = useSelector(
(state: AppState) => state.mainData.matchesIndex
const remoteMatchesIndex = useSelector(
(state: AppState) => state.mainData.remoteMatchesIndex
);

const pubKey = useSelector((state: AppState) => state.renderer.pubKey);
Expand Down Expand Up @@ -76,14 +76,18 @@ export default function ListItemMatch({
}}
/>
<HoverTile grpId={internalMatch.playerDeck.deckTileId || DEFAULT_TILE}>
{!matchesIndex.includes(matchKey) ? (
{!remoteMatchesIndex.includes(matchKey) ? (
<IconUpload
style={{
margin: "auto auto auto 8px",
width: "32px",
height: "24px",
}}
onClick={uploadMatch}
onClick={(e: React.MouseEvent<SVGSVGElement, MouseEvent>): void => {
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
uploadMatch();
}}
fill="#FFF"
/>
) : null}
Expand Down
2 changes: 1 addition & 1 deletion src/info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"6.4.4","branch":"master","timestamp":1700942218819}
{"version":"6.4.4","branch":"dev","timestamp":1700961911431}
2 changes: 1 addition & 1 deletion src/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const actions = {
SET_UUID_CARDS_DATA: MainDataSlice.setUUIDCards,
FORCE_COLLECTION: MainDataSlice.setForceCollection,
SET_DECKS_INDEX: MainDataSlice.setDecksIndex,
SET_MATCHES_INDEX: MainDataSlice.setMatchesIndex,
SET_LOCAL_MATCHES_INDEX: MainDataSlice.setLocalMatchesIndex,
SET_REMOTE_MATCHES_INDEX: MainDataSlice.setRemoteMatchesIndex,
SET_DRAFTS_INDEX: MainDataSlice.setDraftsIndex,
SET_HIDDEN_DECKS: MainDataSlice.setHiddenDecks,
SET_PUBKEY: RendererSlice.setPubKey,
Expand Down
18 changes: 15 additions & 3 deletions src/redux/slices/mainDataSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const mainState = {
liveFeedMatches: {} as Record<string, DbMatch>,
matchesIndex: [] as string[],
localMatchesIndex: [] as string[],
remoteMatchesIndex: [] as string[],
draftsIndex: [] as string[],
hiddenDecks: [] as string[],
decksIndex: {} as Record<string, number>,
Expand Down Expand Up @@ -144,11 +145,18 @@ const mainDataSlice = createSlice({
): void => {
state.decksIndex = { ...state.decksIndex, ...action.payload };
},
setMatchesIndex: (
setRemoteMatchesIndex: (
state: MainState,
action: PayloadAction<string[]>
): void => {
state.matchesIndex = _.uniq([...state.matchesIndex, ...action.payload]);
state.remoteMatchesIndex = _.uniq([
...state.remoteMatchesIndex,
...action.payload,
]);
state.matchesIndex = _.uniq([
...state.remoteMatchesIndex,
...state.localMatchesIndex,
]);
},
setLocalMatchesIndex: (
state: MainState,
Expand All @@ -158,6 +166,10 @@ const mainDataSlice = createSlice({
...state.localMatchesIndex,
...action.payload,
]);
state.matchesIndex = _.uniq([
...state.remoteMatchesIndex,
...state.localMatchesIndex,
]);
},
setDraftsIndex: (
state: MainState,
Expand Down Expand Up @@ -187,7 +199,7 @@ export const {
setUUIDInventory,
setUUIDCards,
setDecksIndex,
setMatchesIndex,
setRemoteMatchesIndex,
setLocalMatchesIndex,
setDraftsIndex,
setHiddenDecks,
Expand Down
2 changes: 1 addition & 1 deletion src/toolDb/setDbMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function setDbMatch(match: InternalMatch) {
}

reduxAction(store.dispatch, {
type: "SET_MATCHES_INDEX",
type: "SET_REMOTE_MATCHES_INDEX",
arg: globalData.matchesIndex,
});
}
2 changes: 1 addition & 1 deletion tooldb-worker/afterLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function afterLogin() {
});

self.toolDb
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`)
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true)
.then(handleMatchesIndex);

self.toolDb
Expand Down
2 changes: 1 addition & 1 deletion tooldb-worker/handleMatchesIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import reduxAction from "./reduxAction";

export default function handleMatchesIndex(matchesIds: string[] | null) {
if (matchesIds) {
reduxAction("SET_MATCHES_INDEX", matchesIds);
reduxAction("SET_REMOTE_MATCHES_INDEX", matchesIds);

getMatchesData(
"MATCHES_DATA",
Expand Down
14 changes: 7 additions & 7 deletions tooldb-worker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tooldb-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {
"automerge": "^1.0.1-preview.7",
"mtgatool-db": "^2.1.9",
"mtgatool-db": "^2.1.10",
"mtgatool-shared": "^2.2.0"
}
}
2 changes: 1 addition & 1 deletion tooldb-worker/toolDbWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ self.onmessage = (e: any) => {
case "REFRESH_MATCHES":
if (self.toolDb.user) {
self.toolDb
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000)
.queryKeys(`:${self.toolDb.user.pubKey}.matches-`, false, 5000, true)
.then(handleMatchesIndex);
}
break;
Expand Down

0 comments on commit 2409dbe

Please sign in to comment.