Skip to content

Commit

Permalink
feat: init the chrome extension (#183)
Browse files Browse the repository at this point in the history
* lottie 优化
* 初始化chrome 侧边栏插件
  • Loading branch information
xingwanying authored Jul 17, 2024
2 parents bd36503 + 728ce29 commit 4304f0e
Show file tree
Hide file tree
Showing 28 changed files with 22,216 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function RootLayout({
<BotProvider>
<div className="flex flex-col">
<Navbar></Navbar>
{children}
<div className="pb-[40px]">{children}</div>
</div>
</BotProvider>
</SearchProvider>
Expand Down
8 changes: 6 additions & 2 deletions client/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export default function Home() {

if (isOpening) {
return (
<FullPageSkeleton type="OPENING" onComplete={() => setComplete(true)} />
<FullPageSkeleton
type="OPENING"
loop={false}
onComplete={() => setComplete(true)}
/>
);
}

Expand All @@ -61,7 +65,7 @@ export default function Home() {
}

return (
<div className="mb-[40px]">
<div>
<div className="grid grid-flow-row-dense gap-8 justify-items-center px-[40px] grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6">
<BotList type="list" />
{!isEmpty(bots) &&
Expand Down
7 changes: 4 additions & 3 deletions client/components/FullPageSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ export const SKELETON_MAP = {

export interface FullPageSkeletonProps {
type?: 'LOADING' | 'OPENING';
loop?: boolean;
onComplete?: () => void;
}

const FullPageSkeleton = (props: FullPageSkeletonProps) => {
const { type = 'LOADING', onComplete } = props;
const { type = 'LOADING', onComplete, loop = true } = props;
return (
<div className="fixed top-0 left-0 right-0 bottom-0 z-50 flex justify-center items-center bg-white bg-opacity-75">
<Lottie
loop={true}
loop={loop}
autoplay={true}
animationData={SKELETON_MAP[type]}
onLoopComplete={onComplete}
onComplete={onComplete}
style={{
minHeight: '900px',
maxHeight: '1440px',
Expand Down
10,001 changes: 10,000 additions & 1 deletion client/public/loading.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
22 changes: 22 additions & 0 deletions extension/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// create out directory for static Chrome Extension

const fs = require('fs');
const glob = require('glob');

const files = glob.sync('out/**/*.html');
files.forEach((file) => {
const content = fs.readFileSync(file, 'utf-8');
const modifiedContent = content.replace(/\/_next/g, './next');
fs.writeFileSync(file, modifiedContent, 'utf-8');
});

const sourcePath = 'out/_next';
const destinationPath = 'out/next';

fs.rename(sourcePath, destinationPath, (err) => {
if (err) {
console.error('Rename failed:', err);
} else {
console.log('Rename successfully.');
}
});
17 changes: 17 additions & 0 deletions extension/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
output: 'export',

// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
// trailingSlash: true,

// Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
// skipTrailingSlashRedirect: true,

// Optional: Change the output directory `out` -> `dist`
// distDir: 'dist',
}

module.exports = nextConfig
40 changes: 40 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "extension",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "npm run prep",
"prep": "next build && node export.js",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"autoprefixer": "^10.4.19",
"css-loader": "^7.1.2",
"mini-css-extract-plugin": "^2.9.0",
"next": "14.2.5",
"next-compose-plugins": "^2.2.1",
"petercat-lui": "^0.0.24",
"postcss-loader": "^8.1.1",
"react": "^18",
"react-dom": "^18",
"style-loader": "^4.0.0"
},
"devDependencies": {
"@types/chrome": "^0.0.268",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"next-transpile-modules": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.4.6",
"ts-loader": "^9.5.1",
"typescript": "^5",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
}
}
6 changes: 6 additions & 0 deletions extension/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
3 changes: 3 additions & 0 deletions extension/public/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((error) => console.error(error));
Binary file added extension/public/icons/logo-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icons/logo-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icons/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icons/logo-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions extension/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"manifest_version": 3,
"name": "PeterCat",
"short_name": "petercat",
"version": "0.0.1",
"description": "petercat, your github Q&A assitant",
"icons": {
"16": "/icons/logo-16.png",
"32": "/icons/logo-32.png",
"48": "/icons/logo-48.png",
"192": "/icons/logo-192.png"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "点击打开侧边栏"
},
"side_panel": {
"default_path": "index.html"
},
"permissions": ["sidePanel"]
}
Binary file added extension/src/app/favicon.ico
Binary file not shown.
33 changes: 33 additions & 0 deletions extension/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}
19 changes: 19 additions & 0 deletions extension/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Metadata } from 'next';
import './globals.css';

export const metadata: Metadata = {
title: 'PeterCat',
description: 'Create your own Q&A bot',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="zh-CN">
<body>{children}</body>
</html>
);
}
18 changes: 18 additions & 0 deletions extension/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';

export default function Home() {
return (
<main
style={{
width: '100vw',
height: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '64px',
}}
>
<h1>PeterCat</h1>
</main>
);
}
14 changes: 14 additions & 0 deletions extension/src/components/ChatPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';
import { Chat } from 'petercat-lui';
import React from 'react';
const ChatPanel = () => {
return (
<Chat
apiDomain="https://api.petercat.chat"
apiUrl="/api/chat/stream_qa"
token="594dc633-acf6-4fed-a52d-c5852c6f4694"
/>
);
};

export default ChatPanel;
20 changes: 20 additions & 0 deletions extension/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from "tailwindcss";

const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
plugins: [],
};
export default config;
27 changes: 27 additions & 0 deletions extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"outDir": "./dist",
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 4304f0e

Please sign in to comment.