Skip to content

Commit

Permalink
Merge branch 'beta' into issue-open-sauced#1374
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanas159 authored Jul 18, 2023
2 parents 7170cf0 + 9716f9a commit 7950b6f
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 93 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@

> All notable changes to this project will be documented in this file
## [1.56.0](https://github.com/open-sauced/insights/compare/v1.55.0...v1.56.0) (2023-07-17)


### 🐛 Bug Fixes

* add hidden form for Netlify forms submission ([#1351](https://github.com/open-sauced/insights/issues/1351)) ([8075012](https://github.com/open-sauced/insights/commit/80750124072a742443a89716f9b2e956f7bdcb25))
* ensure font color of selected interests pill changed is white ([#1342](https://github.com/open-sauced/insights/issues/1342)) ([b778f11](https://github.com/open-sauced/insights/commit/b778f11484d02b4d159fe3cd22f43de4a5c28196))
* improve loading performance of individual highlight ([#1349](https://github.com/open-sauced/insights/issues/1349)) ([9e193fe](https://github.com/open-sauced/insights/commit/9e193feae32739894051ec9d3236826cb00a1c88))
* prevent concurrent user profile update requests ([#1372](https://github.com/open-sauced/insights/issues/1372)) ([b23b9df](https://github.com/open-sauced/insights/commit/b23b9df076596b7d5163ef9f8d7bc7f28ecde92a))


### 🎨 Styles

* text inputs colors were not consistent in the user settings page ([#1360](https://github.com/open-sauced/insights/issues/1360)) ([edae9c4](https://github.com/open-sauced/insights/commit/edae9c4a26bbc21921422356c623f2a8c0ca0939))


### 🍕 Features

* add force login component to design system ([#1330](https://github.com/open-sauced/insights/issues/1330)) ([9d68ffc](https://github.com/open-sauced/insights/commit/9d68ffcef1bbd2f17f05492d1b4e9d4ce4263de4))
* add top contributors panel to feeds page ([#1347](https://github.com/open-sauced/insights/issues/1347)) ([5b58dd5](https://github.com/open-sauced/insights/commit/5b58dd532ff495fa921053ee1bb48eef2544d678))
* added new topics to the list ([#1357](https://github.com/open-sauced/insights/issues/1357)) ([33f03bb](https://github.com/open-sauced/insights/commit/33f03bb53b82e8bb18e49c7e5ccba80c77ab982d))
* change position of visibility action component ([#1331](https://github.com/open-sauced/insights/issues/1331)) ([f3f615c](https://github.com/open-sauced/insights/commit/f3f615caf3b8a69943d6b1443ac0b35075501b4b))
* changed the last commit date icon with a calender ([#1350](https://github.com/open-sauced/insights/issues/1350)) ([2ae9d53](https://github.com/open-sauced/insights/commit/2ae9d5330e9231d108a9a20b458aed5398c7d24c))
* implement featured highlights list ([#1337](https://github.com/open-sauced/insights/issues/1337)) ([ed32594](https://github.com/open-sauced/insights/commit/ed32594c64dc616e57e7b9fbea299ba4584bdb68))
* implement newsletter submission functionality ([#1332](https://github.com/open-sauced/insights/issues/1332)) ([d996ac7](https://github.com/open-sauced/insights/commit/d996ac714fa2cf6394416fcb542c278634edc394))
* upgrade to Next 13.4, Supabase helper libs to 0.7.x ([#1301](https://github.com/open-sauced/insights/issues/1301)) ([26876c2](https://github.com/open-sauced/insights/commit/26876c260546815102ac5584c0579e12b1323361))

## [1.56.0-beta.12](https://github.com/open-sauced/insights/compare/v1.56.0-beta.11...v1.56.0-beta.12) (2023-07-17)


### 🍕 Features

* add top contributors panel to feeds page ([#1347](https://github.com/open-sauced/insights/issues/1347)) ([5b58dd5](https://github.com/open-sauced/insights/commit/5b58dd532ff495fa921053ee1bb48eef2544d678))

## [1.56.0-beta.11](https://github.com/open-sauced/insights/compare/v1.56.0-beta.10...v1.56.0-beta.11) (2023-07-17)


Expand Down
79 changes: 79 additions & 0 deletions components/atoms/TopContributorCard/top-contributor-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useEffect, useState } from "react";

import Link from "next/link";
import { useRouter } from "next/router";
import { getAvatarByUsername } from "lib/utils/github";
import useFollowUser from "lib/hooks/useFollowUser";
import useSupabaseAuth from "lib/hooks/useSupabaseAuth";

import Avatar from "../Avatar/avatar";
import Button from "../Button/button";

export interface TopContributorCardProps {
login: string;
}

const TopContributorCard = ({ login }: TopContributorCardProps) => {
const router = useRouter();
const currentPath = router.asPath;

const { isError: notFollowing, follow, unFollow } = useFollowUser(login);
const [host, setHost] = useState("");
const { sessionToken, signIn } = useSupabaseAuth();

const handleFollowContributor = async () => {
try {
if (notFollowing) {
await follow();
return;
}
await unFollow();
} catch (error) {
console.log(error);
}
};

useEffect(() => {
if (typeof window !== "undefined") {
setHost(window.location.origin as string);
}
}, []);

return (
<div className="flex items-center justify-between w-full gap-4 bg-light-slate-1">
<Link href={`/user/${login}`}>
<div className="flex items-center gap-2">
<Avatar isCircle size={35} avatarURL={getAvatarByUsername(login)} />
<p className="font-semibold text-light-slate-12">{login}</p>
</div>
</Link>
{sessionToken && !notFollowing ? (
<Button
onClick={() =>
sessionToken
? handleFollowContributor()
: signIn({ provider: "github", options: { redirectTo: `${host}/${currentPath}` } })
}
className="!px-2 !py-1"
variant="primary"
>
following
</Button>
) : (
<Button
onClick={() =>
sessionToken
? handleFollowContributor()
: signIn({ provider: "github", options: { redirectTo: `${host}/${currentPath}` } })
}
className="!px-2 !py-1 border-light-orange-7 text-light-orange-10"
variant="text"
>
follow
</Button>
)}
</div>
);
};

export default TopContributorCard;
36 changes: 0 additions & 36 deletions components/atoms/TopUserCard/top-user-card.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import TopContributorCard from "components/atoms/TopContributorCard/top-contributor-card";
import { useFetchTopContributors } from "lib/hooks/useFetchTopContributors";
import SkeletonWrapper from "components/atoms/SkeletonLoader/skeleton-wrapper";

interface TopContributorsPanelProps {
loggedInUserLogin: string;
}
const TopContributorsPanel = ({ loggedInUserLogin }: TopContributorsPanelProps) => {
const { data, isLoading } = useFetchTopContributors();

const topContributorsWithoutLoggedInUser = data ? data.filter((user) => user.login !== loggedInUserLogin) : [];
const top3Contributors = topContributorsWithoutLoggedInUser.slice(0, 3).map((user) => user.login);

return (
<div className="flex flex-col max-w-xs gap-6 p-6 bg-white border rounded-xl">
<h2 className="pb-2 text-2xl border-b">Top Contributors</h2>

{isLoading &&
Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="flex items-center justify-between gap-4 ">
<SkeletonWrapper radius={100} height={40} width={40} /> <SkeletonWrapper height={40} classNames="w-full" />
</div>
))}
{top3Contributors.map((login, i) => (
<TopContributorCard key={i} login={login} />
))}
</div>
);
};

export default TopContributorsPanel;
18 changes: 0 additions & 18 deletions components/molecules/TopUsersPanel/top-user-panel.tsx

This file was deleted.

20 changes: 20 additions & 0 deletions lib/hooks/useFetchTopContributors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import useSWR, { Fetcher } from "swr";
import publicApiFetcher from "lib/utils/public-api-fetcher";

type TopContributorsResponse = { login: string }[];

const useFetchTopContributors = () => {
const { data, error, mutate } = useSWR<TopContributorsResponse, Error>(
"users/top",
publicApiFetcher as Fetcher<TopContributorsResponse, Error>
);

return {
data: data ?? [],
isLoading: !error && !data,
isError: !!error,
mutate,
};
};

export { useFetchTopContributors };
7 changes: 5 additions & 2 deletions lib/hooks/useFollowUser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import useSWR, { Fetcher } from "swr";
import useSWR, { Fetcher, useSWRConfig } from "swr";
import publicApiFetcher from "lib/utils/public-api-fetcher";
import useSupabaseAuth from "./useSupabaseAuth";

interface FollowUserResponse {
data: DbFollowUser;
}
const useFollowUser = (username: string) => {
const { sessionToken } = useSupabaseAuth();
const { sessionToken, user } = useSupabaseAuth();
const { mutate: mutateGlobal } = useSWRConfig(); // adding this to mutate the global user data to update the users card status on follow/unfollow

const { data, error, mutate } = useSWR<FollowUserResponse, Error>(
username ? `users/${username}/follow` : null,
Expand All @@ -23,6 +24,7 @@ const useFollowUser = (username: string) => {

if (req && req.ok) {
mutate();
mutateGlobal(`user/${user?.user_metadata?.username}`);
}
};

Expand All @@ -36,6 +38,7 @@ const useFollowUser = (username: string) => {

if (req && req.ok) {
mutate();
mutateGlobal(`user/${user?.user_metadata?.username}`);
}
};

Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@open-sauced/insights",
"description": "🍕The dashboard for open source discovery.",
"keywords": [],
"version": "1.56.0-beta.11",
"version": "1.56.0",
"author": "Brian Douglas <brian@opensauced.pizza>",
"private": true,
"license": "Apache 2.0",
Expand Down
5 changes: 4 additions & 1 deletion pages/feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Link from "next/link";
import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict";
import clsx from "clsx";

import TopContributorsPanel from "components/molecules/TopContributorsPanel/top-contributors-panel";
import useSupabaseAuth from "lib/hooks/useSupabaseAuth";
import { useFetchAllHighlights } from "lib/hooks/useFetchAllHighlights";
import { useFetchHighlightRepos } from "lib/hooks/useFetchHiglightRepos";
Expand Down Expand Up @@ -68,6 +69,7 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (props: HighlightSSRProps) => {

const { data, mutate, setPage, isLoading, meta } = useFetchAllHighlights(selectedRepo);
const { data: emojis } = useFetchAllEmojis();

const { data: loggedInUser, isLoading: loggedInUserLoading } = useFetchUser(user?.user_metadata.user_name as string);

const { followers_count, following_count, highlights_count } = loggedInUser || {};
Expand Down Expand Up @@ -121,7 +123,7 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (props: HighlightSSRProps) => {
twitterCard="summary_large_image"
/>
<div className="container flex flex-col gap-16 px-2 pt-12 mx-auto md:px-16 lg:justify-end md:flex-row">
<div className="flex-col flex-1 hidden gap-8 mt-12 md:flex">
<div className="flex-col flex-1 hidden gap-6 mt-12 md:flex">
{user && (
<div>
<UserCard
Expand All @@ -132,6 +134,7 @@ const Feeds: WithPageLayout<HighlightSSRProps> = (props: HighlightSSRProps) => {
/>
</div>
)}
<TopContributorsPanel loggedInUserLogin={loggedInUser?.login ?? ""} />
</div>
{singleHighlight && (
<Dialog
Expand Down
18 changes: 8 additions & 10 deletions stories/atoms/top-user-card.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { ComponentStory } from "@storybook/react";
import TopUserCard from "components/atoms/TopUserCard/top-user-card";
import { StoryFn } from "@storybook/react";
import TopContributorCard from "components/atoms/TopContributorCard/top-contributor-card";

const storyConfig = {
title: "Design System/Atoms/TopUserCard",
title: "Design System/Atoms/TopContributorCard",
};
export default storyConfig;

const TopUserCardTemplate: ComponentStory<typeof TopUserCard> = (args) => <TopUserCard {...args} />;
const TopContributorCardTemplate: StoryFn<typeof TopContributorCard> = (args) => <TopContributorCard {...args} />;

export const Following = TopUserCardTemplate.bind({});
export const NotFollowing = TopUserCardTemplate.bind({});
export const Following = TopContributorCardTemplate.bind({});
export const NotFollowing = TopContributorCardTemplate.bind({});

Following.args = {
username: "diivi",
following: true,
login: "diivi",
};

NotFollowing.args = {
username: "ogdev-01",
following: false,
login: "ogdev-01",
};
16 changes: 16 additions & 0 deletions stories/molecules/top-contributors-panel.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Meta, StoryFn } from "@storybook/react";
import TopContributorsPanel from "components/molecules/TopContributorsPanel/top-contributors-panel";

const storyConfig = {
title: "Design System/Molecules/TopContributorsPanel",
} as Meta<typeof TopContributorsPanel>;

export default storyConfig;

const TopContributorsPanelTemplate: StoryFn<typeof TopContributorsPanel> = (args) => <TopContributorsPanel {...args} />;

export const Default = TopContributorsPanelTemplate.bind({});

Default.args = {
loggedInUserLogin: "ogdev-01",
};
23 changes: 0 additions & 23 deletions stories/molecules/top-users-panel.stories.tsx

This file was deleted.

0 comments on commit 7950b6f

Please sign in to comment.