Skip to content

Commit

Permalink
feat: Added Feature Friends Whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
copyandexecute committed Jun 25, 2024
1 parent 8aeb8e6 commit 0d1e555
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 57 deletions.
14 changes: 8 additions & 6 deletions src/components/invite/InvitePopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { invoke } from "@tauri-apps/api";
import { createEventDispatcher } from "svelte";
import ConfigTextInput from "../config/inputs/ConfigTextInput.svelte";
import { addNotification } from "../../stores/notificationStore.js";
import { getNoRiskToken, noriskError } from "../../utils/noriskUtils.js";
import { defaultUser } from "../../stores/credentialsStore.js";
const dispatch = createEventDispatcher();
Expand All @@ -23,17 +26,16 @@
async function inviteFriend() {
if (friendIdentifier !== "") {
const loginData = options.accounts.find(acc => acc.uuid == options.currentUuid);
await invoke("add_player_to_whitelist", {
identifier: friendIdentifier,
noriskToken: options.experimentalMode ? loginData.experimentalToken : loginData.noriskToken,
requestUuid: options.currentUuid,
noriskToken: getNoRiskToken(),
requestUuid: $defaultUser.id,
}).then(() => {
alert("Successfully invited " + friendIdentifier + " to the NRC closed beta!");
hideSettings();
}).catch((e) => {
alert("An error occurred while inviting " + friendIdentifier + " to the NRC closed beta: " + e);
console.error(e);
noriskError(e);
addNotification("An error occurred while inviting " + friendIdentifier + " to the NRC closed beta: " + e);
});
}
}
Expand All @@ -58,7 +60,7 @@
<hr>
<div class="settings-wrapper">
<p>You have
<b>{ friendInviteSlots.availableSlots == -1 ? '' : `${friendInviteSlots.availableSlots - friendInviteSlots.previousInvites}/${friendInviteSlots.availableSlots}`}</b>
<b>{ friendInviteSlots.availableSlots === -1 ? '' : `${friendInviteSlots.availableSlots - friendInviteSlots.previousInvites}/${friendInviteSlots.availableSlots}`}</b>
invites left.<br>You can use them to invite a friend to the NRC closed beta.</p>
<ConfigTextInput title="Username / UUID" bind:value={friendIdentifier} />
</div>
Expand Down
157 changes: 106 additions & 51 deletions src/components/v2/HomeNavbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,126 @@
import { push } from "svelte-spa-router";
import { appWindow } from "@tauri-apps/api/window";
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api";
import { getNoRiskToken, noriskError, noriskLog } from "../../utils/noriskUtils.js";
import InvitePopup from "../invite/InvitePopup.svelte";
import { addNotification } from "../../stores/notificationStore.js";
let navItems = [
{ name: "SETTINGS", onClick: () => push("/launcher-settings"), condition: true },
{
name: "PROFILES",
onClick: () => push("/profiles"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},
/*
Hallo Tim ich habe wirklich probiert es zu fixen, aber ich muss jetzt weitermachen damit wir ich schlafen kann ok
ich setze mich nochmal dran wenn du mich pingst
{
name: "SERVERS",
onClick: () => console.log("Servers clicked"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},*/
{
name: "ADDONS",
onClick: () => push("/addons"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},
{
name: "CAPES",
onClick: () => push("/capes"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},
/*
Ich habs wirklich probiert aber Overflow hat gekickt
{
name: "SKIN",
onClick: () => push("/skin"),
condition: () => get(defaultUser) != null,
},*/
{
name: "QUIT", onClick: () => {
appWindow.close();
}, condition: true, className: "quit",
},
];
navItems = navItems.sort((a, b) => b.name.length - a.name.length);
branches.subscribe(value => {
navItems = navItems.sort((a, b) => b.name.length - a.name.length);
});
let showInvitePopup = false;
let featureWhitelist = [];
let friendInviteSlots = {};
let navItems = [];
function updateNavItems() {
navItems = [
{ name: "SETTINGS", onClick: () => push("/launcher-settings"), condition: true },
{
name: "PROFILES",
onClick: () => push("/profiles"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},
/*
Hallo Tim ich habe wirklich probiert es zu fixen, aber ich muss jetzt weitermachen damit wir ich schlafen kann ok
ich setze mich nochmal dran wenn du mich pingst
{
name: "SERVERS",
onClick: () => console.log("Servers clicked"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},*/
{
name: "ADDONS",
onClick: () => push("/addons"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},
{
name: "CAPES",
onClick: () => push("/capes"),
condition: () => get(branches).length > 0 && get(defaultUser) != null,
},
{
name: "INVITE",
onClick: () => showInvitePopup = true,
condition: () => get(branches).length > 0 && get(defaultUser) != null && featureWhitelist.includes("INVITE_FRIENDS") && (friendInviteSlots.availableSlots !== -1 && friendInviteSlots.availableSlots > friendInviteSlots.previousInvites),
},
/*
Ich habs wirklich probiert aber Overflow hat gekickt
{
name: "SKIN",
onClick: () => push("/skin"),
condition: () => get(defaultUser) != null,
},*/
{
name: "QUIT", onClick: () => {
appWindow.close();
}, condition: true, className: "quit",
},
].sort((a, b) => b.name.length - a.name.length);
}
defaultUser.subscribe(value => {
navItems = navItems.sort((a, b) => b.name.length - a.name.length);
});
onMount(async () => {
const branchesUnlisten = branches.subscribe(value => {
navItems = navItems.sort((a, b) => b.name.length - a.name.length);
const branchesUnlisten = branches.subscribe(async value => {
await fetchFeatures();
updateNavItems();
});
const userUnlisten = defaultUser.subscribe(value => {
navItems = navItems.sort((a, b) => b.name.length - a.name.length);
const userUnlisten = defaultUser.subscribe(async value => {
await fetchFeatures();
updateNavItems();
console.log(featureWhitelist, friendInviteSlots)
});
return () => {
branchesUnlisten();
userUnlisten();
};
});
async function fetchFeatures() {
featureWhitelist = [];
await checkFeatureWhitelist("INVITE_FRIENDS");
if (featureWhitelist.includes("INVITE_FRIENDS")) {
await loadFriendInvites();
}
}
async function checkFeatureWhitelist(feature) {
if (!$defaultUser) return;
await invoke("check_feature_whitelist", {
feature: feature,
noriskToken: getNoRiskToken(),
uuid: $defaultUser.id,
}).then((result) => {
console.debug(feature + ":", result);
if (!result) return;
featureWhitelist.push(feature.toUpperCase().replaceAll(" ", "_"));
}).catch((reason) => {
noriskError(reason);
featureWhitelist = [];
});
}
async function loadFriendInvites() {
if (!$defaultUser) return;
await invoke("get_whitelist_slots", {
noriskToken: getNoRiskToken(),
uuid: $defaultUser.id,
}).then((result) => {
noriskLog("Received Whitelist Slots" + JSON.stringify(result));
friendInviteSlots = result;
}).catch((reason) => {
noriskError(reason);
addNotification(reason);
friendInviteSlots = {};
});
}
</script>

{#if showInvitePopup}
<InvitePopup on:getInviteSlots={loadFriendInvites} bind:showModal={showInvitePopup} bind:friendInviteSlots />
{/if}
<div class="container">
<div class="home-navbar-wrapper topleft">
{#each navItems as item (item.name)}
Expand Down

0 comments on commit 0d1e555

Please sign in to comment.