Skip to content

Commit

Permalink
Merge pull request #85 from AshishBarvaliya/ghano/bugs
Browse files Browse the repository at this point in the history
Fix: Ghano bugs - notifications, api stuff
  • Loading branch information
AshishBarvaliya authored Dec 20, 2023
2 parents 24f3ac9 + 9b9b233 commit f96ebad
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 53 deletions.
5 changes: 4 additions & 1 deletion src/components/header-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const HeaderMenu: React.FC<HeaderMenuProps> = () => {

const { data: notificationStatus } = useQuery(
["user", "notification", "new"],
() => getHasNewNotifications(session?.user.id)
() => getHasNewNotifications(),
{
enabled: !!router.query.id && !!session,
}
);
return (
<DropdownMenu>
Expand Down
6 changes: 3 additions & 3 deletions src/components/header-searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Switch } from "./ui/switch";
import { Label } from "./ui/label";
import { INPUT_LIMIT } from "@/constants/website";

const HeaderSearchBar = () => {
const HeaderSearchBar = ({ forMobile = false }: { forMobile?: boolean }) => {
const {
setThemeSearchQuery,
filterTags,
Expand All @@ -28,8 +28,8 @@ const HeaderSearchBar = () => {
return (
<>
<SeachBar
id="font-search"
name="font-search"
id={forMobile ? "mobile-search" : "main-search"}
name={forMobile ? "mobile-search" : "main-search"}
placeholder="Search by font, theme, user, or description"
autoComplete="off"
maxLength={INPUT_LIMIT.NAME_MAX}
Expand Down
53 changes: 27 additions & 26 deletions src/components/notification-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Typography from "./ui/typography";
import moment from "moment";
import { Button } from "./ui/button";
import Link from "next/link";
import LearningTemplate from "@/assets/templates/learning/learning-mini";
import { generateAllShades } from "@/lib/utils";
import { useRouter } from "next/router";
import { getMiniTemplate } from "@/lib/templates";

interface INotificationTileProps {
notification: INotification;
Expand Down Expand Up @@ -62,6 +62,15 @@ export const NotificationTile: React.FC<INotificationTileProps> = ({
}) => {
const router = useRouter();

const colors = notification.theme
? {
bg: notification?.theme?.color_1,
primary: notification?.theme?.color_2,
accent: notification?.theme?.color_3,
extra: notification?.theme?.color_4,
}
: null;

return (
<div
key={notification.id}
Expand Down Expand Up @@ -110,31 +119,23 @@ export const NotificationTile: React.FC<INotificationTileProps> = ({
</div>
) : (
<div className="w-20 mr-2">
<LearningTemplate
id={`notification-${notification?.theme?.id}`}
colors={{
bg: "#ffffff",
primary: "#000000",
accent: "#eb4034",
extra: "#4334eb",
}}
shades={generateAllShades({
bg: "#ffffff",
primary: "#000000",
accent: "#eb4034",
extra: "#4334eb",
})}
fonts={{
primary: {
fontFamily: "Poppins",
weights: [],
},
secondary: {
fontFamily: "Advent Pro",
weights: [],
},
}}
/>
{notification.theme && colors
? getMiniTemplate(notification.theme.template, {
id: `notification-${notification?.theme?.id}`,
colors: colors,
shades: generateAllShades(colors),
fonts: {
primary: {
fontFamily: "Roboto",
weights: [],
},
secondary: {
fontFamily: "Poppins",
weights: [],
},
},
})
: null}
</div>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/profile-following.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ export const UserTile = ({
<div className="flex flex-col ml-3 justify-between">
<div className="flex items-center gap-2">
{user.name}
{user?.level && (
{user?.level ? (
<AwardIcon
className="h-3 w-3"
level={user.level}
info={USER_LEVELS[user.level].name}
/>
)}
) : null}
</div>
<div className="flex items-center gap-2">
<Typography element={"p"} as="p" className="text-xs">
Expand Down
2 changes: 1 addition & 1 deletion src/components/profile-themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { getTags, getThemesByUserAndType } from "@/services/theme";
import { GetThemeTileProps, TagProps } from "@/interfaces/theme";
import { GetThemeTileProps } from "@/interfaces/theme";
import { ThemeTile } from "@/components/theme-tile";
import { useSession } from "next-auth/react";
import { useHelpers } from "@/hooks/useHelpers";
Expand Down
23 changes: 16 additions & 7 deletions src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,30 @@ const Sidebar = ({
{
id: "explore",
label: "Explore",
icon: <ZapIcon className="w-5 h-5" />,
getIcon: (isActive: boolean) => (
<ZapIcon className="w-4 h-4" strokeWidth={isActive ? 2.5 : 2} />
),
},
...(status === "authenticated"
? [
{
id: "foryou",
label: "For you",
icon: <PartyPopper className="w-5 h-5" />,
getIcon: (isActive: boolean) => (
<PartyPopper
className="w-4 h-4"
strokeWidth={isActive ? 2.5 : 2}
/>
),
},
]
: []),
{
id: "popular",
label: "Popular",
icon: <BarChart4 className="w-5 h-5" />,
getIcon: (isActive: boolean) => (
<BarChart4 className="w-4 h-4" strokeWidth={isActive ? 2.5 : 2} />
),
},
];

Expand All @@ -56,7 +65,7 @@ const Sidebar = ({
) : (
<>
<div className="flex md:hidden px-2 gap-1 py-1 pt-2">
<HeaderSearchBar />
<HeaderSearchBar forMobile />
</div>
<div className="flex overflow-y-auto md:flex-col flex-1 gap-2 py-2 md:py-4">
{tabs.map((tab) => (
Expand All @@ -66,12 +75,12 @@ const Sidebar = ({
setThemeType(tab.id as "explore" | "foryou" | "popular")
}
className={cn(
"flex gap-2.5 items-center py-2 px-2 md:px-8 mx-3 text-lg cursor-pointer hover:bg-primary/20",
"flex gap-2.5 items-center py-2 px-2 md:px-9 mx-3 text-base cursor-pointer hover:bg-primary/20",
themeType === tab.id &&
"bg-primary/60 shadow-md hover:bg-primary/60"
"bg-primary/60 shadow-inset hover:bg-primary/60 font-[500]"
)}
>
{tab.icon}
{tab.getIcon(themeType === tab.id)}
{tab.label}
</div>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const buttonVariants = cva(
default: "h-8 text-xs lg:h-10 px-4 lg:text-sm py-2",
sm: "h-6 text-xs border-[0.5px] px-3",
md: "h-8 px-4 text-xs border-[0.5px]",
lg: "h-10 text-sm px-6 lg:h-12 lg:px-8 lg:border lg:text-sm",
lg: "h-10 text-sm px-6 lg:h-12 lg:px-8 lg:border lg:text-base",
icon: "h-10 w-10",
circle: "p-3",
},
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/notification.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TemplateType } from "./templates";

export interface INotification {
id: string;
createdAt: Date;
Expand All @@ -7,6 +9,11 @@ export interface INotification {
theme?: {
id: string;
name: string;
template: TemplateType;
color_1: string;
color_2: string;
color_3: string;
color_4: string;
};
notifier: {
id: string;
Expand Down
5 changes: 5 additions & 0 deletions src/pages/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export default async function handler(
columns: {
id: true,
name: true,
template: true,
color_1: true,
color_2: true,
color_3: true,
color_4: true,
},
},
notifier: {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/api/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ export default async function handler(
LEFT JOIN
tag ON tag.id = themes_to_tags."tagId"
WHERE
theme."isPrivate" = false
AND
theme."userId" = ${userId}
GROUP BY
theme.id, "user".id
Expand Down Expand Up @@ -314,8 +316,7 @@ export default async function handler(
LEFT JOIN
tag ON tag.id = themes_to_tags."tagId"
WHERE
theme."isPrivate" = false
AND users_to_liked_themes."userId" = ${userId}
users_to_liked_themes."userId" = ${userId}
GROUP BY
theme.id, "user".id
ORDER BY
Expand Down
14 changes: 7 additions & 7 deletions src/pages/user/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default function User() {
);
const { data: notificationStatus } = useQuery(
["user", "notification", "new"],
() => getHasNewNotifications(session?.user?.id),
() => getHasNewNotifications(),
{
enabled: !!router.query.id,
enabled: !!router.query.id && !!session,
}
);
const { mutate: mutateUserFollow, isLoading: isLoadingFollow } = useMutation({
Expand Down Expand Up @@ -221,11 +221,11 @@ export default function User() {
];

const renderStats = () => (
<div className="flex flex-col w-full py-4 border-t border-border/20">
<div className="flex flex-col w-full py-3 border-t border-border/20">
<Typography
element="p"
as="p"
className="text-primary-foreground/90 font-bold mb-2"
className="text-primary-foreground/90 font-bold mb-1"
>
Community Stats
</Typography>
Expand Down Expand Up @@ -307,7 +307,7 @@ export default function User() {
{user?.name || "-"}
</Typography>
{user && user.level !== undefined ? (
<div className="flex items-center">
<div className="flex items-center justify-center">
<Typography
element="p"
as="p"
Expand All @@ -328,7 +328,7 @@ export default function User() {
/>
)}
{renderButton(session, user)}
<div className="flex flex-col py-3 w-full px-4 text-sm">
<div className="flex flex-col py-2 w-full px-4 text-sm">
<Typography
element="p"
as="p"
Expand Down Expand Up @@ -393,7 +393,7 @@ export default function User() {
</div>
</div>
</div>
<div className="flex flex-col lg:mt-[56px] overflow-y-auto flex-1">
<div className="flex flex-col lg:mt-[56px] overflow-y-auto flex-1 mb-2">
{navigations.find((tab) => tab.title === selectedNav)?.component}
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export const markNotificationAsRead = async () => {
return response.data;
};

export const getHasNewNotifications = async (id?: string) => {
if (!id) return new Promise((_, reject) => reject());
export const getHasNewNotifications = async () => {
const apiUrl = `/api/notifications?new=1`;
const response = await axios.get(apiUrl);

Expand Down
2 changes: 1 addition & 1 deletion src/styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('https://fonts.googleapis.com/css?family=Poppins:400,700&display=swap');
@import url('https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Nosifer&display=swap');
@tailwind base;
@tailwind components;
Expand Down

0 comments on commit f96ebad

Please sign in to comment.