Skip to content

Commit

Permalink
revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh committed Jun 30, 2024
1 parent af69f29 commit 947b5c3
Show file tree
Hide file tree
Showing 66 changed files with 2,185 additions and 1,311 deletions.
18 changes: 9 additions & 9 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"trailingComma": "all",
"printWidth": 140,
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"bracketSameLine": false,
"useTabs": true
}
"trailingComma": "all",
"printWidth": 140,
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"bracketSameLine": false,
"useTabs": true
}
23 changes: 18 additions & 5 deletions .vscode/unthread.me.code-workspace
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"folders": [
{
"path": "../"
}
"path": "../",
},
],
"settings": {
"editor.formatOnSave": true,
Expand All @@ -11,11 +11,24 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always",
// "source.organizeImports": "always",
"source.fixAll": "always"
"source.fixAll": "always",
},
"files.associations": {
"tsconfig.*json": "jsonc",
"*.css": "tailwindcss",
}
},
"typescript.inlayHints.parameterNames.suppressWhenArgumentMatchesName": true,
"editor.detectIndentation": false,
"prettier.requireConfig": true,
"typescript.inlayHints.parameterNames.enabled": "all",
"typescript.inlayHints.variableTypes.enabled": false,
"typescript.inlayHints.propertyDeclarationTypes.enabled": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"eslint.useESLintClass": true,
"explorer.sortOrder": "type",
"explorer.sortOrderLexicographicOptions": "upper",
"[dotenv]": {
"editor.defaultFormatter": "foxundermoon.shell-format",
},
},
}
}
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ This template provides a minimal setup to get React working in Vite with HMR and

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:
- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
// other rules...
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
Binary file modified bun.lockb
Binary file not shown.
121 changes: 64 additions & 57 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,65 @@
{
"name": "unthread.me",
"private": false,
"version": "0.0.0",
"type": "module",
"homepage": "https://unthread.me/",
"scripts": {
"dev": "vite",
"build": "bunx --bun vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"format": "prettier --write ."
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@react-spring/web": "^9.7.3",
"@types/bun": "^1.1.5",
"@types/chai": "^4.3.16",
"@types/express": "^4.17.21",
"@types/node": "^20.14.8",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"apexcharts": "^3.49.2",
"autoprefixer": "^10.4.19",
"body-parser": "^1.20.2",
"compromise": "^14.13.0",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-vite": "^2.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-unused-imports": "^4.0.0",
"express": "^4.19.2",
"ky": "^1.3.0",
"path": "^0.12.7",
"pify": "^6.1.0",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"react-apexcharts": "^1.4.1",
"react-router-dom": "^6.23.1",
"tailwindcss": "^3.4.4",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"vite": "^5.3.1",
"zustand": "^4.5.2"
}
}
"name": "unthread.me",
"private": false,
"version": "0.0.0",
"type": "module",
"homepage": "https://unthread.me/",
"scripts": {
"dev": "vite",
"build": "bunx --bun vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --fix --max-warnings 0",
"preview": "vite preview",
"format": "prettier --write .",
"index": "iigen"
},
"dependencies": {
"@lingui/core": "^4.11.1",
"import-index-generator": "^0.2.2",
"make-plural": "^7.4.0",
"polished": "^4.3.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"ua-parser-js": "^1.0.38"
},
"devDependencies": {
"@react-spring/web": "^9.7.3",
"@types/bun": "^1.1.5",
"@types/chai": "^4.3.16",
"@types/express": "^4.17.21",
"@types/node": "^20.14.8",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"apexcharts": "^3.49.2",
"autoprefixer": "^10.4.19",
"body-parser": "^1.20.2",
"compromise": "^14.13.0",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-vite": "^2.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-unused-imports": "^4.0.0",
"express": "^4.19.2",
"ky": "^1.3.0",
"path": "^0.12.7",
"pify": "^6.1.0",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"react-apexcharts": "^1.4.1",
"react-router-dom": "^6.23.1",
"tailwindcss": "^3.4.4",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"vite": "^5.3.1",
"zustand": "^4.5.2"
}
}
2 changes: 1 addition & 1 deletion prettier.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
export default {
plugins: [require("prettier-plugin-tailwindcss")],
};
62 changes: 62 additions & 0 deletions scripts/generate-indexes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as fs from "fs";
import * as path from "path";

const srcDir = path.resolve(__dirname, "../src");

// Function to check if file contains 'export default'
const hasDefaultExport = (filePath: string): boolean => {
const content = fs.readFileSync(filePath, "utf-8");
return content.includes("export default");
};

// Function to generate index.ts
const generateIndexFile = (dirPath: string) => {
const files = fs.readdirSync(dirPath).filter((file) => file.endsWith(".ts") && file !== "index.ts" && !file.includes(".styles."));
const imports: string[] = [];
const exports: string[] = [];

files.forEach((file) => {
const filePath = path.join(dirPath, file);
if (hasDefaultExport(filePath)) {
const fileName = path.basename(file, ".ts");
imports.push(`import ${fileName} from "./${fileName}";`);
exports.push(fileName);
}
});

if (imports.length > 0) {
const indexContent = `${imports.join("\n")}
export default {
${exports.join(",\n ")},
};`;

fs.writeFileSync(path.join(dirPath, "index.ts"), indexContent, "utf-8");
console.log(`Generated index.ts in ${dirPath}`);
}
};

// Function to start the process
const generateIndexes = (baseDir: string) => {
const getDirectories = (dir: string): string[] => {
const subdirs = fs
.readdirSync(dir)
.map((subdir) => path.join(dir, subdir))
.filter((subdirPath) => fs.statSync(subdirPath).isDirectory());
return subdirs.reduce((acc: string[], subdir) => acc.concat(subdir, getDirectories(subdir)), []);
};

const directories = [baseDir, ...getDirectories(baseDir)];

console.log("Directories", directories);

directories.forEach((dir) => {
console.log(`Generating index.ts in ${dir}`);
generateIndexFile(dir);
});
};

// Start

// Start generating index.ts files
generateIndexes(srcDir);
27 changes: 12 additions & 15 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import { Navigate, Route, Routes } from "react-router-dom";

import Home from "@src/pages/Home";

import useAccessTokenUpdater from "./hooks/useAccessTokenUpdater";
import { useThreadsAPIExirationUpdater, useThreadsAPIMediaDataUpdater, useThreadsAPIUserDataUpdater } from "./hooks/useThreadsAPI";
import useAccessTokenUpdater from "./client/hooks/useAccessTokenUpdater";
import {
getAllUserInsightsWithDefaultParams,
getDefaultConversation,
getFollowerDemographicsInsights,
getMediaInsightsWithDefaultParams,
getUserProfile,
getUserThreads,
} from "./threadsapi/api";
useThreadsAPIExirationUpdater,
useThreadsAPIMediaDataUpdater,
useThreadsAPIUserDataUpdater,
} from "./client/hooks/useCacheStoreUpdaters";
import threadsapi from "./threadsapi";

const App: FC = () => {
useAccessTokenUpdater();
useThreadsAPIUserDataUpdater("user_profile", getUserProfile);
useThreadsAPIUserDataUpdater("user_threads", getUserThreads);
useThreadsAPIUserDataUpdater("user_insights", getAllUserInsightsWithDefaultParams);
useThreadsAPIUserDataUpdater("user_follower_demographics", getFollowerDemographicsInsights);
useThreadsAPIMediaDataUpdater("user_threads_replies", getDefaultConversation);
useThreadsAPIMediaDataUpdater("user_threads_insights", getMediaInsightsWithDefaultParams);
useThreadsAPIUserDataUpdater("user_profile", threadsapi.get_user_profile);
useThreadsAPIUserDataUpdater("user_threads", threadsapi.get_user_threads);
useThreadsAPIUserDataUpdater("user_insights", threadsapi.get_user_insights);
useThreadsAPIUserDataUpdater("user_follower_demographics", threadsapi.get_follower_demographics);
useThreadsAPIMediaDataUpdater("user_threads_replies", threadsapi.get_conversation);
useThreadsAPIMediaDataUpdater("user_threads_insights", threadsapi.get_media_insights);
useThreadsAPIExirationUpdater();
return (
<>
Expand Down
Loading

0 comments on commit 947b5c3

Please sign in to comment.