Skip to content

Commit

Permalink
initial flow created
Browse files Browse the repository at this point in the history
  • Loading branch information
staranbeer committed Dec 15, 2022
1 parent b4fe693 commit 3dbe8ea
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 37 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"react-dom": "18.2.0",
"styled-components": "5.3.6",
"typescript": "4.9.4"
},
"devDependencies": {
"@types/styled-components": "^5.1.26"
}
}
11 changes: 0 additions & 11 deletions pages/_app.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions pages/api/hello.ts

This file was deleted.

7 changes: 0 additions & 7 deletions pages/index.tsx

This file was deleted.

25 changes: 19 additions & 6 deletions pnpm-lock.yaml

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

45 changes: 45 additions & 0 deletions src/components/AddGithubRepo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Block, Button, Flex, TextInput } from "@cube-dev/ui-kit";
import { useRouter } from "next/router";
import { useState } from "react";

function AddGithubRepo() {
const [value, setValue] = useState("");
const [valid, setValid] = useState(true);

const router = useRouter();
function handleSubmit(value: string) {
const githubRegex = "^https:\\/\\/[^\\/:]+[\\/:]([^\\/:]+)\\/(.+)";
const chunks = value.match(githubRegex);

if (!value) {
return setValid(false);
}

if (value.startsWith("https://github.com")) {
const chunks = value.match(githubRegex);
if (chunks && chunks.length === 3) {
router.push(`${chunks[1]}/${chunks[2]}`);
return setValid(true);
}
}

setValue("");
}

return (
<Flex gap="1rem" flow="column">
<TextInput
value={value}
onChange={setValue}
label="Add github repo"
placeholder="http://github.com/staranbeer/blog"
/>
<Button onPress={() => handleSubmit(value)} type="primary">
Submit
</Button>
{!valid && <Block color="#ff0000">please enter a valid repo</Block>}
</Flex>
);
}

export default AddGithubRepo;
29 changes: 29 additions & 0 deletions src/pages/[...docs].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";

export async function getServerSideProps() {
return { props: { name: "taran" } };
}

function Docs({ name }: InferGetServerSidePropsType<GetServerSideProps>) {

const router = useRouter();

const [owner, setOwner] = useState<string>("");
const [repo, setRepo] = useState<string>("");

useEffect(() => {
if (router.query.docs) {
setOwner(router.query.docs[0]);
setRepo(router.query.docs[1]);
}
console.log(owner, repo);
}, []);

return <div>{name}</div>;
}

export default Docs;

// https://github.com/staranbeer/blog
13 changes: 13 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "../../styles/globals.css";
import type { AppProps } from "next/app";
import { Root, SSRProvider } from "@cube-dev/ui-kit";

export default function App({ Component, pageProps }: AppProps) {
return (
<Root>
<SSRProvider>
<Component {...pageProps} />
</SSRProvider>
</Root>
);
}
25 changes: 25 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Document, { DocumentContext } from "next/document";
import { ServerStyleSheet } from "styled-components";

export default class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
sheet.collectStyles(<App {...props} />),
});

const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: [initialProps.styles, sheet.getStyleElement()],
};
} finally {
sheet.seal();
}
}
}
17 changes: 17 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Button, Flex, TextInput } from "@cube-dev/ui-kit";
import AddGithubRepo from "../components/AddGithubRepo";

function Home() {
return (
<Flex
justifyContent="center"
alignItems="center"
styles={{ minHeight: "100vh" }}
overflow="hidden"
>
<AddGithubRepo />
</Flex>
);
}

export default Home;

0 comments on commit 3dbe8ea

Please sign in to comment.