Skip to content

Commit ab20c5a

Browse files
committed
improve files organisation
1 parent a6227fd commit ab20c5a

29 files changed

+87
-74
lines changed

src/App.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
22

33
import { Home, Layout, List, ManageList } from './views';
44

5-
import { useAuth } from './api';
5+
import { useAuth, useShoppingListData, useShoppingLists } from '@api';
66

7-
import { useShoppingListData, useShoppingLists } from './api';
8-
9-
import { useStateWithStorage } from './utils';
7+
import { useStateWithStorage } from '@utils';
108

119
export function App() {
1210
/**

src/api/firebase.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from 'firebase/firestore';
1515
import { useEffect, useState } from 'react';
1616
import { db } from './config';
17-
import { getDaysBetweenDates, getFutureDate } from '../utils';
17+
import { getDaysBetweenDates, getFutureDate } from '@utils';
1818
import { calculateEstimate } from '@the-collab-lab/shopping-list-utils';
1919

2020
/**

src/api/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './firebase';
2-
export { useAuth } from './useAuth';
2+
export * from './useAuth';

src/components/NavBar/NavBar.jsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
2-
import NavBarContent from './NavBarContent';
2+
import { NavBarContent } from '@components';
33

4-
export function NavBar({ user, lists, listPath }) {
4+
const NavBar = ({ user, lists, listPath }) => {
55
const [isNavOpen, setIsNavOpen] = useState(false);
66

77
return (
@@ -78,4 +78,6 @@ export function NavBar({ user, lists, listPath }) {
7878
</nav>
7979
</>
8080
);
81-
}
81+
};
82+
83+
export default NavBar;

src/components/NavBar/NavBarContent.jsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { useTranslation } from 'react-i18next';
2-
import { SignOut } from '../../api/useAuth.jsx';
3-
import { NavigationLink } from './NavigationLink.jsx';
2+
import { SignOut } from '@api';
43
import { useNavigate } from 'react-router-dom';
5-
import { ButtonWithIcon } from '../ButtonWithIcon.jsx';
4+
import { ButtonWithIcon, NavigationLink } from '@components';
65

7-
export default function NavLinks({ listPath, lists, setIsNavOpen }) {
6+
const NavBarContent = ({ listPath, lists, setIsNavOpen }) => {
87
const navigate = useNavigate();
98
const { t } = useTranslation();
109

@@ -60,4 +59,6 @@ export default function NavLinks({ listPath, lists, setIsNavOpen }) {
6059
/>
6160
</>
6261
);
63-
}
62+
};
63+
64+
export default NavBarContent;

src/components/NavBar/NavigationLink.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NavLink } from 'react-router-dom';
22

3-
export function NavigationLink({ text, destination, handleClick, icon }) {
3+
const NavigationLink = ({ text, destination, handleClick, icon }) => {
44
return (
55
<NavLink
66
onClick={handleClick}
@@ -16,4 +16,6 @@ export function NavigationLink({ text, destination, handleClick, icon }) {
1616
{text}
1717
</NavLink>
1818
);
19-
}
19+
};
20+
21+
export default NavigationLink;

src/components/NavBar/index.js

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function ButtonWithIcon({ text, handleClick, icon }) {
1+
const ButtonWithIcon = ({ text, handleClick, icon }) => {
22
return (
33
<button
44
onClick={handleClick}
@@ -8,4 +8,6 @@ export function ButtonWithIcon({ text, handleClick, icon }) {
88
{text}
99
</button>
1010
);
11-
}
11+
};
12+
13+
export default ButtonWithIcon;

src/components/Confirm.jsx src/components/custom-components/Confirm.jsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useEffect, useRef } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
4-
import Loading from './Loading';
3+
import { Loading } from '@components';
54

65
const Confirm = ({ open, onClose, onConfirm, children, title, loading }) => {
76
const { t } = useTranslation();
File renamed without changes.

src/components/DeleteList.jsx src/components/home-components/DeleteList.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
22
import { useTranslation, Trans } from 'react-i18next';
3-
import { deleteList } from '../api/firebase';
4-
import Confirm from './Confirm';
3+
import { deleteList } from '@api';
4+
import { Confirm } from '@components';
55

66
const DeleteList = ({ user, email, listPath, listName, setListPath }) => {
77
const { t } = useTranslation();

src/components/ListForm.jsx src/components/home-components/ListForm.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { useState } from 'react';
2-
import { createList } from '../api';
2+
import { createList } from '@api';
33
import { useNavigate } from 'react-router-dom';
44
import { useTranslation } from 'react-i18next';
5-
import { inputHasValue } from '../utils/inputValidation';
6-
import { stringsHaveSameValue } from '../utils/inputValidation';
5+
import { stringsHaveSameValue, inputHasValue } from '@utils';
76

87
const ListForm = (props) => {
98
const { setMessage, setListPath, userId, userEmail, data } = props;

src/components/SingleList.jsx src/components/home-components/SingleList.jsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useNavigate } from 'react-router-dom';
2-
import DeleteList from './DeleteList';
2+
import { DeleteList } from '@components';
33

4-
export function SingleList({ userEmail, name, path, setListPath, userId }) {
4+
const SingleList = ({ userEmail, name, path, setListPath, userId }) => {
55
const navigate = useNavigate();
66
function handleClick() {
77
setListPath(path);
@@ -25,4 +25,6 @@ export function SingleList({ userEmail, name, path, setListPath, userId }) {
2525
/>
2626
</li>
2727
);
28-
}
28+
};
29+
30+
export default SingleList;

src/components/index.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
export * from './ListItem';
2-
export * from './SingleList';
3-
export * from './ContainerItems';
4-
export * from './SearchList';
5-
export * from './Loading';
6-
export * from './ButtonWithIcon';
7-
export * from './ErrorMessage';
8-
export * from './Message';
9-
export * from './DeleteList';
10-
export * from './Confirm';
11-
export * from './DeleteItem';
1+
export { default as Loading } from './loading/Loading';
2+
3+
export { default as ButtonWithIcon } from './custom-components/ButtonWithIcon';
4+
export { default as ErrorMessage } from './custom-components/ErrorMessage';
5+
export { default as Message } from './custom-components/Message';
6+
export { default as ListButtons } from './custom-components/ListButtons';
7+
export { default as Confirm } from './custom-components/Confirm';
8+
9+
export { default as DeleteItem } from './list-components/DeleteItem';
10+
export { default as ContainerItems } from './list-components/ContainerItems';
11+
export { default as SearchList } from './list-components/SearchList';
12+
export { default as ListItem } from './list-components/ListItem';
13+
14+
export { default as NavBar } from './navBar/NavBar';
15+
export { default as NavigationLink } from './navBar/NavigationLink';
16+
export { default as NavBarContent } from './navBar/NavBarContent';
17+
18+
export { default as DeleteList } from './home-components/DeleteList';
19+
export { default as SingleList } from './home-components/SingleList';
20+
export { default as ListForm } from './home-components/ListForm';

src/components/ContainerItems.jsx src/components/list-components/ContainerItems.jsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { useEffect, useState } from 'react';
2-
import { ListItem } from './ListItem';
3-
import { Fragment } from 'react';
1+
import { useEffect, useState, Fragment } from 'react';
2+
import { ListItem } from '@components';
43

5-
export const ContainerItems = ({
4+
const ContainerItems = ({
65
category,
76
newList,
87
wasRecentlyPurchased,
@@ -48,3 +47,5 @@ export const ContainerItems = ({
4847
<> </>
4948
);
5049
};
50+
51+
export default ContainerItems;

src/components/DeleteItem.jsx src/components/list-components/DeleteItem.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
22
import { useTranslation, Trans } from 'react-i18next';
3-
import { deleteItem } from '../api/firebase';
4-
import Confirm from './Confirm';
3+
import { deleteItem } from '@api';
4+
import { Confirm } from '@components';
55

66
const DeleteItem = ({ itemName, listPath, itemId }) => {
77
const { t } = useTranslation();

src/components/ListItem.jsx src/components/list-components/ListItem.jsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import DeleteItem from './DeleteItem';
1+
import { DeleteItem } from '@components';
22

3-
export function ListItem({
3+
const ListItem = ({
44
isRecentlyPurchased,
55
itemId,
66
listPath,
77
name,
88
updatePurchaseDate,
9-
}) {
9+
}) => {
1010
return (
1111
<div
1212
href="/"
@@ -51,4 +51,6 @@ export function ListItem({
5151
</li>
5252
</div>
5353
);
54-
}
54+
};
55+
56+
export default ListItem;

src/components/SearchList.jsx src/components/list-components/SearchList.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ export const SearchList = ({ data, setNewList }) => {
4747
);
4848
};
4949

50-
// export default SearchList;
50+
export default SearchList;
File renamed without changes.
File renamed without changes.

src/i18n.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const resources = {
177177
ButtonDeleteList: 'Supprimer {{listNameUppercase}}',
178178
ModalDeleteListTitle: 'Supprimer la liste {{listNameUppercase}}',
179179
ModalDeleteListConfirmSuppression:
180-
'Voulez-vous definitivement supprimer la liste {{listNameUppercase}} ?',
180+
'Voulez-vous définitivement supprimer la liste {{listNameUppercase}} ?',
181181
ModalDeleteListStopUsing:
182182
"Voulez-vouz arrêter d'utiliser la liste {{listNameUppercase}} ?",
183183
},

src/utils/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './dates';
22
export * from './hooks';
3+
export * from './inputValidation';

src/views/Home.jsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { SingleList } from '../components';
21
import { useState } from 'react';
32
import { useTranslation } from 'react-i18next';
4-
import ListForm from '../components/ListForm';
5-
import ErrorMessage from '../components/ErrorMessage';
3+
import { ErrorMessage, ListForm, SingleList } from '@components';
64

75
export function Home({ data, setListPath, userId, userEmail }) {
86
const { t } = useTranslation();

src/views/Layout.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Outlet } from 'react-router-dom';
22
import { useTranslation, Trans } from 'react-i18next';
3-
import { SignIn } from '../api/useAuth.jsx';
4-
import { NavBar } from '../components/NavBar/NavBar.jsx';
3+
import { SignIn } from '@api';
4+
import { NavBar, Loading } from '@components';
55
import Groceries from '../assets/groceries.png';
6-
import Loading from '../components/Loading.jsx';
76

87
export function Layout({ lists, listPath, user, isLoadingUser }) {
98
const { t } = useTranslation();

src/views/List.jsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import { useState, useEffect } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { ContainerItems } from '../components';
4-
import { SearchList } from '../components';
5-
import { useParams, useNavigate } from 'react-router-dom';
6-
import { updateItem, comparePurchaseUrgency } from '../api/firebase';
7-
import { isMoreThanADayAgo } from '../utils';
8-
import Loading from '../components/Loading';
9-
import ListButtons from '../components/ListButtons';
3+
import { ContainerItems, SearchList, Loading, ListButtons } from '@components';
4+
import { useParams } from 'react-router-dom';
5+
import { updateItem, comparePurchaseUrgency } from '@api';
6+
import { isMoreThanADayAgo } from '@utils';
107

118
export function List({ data, lists, listPath, isLoadingListData }) {
129
const [newList, setNewList] = useState([]);
1310
const [sortedList, setSortedList] = useState([]);
1411
const { path } = useParams();
15-
const navigate = useNavigate();
1612
const { t } = useTranslation();
1713

1814
const categoryArray = [

src/views/ManageList.jsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { useState } from 'react';
22
import { useTranslation, Trans } from 'react-i18next';
3-
import { addItem } from '../api/firebase';
4-
import { shareList } from '../api/firebase';
5-
import ErrorMessage from '../components/ErrorMessage';
6-
import Message from '../components/Message';
3+
import { addItem, shareList } from '@api';
4+
import { ErrorMessage, Message } from '@components';
75
import {
86
inputHasValue,
97
inputHasOnlyNUmbers,
108
stringsHaveSameValue,
11-
} from '../utils/inputValidation';
9+
} from '@utils';
1210

1311
export function ManageList({ data, listPath, userId, userEmail }) {
1412
const { t } = useTranslation();

vite.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import eslint from '@nabla/vite-plugin-eslint';
33
import react from '@vitejs/plugin-react';
44
import svgr from 'vite-plugin-svgr';
55
import { VitePWA } from 'vite-plugin-pwa';
6+
import path from 'path';
67

78
const PWAConfig = {
89
includeAssets: ['favicon.ico', 'robots.txt'],
@@ -57,6 +58,13 @@ export default defineConfig({
5758
},
5859
},
5960
},
61+
resolve: {
62+
alias: {
63+
'@components': path.resolve(__dirname, 'src/components'),
64+
'@api': path.resolve(__dirname, 'src/api'),
65+
'@utils': path.resolve(__dirname, 'src/utils'),
66+
},
67+
},
6068
optimizeDeps: { disabled: false },
6169
plugins: [
6270
eslint({ cache: false, formatter: 'stylish' }),

0 commit comments

Comments
 (0)