feat: adding background image upload

This commit is contained in:
Chubby Granny Chaser 2024-10-16 10:59:57 +01:00
parent bdaf68ad23
commit 67109ff51a
No known key found for this signature in database
10 changed files with 32 additions and 23 deletions

View file

@ -70,7 +70,7 @@ export function useUserDetails() {
subscription: userDetails?.subscription || null, subscription: userDetails?.subscription || null,
}); });
}, },
[updateUserDetails, userDetails?.username] [updateUserDetails, userDetails?.username, userDetails?.subscription]
); );
const syncFriendRequests = useCallback(async () => { const syncFriendRequests = useCallback(async () => {
@ -127,9 +127,9 @@ export function useUserDetails() {
const blockUser = (userId: string) => window.electron.blockUser(userId); const blockUser = (userId: string) => window.electron.blockUser(userId);
const unblockUser = (userId: string) => { const unblockUser = (userId: string) => window.electron.unblockUser(userId);
return window.electron.unblockUser(userId);
}; const hasActiveSubscription = userDetails?.subscription?.status === "active";
return { return {
userDetails, userDetails,
@ -139,6 +139,7 @@ export function useUserDetails() {
friendRequetsModalTab, friendRequetsModalTab,
isFriendsModalVisible, isFriendsModalVisible,
friendModalUserId, friendModalUserId,
hasActiveSubscription,
showFriendsModal, showFriendsModal,
hideFriendsModal, hideFriendsModal,
fetchUserDetails, fetchUserDetails,

View file

@ -19,11 +19,10 @@ import { App } from "./app";
import { store } from "./store"; import { store } from "./store";
import resources from "@locales"; import resources from "@locales";
import { AchievementNotification } from "./pages/achievement/notification/achievement-notification"; import { AchievementNotification } from "./pages/achievements/notification/achievement-notification";
import "./workers"; import "./workers";
import { RepacksContextProvider } from "./context"; import { RepacksContextProvider } from "./context";
import { Achievement } from "./pages/achievement/achievements";
import { SuspenseWrapper } from "./components"; import { SuspenseWrapper } from "./components";
const Home = React.lazy(() => import("./pages/home/home")); const Home = React.lazy(() => import("./pages/home/home"));
@ -35,6 +34,9 @@ const SearchResults = React.lazy(() => import("./pages/home/search-results"));
const Settings = React.lazy(() => import("./pages/settings/settings")); const Settings = React.lazy(() => import("./pages/settings/settings"));
const Catalogue = React.lazy(() => import("./pages/catalogue/catalogue")); const Catalogue = React.lazy(() => import("./pages/catalogue/catalogue"));
const Profile = React.lazy(() => import("./pages/profile/profile")); const Profile = React.lazy(() => import("./pages/profile/profile"));
const Achievements = React.lazy(
() => import("./pages/achievements/achievements")
);
Sentry.init({}); Sentry.init({});
@ -90,7 +92,10 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
path="/profile/:userId" path="/profile/:userId"
element={<SuspenseWrapper Component={Profile} />} element={<SuspenseWrapper Component={Profile} />}
/> />
<Route path="/achievements" Component={Achievement} /> <Route
path="/achievements"
element={<SuspenseWrapper Component={Achievements} />}
/>
</Route> </Route>
<Route <Route
path="/achievement-notification" path="/achievement-notification"

View file

@ -12,7 +12,7 @@ import { SkeletonTheme } from "react-loading-skeleton";
import { AchievementsSkeleton } from "./achievements-skeleton"; import { AchievementsSkeleton } from "./achievements-skeleton";
import { AchievementsContent } from "./achievements-content"; import { AchievementsContent } from "./achievements-content";
export function Achievement() { export default function Achievements() {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const objectId = searchParams.get("objectId"); const objectId = searchParams.get("objectId");
const shop = searchParams.get("shop"); const shop = searchParams.get("shop");
@ -51,8 +51,6 @@ export function Achievement() {
} }
}, [objectId, shop, userId]); }, [objectId, shop, userId]);
if (!objectId || !shop || !title) return null;
const otherUserId = userDetails?.id === userId ? null : userId; const otherUserId = userDetails?.id === userId ? null : userId;
const otherUser = otherUserId const otherUser = otherUserId
@ -66,9 +64,9 @@ export function Achievement() {
return ( return (
<GameDetailsContextProvider <GameDetailsContextProvider
gameTitle={title} gameTitle={title!}
shop={shop as GameShop} shop={shop as GameShop}
objectId={objectId} objectId={objectId!}
> >
<GameDetailsContextConsumer> <GameDetailsContextConsumer>
{({ isLoading, achievements }) => { {({ isLoading, achievements }) => {

View file

@ -11,7 +11,7 @@ import {
ModalProps, ModalProps,
TextField, TextField,
} from "@renderer/components"; } from "@renderer/components";
import { useAppSelector, useToast, useUserDetails } from "@renderer/hooks"; import { useToast, useUserDetails } from "@renderer/hooks";
import { SPACING_UNIT } from "@renderer/theme.css"; import { SPACING_UNIT } from "@renderer/theme.css";
import { yupResolver } from "@hookform/resolvers/yup"; import { yupResolver } from "@hookform/resolvers/yup";
@ -51,8 +51,8 @@ export function EditProfileModal(
const { getUserProfile } = useContext(userProfileContext); const { getUserProfile } = useContext(userProfileContext);
const { userDetails } = useAppSelector((state) => state.userDetails); const { userDetails, fetchUserDetails, hasActiveSubscription } =
const { fetchUserDetails } = useUserDetails(); useUserDetails();
useEffect(() => { useEffect(() => {
if (userDetails) { if (userDetails) {
@ -112,14 +112,18 @@ export function EditProfileModal(
if (filePaths && filePaths.length > 0) { if (filePaths && filePaths.length > 0) {
const path = filePaths[0]; const path = filePaths[0];
// const { imagePath } = await window.electron if (!hasActiveSubscription) {
// .processProfileImage(path) const { imagePath } = await window.electron
// .catch(() => { .processProfileImage(path)
// showErrorToast(t("image_process_failure")); .catch(() => {
// return { imagePath: null }; showErrorToast(t("image_process_failure"));
// }); return { imagePath: null };
});
onChange(path); onChange(imagePath);
} else {
onChange(path);
}
} }
}; };

View file

@ -9,6 +9,7 @@ import { useToast, useUserDetails } from "@renderer/hooks";
export function UploadBackgroundImageButton() { export function UploadBackgroundImageButton() {
const [isUploadingBackgroundImage, setIsUploadingBackgorundImage] = const [isUploadingBackgroundImage, setIsUploadingBackgorundImage] =
useState(false); useState(false);
const { hasActiveSubscription } = useUserDetails();
const { isMe, setSelectedBackgroundImage } = useContext(userProfileContext); const { isMe, setSelectedBackgroundImage } = useContext(userProfileContext);
const { patchUser } = useUserDetails(); const { patchUser } = useUserDetails();
@ -42,7 +43,7 @@ export function UploadBackgroundImageButton() {
} }
}; };
if (!isMe) return null; if (!isMe || !hasActiveSubscription) return null;
return ( return (
<Button <Button