Skip to content

Commit

Permalink
Merge branch 'beta' into feat/repo-pages-contributor-graph
Browse files Browse the repository at this point in the history
  • Loading branch information
zeucapua committed May 1, 2024
2 parents e9b049c + 515c916 commit 3711d85
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 18 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@

> All notable changes to this project will be documented in this file

## [2.23.1-beta.1](https://github.com/open-sauced/app/compare/v2.23.0...v2.23.1-beta.1) (2024-05-01)


### 🐛 Bug Fixes

* explore links 404 ([#3297](https://github.com/open-sauced/app/issues/3297)) ([ba05a16](https://github.com/open-sauced/app/commit/ba05a16f55f73b518eb6b62ed388d92ebfe8f70e))

## [2.23.0](https://github.com/open-sauced/app/compare/v2.22.0...v2.23.0) (2024-05-01)


### 🐛 Bug Fixes

* repository page speed improvements ([#3269](https://github.com/open-sauced/app/issues/3269)) ([fcbf89d](https://github.com/open-sauced/app/commit/fcbf89d54f098fbaa8487fede28ab15f954fc29b))


### 🍕 Features

* add nudge bottom banner for non logged in users ([#3259](https://github.com/open-sauced/app/issues/3259)) ([ea88536](https://github.com/open-sauced/app/commit/ea8853636d24d462edd4e57e640ef3974dfc00b9))
* implement 'Add to workspace' in repo pages ([#3282](https://github.com/open-sauced/app/issues/3282)) ([b1efc46](https://github.com/open-sauced/app/commit/b1efc46c20fbe9316c0125b1bddc713ca6d923e2))

## [2.23.0-beta.2](https://github.com/open-sauced/app/compare/v2.23.0-beta.1...v2.23.0-beta.2) (2024-05-01)


### 🍕 Features

* implement 'Add to workspace' in repo pages ([#3282](https://github.com/open-sauced/app/issues/3282)) ([b1efc46](https://github.com/open-sauced/app/commit/b1efc46c20fbe9316c0125b1bddc713ca6d923e2))

## [2.23.0-beta.1](https://github.com/open-sauced/app/compare/v2.22.1-beta.1...v2.23.0-beta.1) (2024-05-01)


Expand Down
117 changes: 117 additions & 0 deletions components/Repositories/AddToWorkspaceDrawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { MdWorkspaces } from "react-icons/md";
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { BsGithub } from "react-icons/bs";
import Button from "components/shared/Button/button";
import { Drawer } from "components/shared/Drawer";
import { useToast } from "lib/hooks/useToast";
import useSupabaseAuth from "lib/hooks/useSupabaseAuth";
import useWorkspaces from "lib/hooks/api/useWorkspaces";
import { fetchApiData } from "helpers/fetchApiData";
import SingleSelect from "components/atoms/Select/single-select";
import Text from "components/atoms/Typography/text";

export default function AddToWorkspaceDrawer({ repository }: { repository: string }) {
const router = useRouter();
const { toast } = useToast();
const { signIn, user, sessionToken } = useSupabaseAuth();
const [workspaceId, setWorkspaceId] = useState("new");
const { data: workspaces, isLoading: workspacesLoading, mutate } = useWorkspaces({ load: !!user, limit: 100 });

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

const addRepositoryToWorkspace = async () => {
if (workspaceId === "new") {
router.push(`/workspaces/new?repos=${JSON.stringify([repository])}`);
return;
}

const { data, error } = await fetchApiData<Workspace>({
method: "POST",
path: `workspaces/${workspaceId}/repos/${repository}`,
body: {}, // empty body needed to avoid error
bearerToken: sessionToken!,
pathValidator: () => true,
});

if (error) {
toast({ description: `Error adding repository to the workspace. Please try again`, variant: "danger" });
} else {
toast({ description: `Added repository successfully`, variant: "success" });
}
};
return (
<Drawer
title="Add repository to Workspace"
description="Create a new workspace or add to an existing one."
showCloseButton
trigger={
<Button variant="primary" className="shrink-0 items-center gap-3 w-fit">
<MdWorkspaces />
Add to Workspace
</Button>
}
>
{!user ? (
<div className="flex flex-col gap-4 text-center">
<img
src="/assets/workspace_overview.png"
alt="Workspace screenshot from documentation"
className="border-2 border-light-orange-9 shadow-md rounded-lg"
/>
<Text>
Keep track of repositories and contributors easily with our new feature
<span className="font-semibold"> Workspaces!</span> If you&apos;ve used OpenSauced before, your insights and
lists are now part of your personal workspace.
</Text>
<p className="font-medium text-light-orange-10">
Create a new workspace with this repository and explore open source like never before!
</p>
<Button
variant="primary"
className="w-fit gap-2 self-center"
onClick={() => {
signIn({
provider: "github",
options: { redirectTo: `${host}/workspaces/new?repos=${JSON.stringify([repository])}` },
});
}}
>
<BsGithub className="w-5 h-5" />
Connect with GitHub
</Button>
</div>
) : (
<>
{workspacesLoading ? (
<p>Loading...</p>
) : (
<SingleSelect
options={[
{ label: "Create new workspace...", value: "new" },
...workspaces.map(({ id, name }) => ({
label: name,
value: id,
})),
]}
position="popper"
value={workspaceId ?? "new"}
placeholder="Select a workspace"
onValueChange={(value) => {
setWorkspaceId(value);
}}
/>
)}
<Button onClick={addRepositoryToWorkspace} variant="primary" className="w-full !grid">
Confirm
</Button>
</>
)}
</Drawer>
);
}
122 changes: 122 additions & 0 deletions components/Repositories/AddToWorkspaceModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { BsGithub } from "react-icons/bs";
import Card from "components/atoms/Card/card";
import SingleSelect from "components/atoms/Select/single-select";
import { Dialog, DialogContent } from "components/molecules/Dialog/dialog";
import Button from "components/shared/Button/button";
import { fetchApiData } from "helpers/fetchApiData";
import useWorkspaces from "lib/hooks/api/useWorkspaces";
import useSupabaseAuth from "lib/hooks/useSupabaseAuth";
import { useToast } from "lib/hooks/useToast";
import Text from "components/atoms/Typography/text";

type AddToWorkspaceModalProps = {
repository: string;
isOpen: boolean;
onCloseModal: () => void;
};

export default function AddToWorkspaceModal({ repository, isOpen, onCloseModal }: AddToWorkspaceModalProps) {
const { toast } = useToast();
const router = useRouter();
const { signIn, user, sessionToken } = useSupabaseAuth();
const [workspaceId, setWorkspaceId] = useState("new");
const { data: workspaces, isLoading: workspacesLoading, mutate } = useWorkspaces({ load: !!user, limit: 100 });

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

const addRepositoryToWorkspace = async () => {
if (workspaceId === "new") {
router.push(`/workspaces/new?repos=${JSON.stringify([repository])}`);
return;
}

const { data, error } = await fetchApiData<Workspace>({
method: "POST",
path: `workspaces/${workspaceId}/repos/${repository}`,
body: {}, // empty body needed to avoid error
bearerToken: sessionToken!,
pathValidator: () => true,
});

if (error) {
toast({ description: `Error adding repository to the workspace. Please try again`, variant: "danger" });
} else {
toast({ description: `Added repository successfully`, variant: "success" });
onCloseModal();
}
};

return (
<Dialog open={isOpen}>
<DialogContent autoStyle={false} onEscapeKeyDown={onCloseModal} onInteractOutside={onCloseModal}>
<Card heading={<h1 className="text-xl font-semibold">Add to workspace</h1>}>
<div className="flex flex-col gap-4 w-[32rem] h-full px-8 py-4">
{!user ? (
<div className="flex flex-col gap-4 text-center">
<img
src="/assets/workspace_overview.png"
alt="Workspace screenshot from documentation"
className="border-2 border-light-orange-9 shadow-md rounded-lg"
/>
<Text>
Keep track of repositories and contributors easily with our new feature
<span className="font-semibold"> Workspaces!</span> If you&apos;ve used OpenSauced before, your
insights and lists are now part of your personal workspace.
</Text>
<p className="font-medium text-light-orange-10">
Create a new workspace with this repository and explore open source like never before!
</p>
<Button
variant="primary"
className="w-fit gap-2 self-center"
onClick={() => {
signIn({
provider: "github",
options: { redirectTo: `${host}/workspaces/new?repos=${JSON.stringify([repository])}` },
});
}}
>
<BsGithub className="w-5 h-5" />
Connect with GitHub
</Button>
</div>
) : (
<>
<p>Create a new workspace or add to an existing one.</p>
{workspacesLoading ? (
<p>Loading...</p>
) : (
<SingleSelect
options={[
{ label: "Create new workspace...", value: "new" },
...workspaces.map(({ id, name }) => ({
label: name,
value: id,
})),
]}
position="popper"
value={workspaceId ?? "new"}
placeholder="Select a workspace"
onValueChange={(value) => {
setWorkspaceId(value);
}}
/>
)}
<Button onClick={addRepositoryToWorkspace} variant="primary" className="w-fit self-end">
Confirm
</Button>
</>
)}
</div>
</Card>
</DialogContent>
</Dialog>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const ContributorProfileInfo = ({
</Title>
<div className="flex gap-1.5 flex-wrap">
{interestArray.map((interest, index) => (
<Link href={`/${interest}/dashboard/filter/recent`} key={index} className="rounded-3xl">
<Link href={`/explore/topic/${interest}/dashboard/filter/recent`} key={index} className="rounded-3xl">
<LanguagePill topic={interest} />
</Link>
))}
Expand Down
2 changes: 1 addition & 1 deletion components/shared/AppSidebar/AppSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const AppSideBar = ({ workspaceId, hideSidebar, sidebarCollapsed }: AppSi
/>
<SidebarMenuItem
title="Explore"
url={`/${userInterest}/dashboard/filter/recent`}
url={`/explore/topic/${userInterest}/dashboard/filter/recent`}
icon={<Squares2X2Icon className="w-5 h-5 text-slate-400" />}
/>
<SidebarMenuItem
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/app",
"description": "🍕The dashboard for open source discovery.",
"keywords": [],
"version": "2.23.0-beta.1",
"version": "2.23.1-beta.1",
"author": "Brian Douglas <brian@opensauced.pizza>",
"private": true,
"license": "Apache 2.0",
Expand Down
Loading

0 comments on commit 3711d85

Please sign in to comment.