Skip to content

Commit

Permalink
Fix table filters
Browse files Browse the repository at this point in the history
  • Loading branch information
k-ode committed Oct 21, 2024
1 parent bf54416 commit 7b25ff2
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 243 deletions.
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"mobx": "6.13.5",
"mobx-react": "9.1.1",
"mobx-state-tree": "6.0.1",
"mst-query": "4.0.1"
"mst-query": "4.0.2"
},
"devDependencies": {
"@types/react": "^18.2.79",
Expand Down
2 changes: 1 addition & 1 deletion examples/table-filters/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions examples/table-filters/package-lock.json

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

2 changes: 1 addition & 1 deletion examples/table-filters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"mobx": "6.13.5",
"mobx-react": "9.1.1",
"mobx-state-tree": "6.0.1",
"mst-query": "4.0.1",
"mst-query": "4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2"
Expand Down
74 changes: 36 additions & 38 deletions examples/table-filters/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
import { observer } from "mobx-react";
import { useQuery } from "mst-query";
import { useEffect } from "react";
import { Link, Outlet, useNavigate, useParams } from "react-router-dom";
import { useRootStore } from "../context";
import { CompanyModelType } from "../models/models";
import { observer } from 'mobx-react';
import { useQuery } from 'mst-query';
import { useEffect } from 'react';
import { Link, Outlet, useNavigate, useParams } from 'react-router-dom';
import { useRootStore } from '../context';
import { CompanyModelType } from '../models/models';

const Sidebar = observer(({ items }: { items: CompanyModelType[] }) => {
const { companyId } = useParams();
const navigate = useNavigate();
const { companyId } = useParams();
const navigate = useNavigate();

useEffect(() => {
if (!companyId && items.length) {
navigate(`/company/${items[0].id}`);
}
}, [companyId, items, navigate]);
useEffect(() => {
if (!companyId && items.length) {
navigate(`/company/${items[0].id}`);
}
}, [companyId, items, navigate]);

return (
<div>
{items.map((item: any) => (
<div key={item.id}>
<Link to={`company/${item.id}`}>{item.name}</Link>
return (
<div>
{items.map((item: any) => (
<div key={item.id}>
<Link to={`company/${item.id}`}>{item.name}</Link>
</div>
))}
</div>
))}
</div>
);
);
});

const MainScreen = observer(
({ companies }: { companies: CompanyModelType[] }) => {
const MainScreen = observer(({ companies }: { companies: CompanyModelType[] }) => {
return (
<div className="app-container">
<div className="app-sidebar">
<Sidebar items={companies} />
<div className="app-container">
<div className="app-sidebar">
<Sidebar items={companies} />
</div>
<div className="app-list">
<Outlet />
</div>
</div>
<div className="app-list">
<Outlet />
</div>
</div>
);
},
);
});

export const App = observer(() => {
const rootStore = useRootStore();
const { data } = useQuery(rootStore.baseQuery);
if (!data) {
return <div>Loading app...</div>;
}
return <MainScreen companies={data} />;
const rootStore = useRootStore();
const { data } = useQuery(rootStore.baseQuery);
if (!data) {
return <div>Loading app...</div>;
}
return <MainScreen companies={data} />;
});
Loading

0 comments on commit 7b25ff2

Please sign in to comment.