Skip to content

Commit 134f32d

Browse files
authored
Additional cleanup for root and firebase package (#589)
* Clean up comments in index.tsx * Fix compilation errors * Minor clean-up * Add TODOs * Remove unused issue-states config * Clean up * Review TODOs
1 parent 733ea51 commit 134f32d

File tree

28 files changed

+48
-74
lines changed

28 files changed

+48
-74
lines changed

.github/issue-states.yml

-13
This file was deleted.

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# testing
55
**/coverage/
66

7-
# production
8-
**/build/
9-
107
# Firebase
118
.firebase
129
.firebaserc

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Igor Krupenja
3+
Copyright (c) 2022 Igor Krupenja
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Already have some document or spreadsheet with your hiking/climbing gear and wan
5757

5858
- Add unit tests for functionality that is ready.
5959
- Improve code structure and maintainability.
60+
- Streamlined and fully automated the deployment process.
6061

6162
## Changelog
6263

@@ -143,7 +144,6 @@ Please note that the development environment works completely fine on macOS and
143144
3. Go to `packages/web-app` and create `.env.development` and `.env.production` files with the variables from `firebaseConfig`. The file format should be like this:
144145

145146
```shell
146-
# Firebase
147147
REACT_APP_FIREBASE_API_KEY="..."
148148
REACT_APP_FIREBASE_AUTH_DOMAIN="..."
149149
REACT_APP_FIREBASE_DATABASE_URL="..."
@@ -152,8 +152,6 @@ REACT_APP_FIREBASE_STORAGE_BUCKET="..."
152152
REACT_APP_FIREBASE_MESSAGING_SENDER_ID="..."
153153
REACT_APP_FIREBASE_APP_ID="..."
154154
REACT_APP_FIREBASE_MEASUREMENT_ID="..."
155-
# GCP Cloud Storage root URL
156-
REACT_APP_GCP_STORAGE_URL="https://storage.googleapis.com/${REACT_APP_FIREBASE_STORAGE_BUCKET}"
157155
```
158156

159157
##### Caveats ⚠️
@@ -191,7 +189,6 @@ REACT_APP_GCP_STORAGE_URL="https://storage.googleapis.com/${REACT_APP_FIREBASE_S
191189

192190
```shell
193191
FIREBASE_PROJECT_ID="..."
194-
FIREBASE_TOKEN="..."
195192
```
196193

197194
Note: You can change additional settings like regions and Cloud Storage bucket name in [the `.env` file](packages/firebase/.env).

packages/firebase/.env

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Firebase functions - functions do to not use Firebase project region automatically
21
FIREBASE_FUNCTIONS_REGION="europe-west1"
32
GCP_STORAGE_BACKUPS_REGION="EU"
43
GCP_STORAGE_BACKUPS_BUCKET="zaino-backups"

packages/firebase/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# production
2+
**/build/
3+
14
# env
25
.env.development
36
.env.production

packages/firebase/.vscode/extensions.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"foxundermoon.shell-format",
44
"timonwong.shellcheck",
55
"dbaeumer.vscode-eslint",
6-
"esbenp.prettier-vscode"
6+
"esbenp.prettier-vscode",
7+
"chflick.firecode",
8+
"jsayol.firebase-explorer"
79
]
810
}

packages/web-app/.env

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
REACT_APP_GCP_STORAGE_URL="https://storage.googleapis.com/${REACT_APP_FIREBASE_STORAGE_BUCKET}"
12
# Disable opening a browser tab with app on dev server start
23
BROWSER=none

packages/web-app/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# production
2+
**/build/
3+
14
# env
25
.env.development
36
.env.test

packages/web-app/config/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ module.exports = function (webpackEnv) {
181181
},
182182
},
183183
{
184-
// make variables and mixins accessible in every SCSS file without explicit import
184+
// Igor: make variables and mixins accessible in every SCSS file without explicit import
185185
loader: 'sass-resources-loader',
186186
options: {
187187
resources: ['src/styles/base/_settings.scss', 'src/styles/base/_mixins.scss'],

packages/web-app/scripts/deploy.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/bash
22
# shellcheck disable=SC2046,SC2005,SC2002
33

4-
node scripts/build.js
5-
64
# Get variables from .env file
75
export $(echo $(cat .env."$1" | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)
6+
7+
node scripts/build.js
8+
89
gcloud config set project "$REACT_APP_FIREBASE_PROJECT_ID"
910
gsutil -m cp -r "src/images/copyrighted/*" gs://"$REACT_APP_FIREBASE_STORAGE_BUCKET"/
1011
gsutil -m acl set -R -a public-read gs://"$REACT_APP_FIREBASE_STORAGE_BUCKET"/

packages/web-app/src/components/Common/Selects/ColorSelect/ColorSelect.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { EditIcon } from '../../Icons/EditIcon';
77
import { SelectOption, SelectPopover } from '../SelectPopover';
88
import { colorSelectStyles } from './style';
99

10-
export type ColorSelectOption = {
10+
type ColorSelectOption = {
1111
value: ColorName;
1212
label: string;
1313
hexValue: string;

packages/web-app/src/components/Common/Selects/SelectPopover/style.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { StylesConfig } from 'react-select';
22
import { SelectOption } from '.';
3-
import { Color } from '../../../../constants/Colors';
43
import checkbox from '../../../../images/icons/check-mark.svg';
54
import styles from '../../../../styles/base/_export.scss';
65

@@ -66,13 +65,6 @@ export const commonSelectStyles: Partial<StylesConfig<SelectOption, boolean>> =
6665
}),
6766
};
6867

69-
export type OptionStyleArguments = {
70-
// for some reason react-select requires this key to be named "data", breaks otherwise
71-
data: Color;
72-
isFocused?: boolean;
73-
isSelected?: boolean;
74-
};
75-
7668
export const colorDot = (color = styles.lightGrey, marginLeft = '2.2rem') => ({
7769
alignItems: 'center',
7870
display: 'flex',

packages/web-app/src/components/Header/AccountDetails/AccountDetails.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const AccountDetails = () => {
1313
const { name, email, photoUrl } = useSelector((state: RootState) => state.user);
1414
const dispatch = useDispatch();
1515
const handleLogout = async () => {
16-
// TODO: Having Firebase Auth sign out here is a temporary workaround for #572
1716
await firebase.auth().signOut();
1817
dispatch(logout());
1918
};

packages/web-app/src/components/ItemModal/Modal/Modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ReactNode } from 'react';
1+
import { ReactNode } from 'react';
22
import ReactModal from 'react-modal';
33
import './style.scss';
44

packages/web-app/src/components/Labels/LabelForm/LabelForm.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ export const LabelForm = ({
9595
</Row>
9696
{nameError && <FormError className="label-form__input__error">{nameError}</FormError>}
9797
<Row className="label-form__buttons">
98+
{/* todo move to parent component */}
9899
<Button
99100
className="button--grey label-form__cancel"
100101
onClick={() => {
101102
toggleForm();
102-
// reset label name preview on typing if cancelling edit
103103
setLabelBadgeText(initialName);
104-
// also reset label badge preview color
105104
setLabelBadgeColor(initialColor);
106105
}}
107106
>

packages/web-app/src/components/Labels/NewLabel/NewLabel.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ type NewLabelProps = {
1616
export const NewLabel = ({ toggleForm }: NewLabelProps) => {
1717
const dispatch = useDispatch();
1818
const [colorName, setColorName] = useState(getRandomColor().name);
19-
const newLabel: Label = {
19+
const label: Label = {
2020
id: uuid(),
2121
name: '',
2222
colorName: colorName,
2323
itemUniqueCount: 0,
2424
itemTotalCount: 0,
2525
lastSortIndex: 0,
2626
};
27-
const [name, setName] = useState(newLabel.name);
27+
const [name, setName] = useState(label.name);
2828

2929
return (
3030
<div className="new-label__container">
@@ -33,7 +33,7 @@ export const NewLabel = ({ toggleForm }: NewLabelProps) => {
3333
</LabelBadge>
3434
<LabelForm
3535
className="new-label"
36-
label={newLabel}
36+
label={label}
3737
// lastSortIndex to keep newly-created label at the top of the list -- if sorting by name
3838
onSubmit={(label) => dispatch(addLabel({ ...label, lastSortIndex: 0 }))}
3939
toggleForm={toggleForm}

packages/web-app/src/components/pages/PrivacyPolicy/PrivacyPolicy.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const PrivacyPolicy = () => {
1212
} catch {
1313
console.warn(
1414
[
15-
'Privacy policy content not found. Please create a file named "PrivacyPolicyContent.tsx" ',
16-
'in the "src/components/pages/PrivacyPolicy" directory.',
15+
'Privacy policy content not found. Please create a file named "PrivacyPolicyContent.tsx"',
16+
' in the "src/components/pages/PrivacyPolicy" directory.',
1717
].join()
1818
);
1919
return {
@@ -27,7 +27,6 @@ export const PrivacyPolicy = () => {
2727
<p className="privacy-policy__title">Zaino</p>
2828
<BackLink />
2929
<PrivacyPolicyContent />
30-
3130
<BackLink className="back-link--large-margin" />
3231
</main>
3332
);

packages/web-app/src/constants/Colors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ColorName } from '@zaino/shared';
22
import styles from '../styles/base/_export.scss';
33

4-
// TODO: split into three files
4+
// TODO: split into three/two files?
55
export type Color = {
66
name: ColorName;
77
fancyName: string;

packages/web-app/src/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { asciiLogo } from './utils/asciiLogo';
1010

1111
firebase.auth().onAuthStateChanged(async (user) => {
1212
if (user) {
13-
// on log in
13+
// User is signed in
1414
const credential = await firebase.auth().getRedirectResult();
15-
// using store.dispatch as useDispatch cannot be used outside of functional components
15+
// Using store.dispatch as useDispatch cannot be used outside of functional components
1616
await store.dispatch(
1717
handleLoginRedirect({ user, isNew: credential.additionalUserInfo?.isNewUser })
1818
);
1919
await store.dispatch(loadUserData(user.uid));
2020
console.log(asciiLogo);
2121
}
2222

23-
// re-render on both login and logout
23+
// Re-render on both login and logout
2424
renderApp();
2525
});
2626

packages/web-app/src/state/collectionSettings.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export enum CollectionSortOption {
66
itemsLowest = 'Least items',
77
itemsUniqueHighest = 'Most unique items',
88
itemsUniqueLowest = 'Least unique items',
9-
// see comments in labels slice for saveSortOrder
109
lastSortOrder = 'Last sort order',
1110
}
1211

packages/web-app/src/state/selectors/items.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ const selectFilteredInventoryItems = createSelector(
3838
return a.name.toLowerCase() < b.name.toLowerCase() ? 1 : -1;
3939
case ItemSortOption.weightHighest:
4040
if (a.weight === '') {
41-
// sort empty weight items appear below 0g items
41+
// sort empty weight items to appear below 0g items
4242
return 1;
4343
} else {
4444
return a.weight < b.weight ? 1 : -1;
4545
}
4646
case ItemSortOption.weightLowest:
4747
if (b.weight === '') {
48-
// sort empty weight items appear above 0g items
48+
// sort empty weight items to appear above 0g items
4949
return 1;
5050
} else {
5151
return a.weight > b.weight ? 1 : -1;

packages/web-app/src/state/slices/categories.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const categoriesSlice = createSlice({
2828
state.push(category);
2929
});
3030
},
31-
// reset state action to be executed on logout
32-
resetCategoriesState: () => [],
31+
resetCategoriesState: () => initialState,
3332
},
3433
});
3534

packages/web-app/src/state/slices/dataLoader.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@ import { loadCategories } from './categories';
88
import { loadItems } from './items';
99
import { loadLabels } from './labels';
1010

11-
/**
12-
* Process Firestore data to get Items and Labels as used in the app.
13-
*
14-
* @param snapshots Two snapshots with item and label data from Firestore.
15-
*/
16-
const processData = (
11+
const processSnapshotData = (
1712
snapshots: firebase.firestore.QuerySnapshot<firebase.firestore.DocumentData>[]
1813
) => {
1914
return snapshots.map((collection) =>
2015
collection.docs.map((doc) => ({ id: doc.id, ...doc.data() }))
2116
) as [Item[], Label[], Category[]];
2217
};
2318

19+
// todo does it belong here?
2420
export const loadUserData = createAsyncThunk<void, string, { state: RootState }>(
2521
'dataLoader/loadUserData',
2622
async (uid, { dispatch }) => {
@@ -30,7 +26,7 @@ export const loadUserData = createAsyncThunk<void, string, { state: RootState }>
3026
db.collection(`users/${uid}/labels`).get(),
3127
db.collection(`users/${uid}/categories`).get(),
3228
]);
33-
const [items, labels, categories] = processData(snapshots);
29+
const [items, labels, categories] = processSnapshotData(snapshots);
3430

3531
batch(() => {
3632
dispatch(loadItems(items));
@@ -40,6 +36,7 @@ export const loadUserData = createAsyncThunk<void, string, { state: RootState }>
4036
}
4137
);
4238

39+
// todo does it belong here?
4340
export const loadDemoData = createAsyncThunk<void, string, { state: RootState }>(
4441
'dataLoader/loadDemoData',
4542
async (uid, { dispatch }) => {
@@ -48,7 +45,7 @@ export const loadDemoData = createAsyncThunk<void, string, { state: RootState }>
4845
db.collection(`users/${uid}/items`).where('isFromDemoData', '==', true).get(),
4946
db.collection(`users/${uid}/labels`).where('isFromDemoData', '==', true).get(),
5047
]);
51-
const [items, labels] = processData(snapshots);
48+
const [items, labels] = processSnapshotData(snapshots);
5249

5350
batch(() => {
5451
dispatch(loadItems(items));

packages/web-app/src/state/slices/items.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const itemsSlice = createSlice({
107107
1
108108
);
109109
});
110+
// todo reorder
110111
builder.addCase(batchUpdateItems.pending, (state, action) => {
111112
action.meta.arg.forEach((update) => {
112113
const index = state.findIndex((item) => item.id === update.id);
@@ -121,7 +122,7 @@ const itemsSlice = createSlice({
121122
);
122123
});
123124
});
124-
// TODO: possibly add rejected handling here, #78
125+
// TODO: add rejected handling here, #78
125126
},
126127
});
127128

packages/web-app/src/state/slices/itemsFilters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
22

3-
export type ItemFilters = {
3+
type ItemFilters = {
44
text: string;
55
categoryId?: string;
66
labels: string[];

packages/web-app/src/state/slices/labels.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export const batchDeleteLabels = createAsyncThunk<void, Label[], { state: RootSt
6161
}
6262
);
6363

64-
// separate variable to annotate type
6564
const initialState: Label[] = [];
6665

6766
const labelsSlice = createSlice({
@@ -135,7 +134,7 @@ const labelsSlice = createSlice({
135134
});
136135
},
137136
// reset action to be executed on logout
138-
resetLabelsState: () => [],
137+
resetLabelsState: () => initialState,
139138
},
140139
extraReducers: (builder) => {
141140
builder.addCase(addLabel.pending, (state, action) => {

0 commit comments

Comments
 (0)