feat: add workwonders

This commit is contained in:
Zamitto
2026-01-03 16:42:49 -03:00
parent 590e09a8c3
commit 8b3bcd88b1
5 changed files with 56 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { Sidebar, BottomPanel, Header, Toast } from "@renderer/components";
import { WorkWondersSdk } from "workwonders-sdk";
import {
useAppDispatch,
useAppSelector,
@@ -52,6 +52,8 @@ export function App() {
const { clearDownload, setLastPacket } = useDownload();
const wokwondersRef = useRef<WorkWondersSdk | null>(null);
const {
hasActiveSubscription,
fetchUserDetails,
@@ -114,7 +116,24 @@ export function App() {
return () => unsubscribe();
}, [updateLibrary]);
useEffect(() => {
const setupWorkWonders = useCallback(
async (token?: string, locale?: string) => {
if (wokwondersRef.current) return;
wokwondersRef.current = new WorkWondersSdk();
await wokwondersRef.current.init({
organization: "hydra",
token,
locale,
});
await wokwondersRef.current.initChangelogWidget();
wokwondersRef.current.initChangelogWidgetMini();
},
[wokwondersRef]
);
const setupExternalResources = useCallback(async () => {
const cachedUserDetails = window.localStorage.getItem("userDetails");
if (cachedUserDetails) {
@@ -125,21 +144,26 @@ export function App() {
dispatch(setProfileBackground(profileBackground));
}
fetchUserDetails()
.then((response) => {
if (response) {
updateUserDetails(response);
}
})
.finally(() => {
if (document.getElementById("external-resources")) return;
const userPreferences = await window.electron.getUserPreferences();
const userDetails = await fetchUserDetails().catch(() => null);
const $script = document.createElement("script");
$script.id = "external-resources";
$script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}/bundle.js?t=${Date.now()}`;
document.head.appendChild($script);
});
}, [fetchUserDetails, updateUserDetails, dispatch]);
if (userDetails) {
updateUserDetails(userDetails);
}
setupWorkWonders(userDetails?.workwondersJwt, userPreferences?.language);
if (!document.getElementById("external-resources")) {
const $script = document.createElement("script");
$script.id = "external-resources";
$script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}/bundle.js?t=${Date.now()}`;
document.head.appendChild($script);
}
}, [fetchUserDetails, updateUserDetails, dispatch, setupWorkWonders]);
useEffect(() => {
setupExternalResources();
}, [setupExternalResources]);
const onSignIn = useCallback(() => {
fetchUserDetails().then((response) => {
@@ -203,6 +227,7 @@ export function App() {
useEffect(() => {
if (contentRef.current) contentRef.current.scrollTop = 0;
wokwondersRef.current?.notifyUrlChange();
}, [location.pathname, location.search]);
useEffect(() => {

View File

@@ -59,6 +59,7 @@ export function useUserDetails() {
username: userDetails?.username || "",
subscription: userDetails?.subscription || null,
featurebaseJwt: userDetails?.featurebaseJwt || "",
workwondersJwt: userDetails?.workwondersJwt || "",
karma: userDetails?.karma || 0,
});
},

View File

@@ -187,6 +187,7 @@ export interface UserDetails {
profileVisibility: ProfileVisibility;
bio: string;
featurebaseJwt: string;
workwondersJwt: string;
subscription: Subscription | null;
karma: number;
quirks?: {