Skip to content

Commit

Permalink
improve files organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
ocsiddisco committed Jun 16, 2024
1 parent a6227fd commit ab20c5a
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 74 deletions.
6 changes: 2 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';

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

import { useAuth } from './api';
import { useAuth, useShoppingListData, useShoppingLists } from '@api';

import { useShoppingListData, useShoppingLists } from './api';

import { useStateWithStorage } from './utils';
import { useStateWithStorage } from '@utils';

export function App() {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'firebase/firestore';
import { useEffect, useState } from 'react';
import { db } from './config';
import { getDaysBetweenDates, getFutureDate } from '../utils';
import { getDaysBetweenDates, getFutureDate } from '@utils';
import { calculateEstimate } from '@the-collab-lab/shopping-list-utils';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './firebase';
export { useAuth } from './useAuth';
export * from './useAuth';
8 changes: 5 additions & 3 deletions src/components/NavBar/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import NavBarContent from './NavBarContent';
import { NavBarContent } from '@components';

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

return (
Expand Down Expand Up @@ -78,4 +78,6 @@ export function NavBar({ user, lists, listPath }) {
</nav>
</>
);
}
};

export default NavBar;
11 changes: 6 additions & 5 deletions src/components/NavBar/NavBarContent.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useTranslation } from 'react-i18next';
import { SignOut } from '../../api/useAuth.jsx';
import { NavigationLink } from './NavigationLink.jsx';
import { SignOut } from '@api';
import { useNavigate } from 'react-router-dom';
import { ButtonWithIcon } from '../ButtonWithIcon.jsx';
import { ButtonWithIcon, NavigationLink } from '@components';

export default function NavLinks({ listPath, lists, setIsNavOpen }) {
const NavBarContent = ({ listPath, lists, setIsNavOpen }) => {
const navigate = useNavigate();
const { t } = useTranslation();

Expand Down Expand Up @@ -60,4 +59,6 @@ export default function NavLinks({ listPath, lists, setIsNavOpen }) {
/>
</>
);
}
};

export default NavBarContent;
6 changes: 4 additions & 2 deletions src/components/NavBar/NavigationLink.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NavLink } from 'react-router-dom';

export function NavigationLink({ text, destination, handleClick, icon }) {
const NavigationLink = ({ text, destination, handleClick, icon }) => {
return (
<NavLink
onClick={handleClick}
Expand All @@ -16,4 +16,6 @@ export function NavigationLink({ text, destination, handleClick, icon }) {
{text}
</NavLink>
);
}
};

export default NavigationLink;
4 changes: 0 additions & 4 deletions src/components/NavBar/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function ButtonWithIcon({ text, handleClick, icon }) {
const ButtonWithIcon = ({ text, handleClick, icon }) => {
return (
<button
onClick={handleClick}
Expand All @@ -8,4 +8,6 @@ export function ButtonWithIcon({ text, handleClick, icon }) {
{text}
</button>
);
}
};

export default ButtonWithIcon;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';

import Loading from './Loading';
import { Loading } from '@components';

const Confirm = ({ open, onClose, onConfirm, children, title, loading }) => {
const { t } = useTranslation();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';
import { deleteList } from '../api/firebase';
import Confirm from './Confirm';
import { deleteList } from '@api';
import { Confirm } from '@components';

const DeleteList = ({ user, email, listPath, listName, setListPath }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useState } from 'react';
import { createList } from '../api';
import { createList } from '@api';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { inputHasValue } from '../utils/inputValidation';
import { stringsHaveSameValue } from '../utils/inputValidation';
import { stringsHaveSameValue, inputHasValue } from '@utils';

const ListForm = (props) => {
const { setMessage, setListPath, userId, userEmail, data } = props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useNavigate } from 'react-router-dom';
import DeleteList from './DeleteList';
import { DeleteList } from '@components';

export function SingleList({ userEmail, name, path, setListPath, userId }) {
const SingleList = ({ userEmail, name, path, setListPath, userId }) => {
const navigate = useNavigate();
function handleClick() {
setListPath(path);
Expand All @@ -25,4 +25,6 @@ export function SingleList({ userEmail, name, path, setListPath, userId }) {
/>
</li>
);
}
};

export default SingleList;
31 changes: 20 additions & 11 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
export * from './ListItem';
export * from './SingleList';
export * from './ContainerItems';
export * from './SearchList';
export * from './Loading';
export * from './ButtonWithIcon';
export * from './ErrorMessage';
export * from './Message';
export * from './DeleteList';
export * from './Confirm';
export * from './DeleteItem';
export { default as Loading } from './loading/Loading';

export { default as ButtonWithIcon } from './custom-components/ButtonWithIcon';
export { default as ErrorMessage } from './custom-components/ErrorMessage';
export { default as Message } from './custom-components/Message';
export { default as ListButtons } from './custom-components/ListButtons';
export { default as Confirm } from './custom-components/Confirm';

export { default as DeleteItem } from './list-components/DeleteItem';
export { default as ContainerItems } from './list-components/ContainerItems';
export { default as SearchList } from './list-components/SearchList';
export { default as ListItem } from './list-components/ListItem';

export { default as NavBar } from './navBar/NavBar';
export { default as NavigationLink } from './navBar/NavigationLink';
export { default as NavBarContent } from './navBar/NavBarContent';

export { default as DeleteList } from './home-components/DeleteList';
export { default as SingleList } from './home-components/SingleList';
export { default as ListForm } from './home-components/ListForm';
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect, useState } from 'react';
import { ListItem } from './ListItem';
import { Fragment } from 'react';
import { useEffect, useState, Fragment } from 'react';
import { ListItem } from '@components';

export const ContainerItems = ({
const ContainerItems = ({
category,
newList,
wasRecentlyPurchased,
Expand Down Expand Up @@ -48,3 +47,5 @@ export const ContainerItems = ({
<> </>
);
};

export default ContainerItems;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';
import { deleteItem } from '../api/firebase';
import Confirm from './Confirm';
import { deleteItem } from '@api';
import { Confirm } from '@components';

const DeleteItem = ({ itemName, listPath, itemId }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import DeleteItem from './DeleteItem';
import { DeleteItem } from '@components';

export function ListItem({
const ListItem = ({
isRecentlyPurchased,
itemId,
listPath,
name,
updatePurchaseDate,
}) {
}) => {
return (
<div
href="/"
Expand Down Expand Up @@ -51,4 +51,6 @@ export function ListItem({
</li>
</div>
);
}
};

export default ListItem;
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ export const SearchList = ({ data, setNewList }) => {
);
};

// export default SearchList;
export default SearchList;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const resources = {
ButtonDeleteList: 'Supprimer {{listNameUppercase}}',
ModalDeleteListTitle: 'Supprimer la liste {{listNameUppercase}}',
ModalDeleteListConfirmSuppression:
'Voulez-vous definitivement supprimer la liste {{listNameUppercase}} ?',
'Voulez-vous définitivement supprimer la liste {{listNameUppercase}} ?',
ModalDeleteListStopUsing:
"Voulez-vouz arrêter d'utiliser la liste {{listNameUppercase}} ?",
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './dates';
export * from './hooks';
export * from './inputValidation';
4 changes: 1 addition & 3 deletions src/views/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { SingleList } from '../components';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import ListForm from '../components/ListForm';
import ErrorMessage from '../components/ErrorMessage';
import { ErrorMessage, ListForm, SingleList } from '@components';

export function Home({ data, setListPath, userId, userEmail }) {
const { t } = useTranslation();
Expand Down
5 changes: 2 additions & 3 deletions src/views/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Outlet } from 'react-router-dom';
import { useTranslation, Trans } from 'react-i18next';
import { SignIn } from '../api/useAuth.jsx';
import { NavBar } from '../components/NavBar/NavBar.jsx';
import { SignIn } from '@api';
import { NavBar, Loading } from '@components';
import Groceries from '../assets/groceries.png';
import Loading from '../components/Loading.jsx';

export function Layout({ lists, listPath, user, isLoadingUser }) {
const { t } = useTranslation();
Expand Down
12 changes: 4 additions & 8 deletions src/views/List.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { ContainerItems } from '../components';
import { SearchList } from '../components';
import { useParams, useNavigate } from 'react-router-dom';
import { updateItem, comparePurchaseUrgency } from '../api/firebase';
import { isMoreThanADayAgo } from '../utils';
import Loading from '../components/Loading';
import ListButtons from '../components/ListButtons';
import { ContainerItems, SearchList, Loading, ListButtons } from '@components';
import { useParams } from 'react-router-dom';
import { updateItem, comparePurchaseUrgency } from '@api';
import { isMoreThanADayAgo } from '@utils';

export function List({ data, lists, listPath, isLoadingListData }) {
const [newList, setNewList] = useState([]);
const [sortedList, setSortedList] = useState([]);
const { path } = useParams();
const navigate = useNavigate();
const { t } = useTranslation();

const categoryArray = [
Expand Down
8 changes: 3 additions & 5 deletions src/views/ManageList.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';
import { addItem } from '../api/firebase';
import { shareList } from '../api/firebase';
import ErrorMessage from '../components/ErrorMessage';
import Message from '../components/Message';
import { addItem, shareList } from '@api';
import { ErrorMessage, Message } from '@components';
import {
inputHasValue,
inputHasOnlyNUmbers,
stringsHaveSameValue,
} from '../utils/inputValidation';
} from '@utils';

export function ManageList({ data, listPath, userId, userEmail }) {
const { t } = useTranslation();
Expand Down
8 changes: 8 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import eslint from '@nabla/vite-plugin-eslint';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import { VitePWA } from 'vite-plugin-pwa';
import path from 'path';

const PWAConfig = {
includeAssets: ['favicon.ico', 'robots.txt'],
Expand Down Expand Up @@ -57,6 +58,13 @@ export default defineConfig({
},
},
},
resolve: {
alias: {
'@components': path.resolve(__dirname, 'src/components'),
'@api': path.resolve(__dirname, 'src/api'),
'@utils': path.resolve(__dirname, 'src/utils'),
},
},
optimizeDeps: { disabled: false },
plugins: [
eslint({ cache: false, formatter: 'stylish' }),
Expand Down

0 comments on commit ab20c5a

Please sign in to comment.