Skip to content

Commit

Permalink
🚀 perf: add import sorting order + lazy components
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerd Müller committed Dec 20, 2023
1 parent d36fccc commit 267e8c2
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 36 deletions.
17 changes: 2 additions & 15 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ module.exports = {
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh', 'prettier'],
rules: {
'prettier/prettier': [
'error',
{
singleQuote: false,
semi: true,
printWidth: 80,
},
],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
plugins: ['react-refresh'],
rules: { 'prettier/prettier': 1},
}
20 changes: 20 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bracketSpacing": true,
"jsonRecursiveSort": true,
"importOrder": [
"<THIRD_PARTY_MODULES>",
"^@material-ui/(.*)$",
"src",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": [
"prettier-plugin-sort-json",
"@trivago/prettier-plugin-sort-imports"
],
"semi": true,
"singleQuote": false,
"printWidth": 80,
"trailingComma": "all"
}
129 changes: 129 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"zustand": "^4.4.7"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^6.15.0",
Expand All @@ -42,6 +43,7 @@
"eslint-plugin-react-refresh": "^0.4.5",
"postcss": "^8.4.32",
"prettier": "^3.1.1",
"prettier-plugin-sort-json": "^3.1.0",
"react-icons": "^4.12.0",
"tailwindcss": "^3.3.7",
"typescript": "^5.3.3",
Expand Down
5 changes: 3 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Routes, Route } from "react-router-dom";
import Layout from "./Layout";
import { Route, Routes } from "react-router-dom";

import Collection from "./Collection";
import Creation from "./Creation";
import Layout from "./Layout";
import Select from "./Select";
import Start from "./Start";

Expand Down
17 changes: 10 additions & 7 deletions src/components/Collection.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useState } from "react";
import { Masonry } from "react-plock";
import Viewer from "@samvera/clover-iiif/viewer";

// import Viewer from "@samvera/clover-iiif/viewer";
// @ts-ignore
import { Block, Button, Card, Page, Navbar, Link, Popup } from "konsta/react";
import { Block, Button, Card, Link, Navbar, Page, Popup } from "konsta/react";
import { Suspense, lazy, useState } from "react";
import { Masonry } from "react-plock";

import utils from "../utils";
import useStore, { Image } from "../store";
import utils from "../utils";

const Viewer = lazy(() => import("@samvera/clover-iiif/viewer"));

const options = {
canvasBackgroundColor: "010A01",
Expand Down Expand Up @@ -101,7 +102,9 @@ function Collection() {
}
/>
<Block className="space-y-4">
<Viewer iiifContent={selectedImage.url} options={options} />
<Suspense fallback={<h2>🌀 Loading...</h2>}>
<Viewer iiifContent={selectedImage.url} options={options} />
</Suspense>
<Button
className="px-4 py-2 rounded-full mr-2"
onClick={() =>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NavLink, Outlet, useMatch, useResolvedPath } from "react-router-dom";
// @ts-ignore
import { App, Icon, Page, Tabbar, TabbarLink } from "konsta/react";
import {
MdOutlineDoorFront,
MdFavoriteBorder,
MdOutlineCollections,
MdOutlineAssignmentInd,
MdOutlineCollections,
MdOutlineDoorFront,
} from "react-icons/md";
import { NavLink, Outlet, useMatch, useResolvedPath } from "react-router-dom";

function Layout() {
return (
Expand Down
8 changes: 4 additions & 4 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState, useRef, useEffect, useCallback } from "react";
import axios from "axios";
import TinderCard from "react-tinder-card";
// @ts-ignore
import { Card, Button, Icon } from "konsta/react";
import { Button, Card, Icon } from "konsta/react";
import { useCallback, useEffect, useRef, useState } from "react";
import { MdOutlineThumbDown, MdOutlineThumbUp } from "react-icons/md";
import TinderCard from "react-tinder-card";

import api from "../api";
import utils from "../utils";
import useStore, { Image } from "../store";
import utils from "../utils";

export interface Element {
artworkLabel: { value: string };
Expand Down
3 changes: 2 additions & 1 deletion src/components/Start.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-ignore
import { Block } from "konsta/react";
import LogoIcon from "/logo_animated.svg";

import CollageIcon from "/collage.webp";
import LogoIcon from "/logo_animated.svg";

const Logo = () => {
return <img src={LogoIcon} alt="Logo GLAMorous Europe" className="w-160" />;
Expand Down
1 change: 1 addition & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router-dom";

import App from "./components/App.tsx";
import "./index.css";

Expand Down
8 changes: 4 additions & 4 deletions src/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import removeBackground, { Config } from "@imgly/background-removal";
/* import removeBackground, { Config } from "@imgly/background-removal";
const config: Config = {
model: "small",
progress: (key: unknown, current: unknown, total: unknown) => {
console.log(`Downloading ${key}: ${current} of ${total}`);
},
};
}; */

async function fetchIIIFIdentifier(
iiifManifest: string,
Expand Down Expand Up @@ -186,7 +186,7 @@ function getImageSelectionData(
}

export default {
bgRemoval: async (path: string) => {
/* bgRemoval: async (path: string) => {
const startTime = Date.now();
try {
const blob: Blob = await removeBackground(path, config);
Expand All @@ -199,7 +199,7 @@ export default {
console.error(error);
throw error;
}
},
}, */
fetchIIIFIdentifier: async (iiifManifest: string) => {
try {
return await fetchIIIFIdentifier(iiifManifest);
Expand Down

0 comments on commit 267e8c2

Please sign in to comment.