- {userDetails.profileImageUrl ? (
+ {userDetails?.profileImageUrl ? (
-
{userDetails.displayName}
+
+ {userDetails ? userDetails.displayName : "Sign in"}
+
-
- >
+
+
);
}
diff --git a/src/renderer/src/components/sidebar/sidebar.css.ts b/src/renderer/src/components/sidebar/sidebar.css.ts
index 5a96e87a..75ac2dd5 100644
--- a/src/renderer/src/components/sidebar/sidebar.css.ts
+++ b/src/renderer/src/components/sidebar/sidebar.css.ts
@@ -125,48 +125,3 @@ export const section = style({
flexDirection: "column",
paddingBottom: `${SPACING_UNIT}px`,
});
-
-export const profileButton = style({
- display: "flex",
- cursor: "pointer",
- transition: "all ease 0.1s",
- gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`,
- alignItems: "center",
- padding: `${SPACING_UNIT * 2}px ${SPACING_UNIT * 2}px`,
- color: vars.color.muted,
- borderBottom: `solid 1px ${vars.color.border}`,
- boxShadow: "0px 0px 15px 0px #000000",
- ":hover": {
- backgroundColor: "rgba(255, 255, 255, 0.15)",
- },
-});
-
-export const profileAvatar = style({
- width: "30px",
- height: "30px",
- borderRadius: "50%",
- display: "flex",
- justifyContent: "center",
- alignItems: "center",
- backgroundColor: vars.color.background,
- border: `solid 1px ${vars.color.border}`,
- position: "relative",
- objectFit: "cover",
-});
-
-export const profileButtonInformation = style({
- display: "flex",
- flexDirection: "column",
- alignItems: "flex-start",
-});
-
-export const statusBadge = style({
- width: "9px",
- height: "9px",
- borderRadius: "50%",
- backgroundColor: vars.color.danger,
- position: "absolute",
- bottom: "-2px",
- right: "-3px",
- zIndex: "1",
-});
diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts
index 40fc708b..2201a754 100644
--- a/src/renderer/src/declaration.d.ts
+++ b/src/renderer/src/declaration.d.ts
@@ -125,7 +125,7 @@ declare global {
updateProfile: (
displayName: string,
newProfileImagePath: string | null
- ) => Promise
;
+ ) => Promise;
}
interface Window {
diff --git a/src/renderer/src/features/user-details-slice.ts b/src/renderer/src/features/user-details-slice.ts
index af14ce56..0cc395b0 100644
--- a/src/renderer/src/features/user-details-slice.ts
+++ b/src/renderer/src/features/user-details-slice.ts
@@ -15,18 +15,14 @@ export const userDetailsSlice = createSlice({
name: "user-details",
initialState,
reducers: {
- setUserDetails: (state, action: PayloadAction) => {
+ setUserDetails: (state, action: PayloadAction) => {
state.userDetails = action.payload;
},
- setProfileBackground: (state, action: PayloadAction) => {
+ setProfileBackground: (state, action: PayloadAction) => {
state.profileBackground = action.payload;
},
- clearUserDetails: (state) => {
- state.userDetails = null;
- state.profileBackground = null;
- },
},
});
-export const { setUserDetails, setProfileBackground, clearUserDetails } =
+export const { setUserDetails, setProfileBackground } =
userDetailsSlice.actions;
diff --git a/src/renderer/src/hooks/use-user-details.ts b/src/renderer/src/hooks/use-user-details.ts
index 3a5ff515..e36fcd36 100644
--- a/src/renderer/src/hooks/use-user-details.ts
+++ b/src/renderer/src/hooks/use-user-details.ts
@@ -2,12 +2,9 @@ import { useCallback } from "react";
import { average } from "color.js";
import { useAppDispatch, useAppSelector } from "./redux";
-import {
- clearUserDetails,
- setProfileBackground,
- setUserDetails,
-} from "@renderer/features";
+import { setProfileBackground, setUserDetails } from "@renderer/features";
import { darkenColor } from "@renderer/helpers";
+import { UserDetails } from "@types";
export function useUserDetails() {
const dispatch = useAppDispatch();
@@ -16,68 +13,64 @@ export function useUserDetails() {
(state) => state.userDetails
);
- const clearUser = useCallback(async () => {
- dispatch(clearUserDetails());
+ const clearUserDetails = useCallback(async () => {
+ dispatch(setUserDetails(null));
+ dispatch(setProfileBackground(null));
+
+ window.localStorage.removeItem("userDetails");
}, [dispatch]);
const signOut = useCallback(async () => {
- clearUser();
+ clearUserDetails();
return window.electron.signOut();
- }, [clearUser]);
+ }, [clearUserDetails]);
- const updateUser = useCallback(async () => {
- return window.electron.getMe().then(async (userDetails) => {
- if (userDetails) {
- dispatch(setUserDetails(userDetails));
+ const updateUserDetails = useCallback(
+ async (userDetails: UserDetails) => {
+ dispatch(setUserDetails(userDetails));
- if (userDetails.profileImageUrl) {
- const output = await average(userDetails.profileImageUrl, {
- amount: 1,
- format: "hex",
- });
-
- dispatch(
- setProfileBackground(
- `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.7)})`
- )
- );
- }
- }
- });
- }, [dispatch]);
-
- const patchUser = useCallback(
- async (displayName: string, imageProfileUrl: string | null) => {
- return window.electron
- .updateProfile(displayName, imageProfileUrl)
- .then(async (userDetails) => {
- if (userDetails) {
- dispatch(setUserDetails(userDetails));
-
- if (userDetails.profileImageUrl) {
- const output = await average(userDetails.profileImageUrl, {
- amount: 1,
- format: "hex",
- });
-
- dispatch(
- setProfileBackground(
- `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.7)})`
- )
- );
- }
- }
+ if (userDetails.profileImageUrl) {
+ const output = await average(userDetails.profileImageUrl, {
+ amount: 1,
+ format: "hex",
});
+
+ const profileBackground = `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.8)})`;
+
+ dispatch(setProfileBackground(profileBackground));
+
+ window.localStorage.setItem(
+ "userDetails",
+ JSON.stringify({ ...userDetails, profileBackground })
+ );
+ }
},
[dispatch]
);
+ const fetchUserDetails = useCallback(async () => {
+ return window.electron.getMe();
+ }, []);
+
+ const patchUser = useCallback(
+ async (displayName: string, imageProfileUrl: string | null) => {
+ const response = await window.electron.updateProfile(
+ displayName,
+ imageProfileUrl
+ );
+
+ return updateUserDetails(response);
+ },
+ [updateUserDetails]
+ );
+
return {
userDetails,
- updateUser,
+ fetchUserDetails,
signOut,
- clearUser,
+ clearUserDetails,
+ updateUserDetails,
patchUser,
profileBackground,
};
diff --git a/src/renderer/src/pages/user/user-edit-modal.tsx b/src/renderer/src/pages/user/user-edit-modal.tsx
index 71ae112f..d70ec510 100644
--- a/src/renderer/src/pages/user/user-edit-modal.tsx
+++ b/src/renderer/src/pages/user/user-edit-modal.tsx
@@ -71,7 +71,6 @@ export const UserEditProfileModal = ({