Skip to content

Commit

Permalink
refactor: ramda,firebase and search-api
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Dec 7, 2024
1 parent 76a689a commit 91233b1
Show file tree
Hide file tree
Showing 67 changed files with 3,796 additions and 5,039 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config/*
scripts/*
public/*
*.test.tsx"
120 changes: 61 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@
"dependencies": {
"@csound/browser": "^6.18.7",
"@emotion/core": "^11.0.0",
"@emotion/css": "^11.13.0",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@emotion/css": "^11.13.5",
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@hlolli/codemirror-lang-csound": "^1.0.0-alpha9",
"@mui/icons-material": "^6.1.0",
"@mui/material": "^6.1.0",
"@reduxjs/toolkit": "^2.2.7",
"@vitejs/plugin-react": "^4.3.1",
"@mui/icons-material": "^6.1.10",
"@mui/material": "^6.1.10",
"@reduxjs/toolkit": "^2.4.0",
"@vitejs/plugin-react": "^4.3.4",
"connected-react-router": "^6.9.3",
"csound7": "npm:@csound/browser@^7.0.0-alpha2",
"date-fns": "^4.0.0-beta.1",
"firebase-functions": "^6.0.0",
"date-fns": "^4.1.0",
"firebase-functions": "^6.1.1",
"history": "^5.3.0",
"mime": "^4.0.4",
"ramda": "^0.30.1",
"react": "^18.3.1",
"react": "^19.0.0",
"react-autosuggest": "^10.1.0",
"react-beautiful-dnd": "^13.1.1",
"react-beforeunload": "^2.6.0",
"react-color": "^2.19.3",
"react-debounce-input": "^3.3.0",
"react-dev-utils": "^12.0.1",
"react-dom": "^18.3.1",
"react-dom": "^19.0.0",
"react-firebaseui": "^6.0.0",
"react-hotkeys": "^2.0.0",
"react-iframe-comm": "^1.2.2",
Expand All @@ -52,87 +52,88 @@
"react-piano": "^3.1.3",
"react-poppop": "^1.5.0",
"react-redux": "^9.1.2",
"react-refresh": "^0.14.2",
"react-router": "^6.26.2",
"react-router-dom": "^6.26.2",
"react-select": "^5.8.0",
"react-share": "^5.1.0",
"react-refresh": "^0.16.0",
"react-router": "^7.0.2",
"react-router-dom": "^7.0.2",
"react-select": "^5.8.3",
"react-share": "^5.1.1",
"react-sortable-hoc": "^2.0.0",
"react-split-pane": "^0.1.92",
"react-use-storage": "^0.5.1",
"redux": "^5.0.1",
"redux-first-history": "^5.2.0",
"url": "^0.11.4",
"vite": "^5.4.5",
"vite-tsconfig-paths": "^5.0.1",
"vite": "^6.0.3",
"vite-raw-plugin": "^1.0.2",
"vite-tsconfig-paths": "^5.1.4",
"wait-on": "^8.0.1"
},
"devDependencies": {
"@babel/core": "7.25.2",
"@babel/helper-builder-react-jsx": "^7.24.7",
"@babel/core": "7.26.0",
"@babel/helper-builder-react-jsx": "^7.25.9",
"@babel/helper-builder-react-jsx-experimental": "^7.12.11",
"@babel/helper-regex": "^7.10.5",
"@babel/plugin-transform-runtime": "^7.25.4",
"@babel/preset-env": "^7.25.4",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@babel/runtime": "^7.25.6",
"@babel/plugin-transform-runtime": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.26.3",
"@babel/preset-typescript": "^7.26.0",
"@babel/runtime": "^7.26.0",
"@emotion/babel-preset-css-prop": "^11.12.0",
"@eslint/js": "^9.10.0",
"@eslint/js": "^9.16.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@sentry/browser": "^8.30.0",
"@sentry/browser": "^8.42.0",
"@svgr/webpack": "^8.1.0",
"@testing-library/react": "^16.0.1",
"@testing-library/react": "^16.1.0",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.13",
"@types/lodash": "^4.17.7",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.13",
"@types/ramda": "^0.30.2",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/react": "^19.0.1",
"@types/react-dom": "^19.0.1",
"@types/react-onclickoutside": "^6.7.10",
"@types/react-redux": "^7.1.33",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"@types/react-redux": "^7.1.34",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"array-move": "^4.0.0",
"autosuggest-highlight": "^3.3.4",
"babel-eslint": "10.1.0",
"babel-loader": "9.1.3",
"babel-loader": "9.2.1",
"babel-plugin-named-asset-import": "^0.3.8",
"camelcase": "^8.0.0",
"case-sensitive-paths-webpack-plugin": "2.4.0",
"codemirror": "^6.0.1",
"concurrently": "^9.0.1",
"concurrently": "^9.1.0",
"copy-webpack-plugin": "^12.0.2",
"cross-env": "^7.0.3",
"css-loader": "7.1.2",
"d3-scale": "^4.0.2",
"dom-to-image-more": "^3.4.5",
"dotenv": "16.4.5",
"dotenv-expand": "11.0.6",
"electron": "^32.1.0",
"electron-builder": "^25.0.5",
"dom-to-image-more": "^3.5.0",
"dotenv": "16.4.7",
"dotenv-expand": "12.0.1",
"electron": "^33.2.1",
"electron-builder": "^25.1.8",
"electron-is-dev": "^3.0.1",
"eslint": "^9.10.0",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-react-app": "^7.0.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-flowtype": "8.0.3",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jsx-a11y": "6.10.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsx-a11y": "6.10.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "7.36.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-unicorn": "^56.0.1",
"eslint-webpack-plugin": "^4.2.0",
"file-loader": "6.2.0",
"file-saver": "^2.0.5",
"firebase": "^10.13.1",
"firebase": "^11.0.2",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"fuse.js": "^7.0.0",
"globals": "^15.9.0",
"globals": "^15.13.0",
"hex-rgb": "^5.0.0",
"html-webpack-plugin": "5.6.0",
"husky": "^9.1.6",
"html-webpack-plugin": "5.6.3",
"husky": "^9.1.7",
"jest": "29.7.0",
"jest-environment-jsdom-fourteen": "1.0.1",
"jest-fetch-mock": "^3.0.3",
Expand All @@ -142,7 +143,7 @@
"moment": "^2.30.1",
"pnp-webpack-plugin": "1.7.0",
"postcss-loader": "8.1.1",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"raw-loader": "^4.0.2",
"react-app-polyfill": "^3.0.0",
"react-redux-test-renderer": "^4.0.1",
Expand All @@ -159,17 +160,18 @@
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"ts-pnp": "1.2.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.5.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0",
"url-loader": "4.1.1",
"uuid": "^10.0.0",
"uuid": "^11.0.3",
"vite-plugin-checker": "^0.8.0",
"vite-plugin-environment": "^1.1.3",
"vite-plugin-svgr": "^4.2.0",
"webpack": "5.94.0",
"vite-plugin-svgr": "^4.3.0",
"webpack": "5.97.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "5.1.0",
"webpack-manifest-plugin": "5.0.0",
"workbox-webpack-plugin": "7.1.0",
"workbox-webpack-plugin": "7.3.0",
"workerize-loader": "^2.0.2"
},
"resolutions": {
Expand Down
41 changes: 26 additions & 15 deletions search/database.js → search/database.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,59 @@
const fs = require("fs");
const { getFirebaseData } = require("./firebase");
const databaseName = { dev: "dev-database.json", prod: "prod-database.json" };
import fs from "node:fs";
import { getFirebaseData } from "./firebase";
import { isSameHour } from "date-fns";

const databaseName: { dev: string; prod: string } = {
dev: "dev-database.json",
prod: "prod-database.json"
};

const databaseFolder = "./";
const { isSameHour } = require("date-fns");

const checkDatabaseFileWrittenSameHour = () => {
interface DatabaseFile {
timestamp: string;
}

const checkDatabaseFileWrittenSameHour = (
databaseID: "dev" | "prod"
): boolean => {
try {
const { timestamp } = openDatabaseFile(databaseID);
return isSameHour(new Date(timestamp), new Date());
} catch (e) {
} catch {
return false;
}
};

const openDatabaseFile = databaseID => {
const openDatabaseFile = (databaseID: "dev" | "prod"): DatabaseFile => {
const file = fs.readFileSync(
`${databaseFolder}/${databaseName[databaseID]}`,
"utf8"
);
return JSON.parse(file);
};

const writeDatabaseFile = (object, path) => {
const writeDatabaseFile = (object: unknown, path: string): void => {
const fileJSON = JSON.stringify(object);
fs.writeFileSync(path, fileJSON);
};

const writeFirebaseDataToDatabaseFile = async databaseID => {
const writeFirebaseDataToDatabaseFile = async (
databaseID: "dev" | "prod"
): Promise<void> => {
const fireBaseData = await getFirebaseData(databaseID);
writeDatabaseFile(
fireBaseData,
`${databaseFolder}/${databaseName[databaseID]}`
);
};

const getDatabase = async databaseID => {
export const getDatabase = async (
databaseID: "dev" | "prod"
): Promise<DatabaseFile> => {
const sameHour = checkDatabaseFileWrittenSameHour(databaseID);

if (sameHour === false) {
if (!sameHour) {
await writeFirebaseDataToDatabaseFile(databaseID);
}
return openDatabaseFile(databaseID);
};

module.exports = {
getDatabase
};
95 changes: 0 additions & 95 deletions search/firebase.js

This file was deleted.

Loading

0 comments on commit 91233b1

Please sign in to comment.