Skip to content

Commit

Permalink
private mode test
Browse files Browse the repository at this point in the history
  • Loading branch information
Manwe-777 committed Nov 14, 2023
1 parent 1b580a3 commit 6c4b164
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/common/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const defaultConfig = {
matchesTableState: undefined,
matchesTableMode: MATCHES_LIST_MODE,
skipFirstpass: false,
privateMode: false,
enableKeyboardShortcuts: true,
shortcutOverlay1: "Alt+Shift+1",
shortcutOverlay2: "Alt+Shift+2",
Expand Down
26 changes: 26 additions & 0 deletions src/components/views/settings/AccountSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import setLocalSetting from "../../../utils/setLocalSetting";
import vodiFn from "../../../utils/voidfn";
import PassphraseGenerate from "../../PassphraseGenerate";
import Button from "../../ui/Button";
import Toggle from "../../ui/Toggle";
import { SettingsPanelProps } from "./ViewSettings";

function resizeBase64Img(
Expand Down Expand Up @@ -50,6 +51,9 @@ export default function AccountSettingsPanel(
): JSX.Element {
const avatars = useSelector((state: AppState) => state.avatars.avatars);
const pubKey = useSelector((state: AppState) => state.renderer.pubKey);
const privateMode = useSelector(
(state: AppState) => state.settings.privateMode
);
const fetchAvatar = useFetchAvatar();
const isLoggedIn = useIsLoggedIn();

Expand Down Expand Up @@ -98,6 +102,22 @@ export default function AccountSettingsPanel(
[fetchAvatar, pubKey]
);

const setPrivateMode = useCallback(
(value: boolean) => {
if (value) {
putData(`rank-${pubKey}`, null, false);
}
reduxAction(dispatch, {
type: "SET_SETTINGS",
arg: {
privateMode: value,
},
});
putData("privateMode", value, true);
},
[dispatch]
);

useEffect(() => {
if (avatarInputRef.current) {
getData<string>("avatar", true)
Expand Down Expand Up @@ -156,6 +176,12 @@ export default function AccountSettingsPanel(
onClick={changeAlias}
/>
</div>
<Toggle
text="Private mode"
value={privateMode}
style={{ margin: "auto" }}
callback={setPrivateMode}
/>
<PassphraseGenerate />
<p
style={{
Expand Down
14 changes: 9 additions & 5 deletions src/toolDb/setDbMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default async function setDbMatch(match: InternalMatch) {
console.log("> Set match", match);

const { pubKey } = store.getState().renderer;
const { privateMode } = store.getState().settings;

const newDbMatch: DbMatch = {
matchId: match.id,
Expand All @@ -38,11 +39,14 @@ export default async function setDbMatch(match: InternalMatch) {

const remoteKey = getUserNamespacedKey(pubKey, `matches-${match.id}`);

window.toolDbWorker.postMessage({
type: "PUSH_DB_MATCH",
key: remoteKey,
match: newDbMatch,
});
if (!privateMode) {
// Send to explore and livefeed
window.toolDbWorker.postMessage({
type: "PUSH_DB_MATCH",
key: remoteKey,
match: newDbMatch,
});
}

// Create CRDT document with the new match added to it
if (!globalData.matchesIndex.includes(remoteKey)) {
Expand Down
32 changes: 20 additions & 12 deletions src/toolDb/upsertDbRank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default async function upsertDbRank(arg: Partial<CombinedRankInfo>) {
console.log("> Upsert rank", arg, rank);

const uuid = getLocalSetting("playerId") || "default";
const { dispatch } = store;
const { dispatch, getState } = store;

const { privateMode } = getState().settings;

const pubKey = getLocalSetting("pubkey");
console.warn("pubKey", { pubKey: pubKey });
Expand All @@ -35,11 +37,14 @@ export default async function upsertDbRank(arg: Partial<CombinedRankInfo>) {
});

putData<DbRankData>(`${uuid}-rank`, newData, true);
putData<DbRankDataWithKey>(`rank-${pubKey}`, {
...newData,
uuid,
pubKey: pubKey,
});

if (!privateMode) {
putData<DbRankDataWithKey>(`rank-${pubKey}`, {
...newData,
uuid,
pubKey: pubKey,
});
}
} else {
putData<DbRankData>(
`${uuid}-rank`,
Expand All @@ -49,12 +54,15 @@ export default async function upsertDbRank(arg: Partial<CombinedRankInfo>) {
},
true
);
putData<DbRankDataWithKey>(`rank-${pubKey}`, {
...defaultRankData,
updated: new Date().getTime(),
uuid,
pubKey: pubKey,
});

if (!privateMode) {
putData<DbRankDataWithKey>(`rank-${pubKey}`, {
...defaultRankData,
updated: new Date().getTime(),
uuid,
pubKey: pubKey,
});
}
}
});
}
4 changes: 4 additions & 0 deletions tooldb-worker/afterLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default function afterLogin() {
self.toolDb
.queryKeys(`:${self.toolDb.user.pubKey}.draft-`)
.then(handleDraftsIndex);

self.toolDb.getData(`setting-private`).then((settingPrivate) => {
reduxAction("SET_SETTINGS", { privateMode: settingPrivate === "true" });
});
}

self.toolDb.addKeyListener(`matches-livefeed-${currentDay}`, handleLiveFeed);
Expand Down

0 comments on commit 6c4b164

Please sign in to comment.