Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusef Almamari committed Aug 4, 2024
1 parent 6e88e3f commit c13b950
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 84 deletions.
118 changes: 75 additions & 43 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"react-dom": "^18.3.1",
"typescript": "^5.5.3",
"vite": "^5.3.4",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-pwa": "^0.20.0"
},
"overrides": {
Expand All @@ -82,8 +83,9 @@
"build": "vite build",
"serve": "vite preview",
"test": "jest",
"lint": "npx eslint .",
"lint": "eslint .",
"lint:fix": "npx eslint --fix .",
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css}\"",
"coverage": "npm test --coverage --watchAll --collectCoverageFrom='src/**/*.{js,ts,jsx,tsx}'"
},
"eslintConfig": {
Expand Down
21 changes: 19 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch, useSelector } from "react-redux";
import { doc, onSnapshot } from "firebase/firestore";
import Bibliography from "./pages/bibliography/Bibliography";
import Home from "./pages/home/Home";
import { loadFromIndexedDB as loadBibs, mergeWithCurrentBibs } from "./data/store/slices/bibsSlice";
import { deleteBib, loadFromIndexedDB as loadBibs, mergeWithCurrentBibs } from "./data/store/slices/bibsSlice";
import { loadFromIndexedDB as loadSettings } from "./data/store/slices/settingsSlice";
import Settings from "./pages/settings/Settings";
import BibliographySettings from "./pages/bibliography/BibliographySettings";
Expand All @@ -17,11 +17,13 @@ import Account from "./pages/account/Account";
import ForgotPassword from "./pages/account/ForgotPassword";
import firestoreDB from "./data/db/firebase/firebase";
import { useDynamicTitle } from "./hooks/hooks.tsx";
import { useToast } from "./context/ToastContext.tsx";

export default function App() {
const { data: bibliographies, loadedFromIndexedDB: bibsLoaded } = useSelector((state) => state.bibliographies); // WATCH: In some browsers, state.bibliographies may display [object Object] on subsequent renders in StrictMode
const { currentUser } = useAuth();
const dispatch = useDispatch();
const toast = useToast();
useDynamicTitle();

useEffect(() => {
Expand All @@ -35,7 +37,22 @@ export default function App() {
coBibsIds.forEach((id) => {
const unsubscribe = onSnapshot(doc(firestoreDB, "coBibs", id), (sDoc) => {
const parsedCoBib = JSON.parse(sDoc.data().bibliography);
dispatch(mergeWithCurrentBibs({ bibs: [parsedCoBib] }));
console.log(
currentUser.uid,
parsedCoBib.collab.collaborators,
parsedCoBib.collab.collaborators.some((co) => co.id === currentUser.uid)
);
if (!parsedCoBib.collab.collaborators.some((co) => co.id === currentUser.uid)) {
// remove the user from the bibliography if they were removed by admin
dispatch(deleteBib({ bibliographyId: parsedCoBib.id }));
toast.show({
message: `You were removed from \`${parsedCoBib.title}\` collaborative bibliography`,
icon: "group",
color: "red",
});
} else {
dispatch(mergeWithCurrentBibs({ bibs: [parsedCoBib] }));
}
});
return () => unsubscribe();
});
Expand Down
2 changes: 1 addition & 1 deletion src/assets/styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -28698,4 +28698,4 @@
"url": "http://creativecommons.org/licenses/by-sa/3.0/"
}
}
]
]
21 changes: 20 additions & 1 deletion src/components/ui/MaterialComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function List({ items = [], className, ...rest }) {
return <md-divider />;
}
return (
<md-list-item {...item} type="button" onClick={item.onClick} key={uid()}>
<md-list-item {...item} type="button" onClick={item?.onClick} key={uid()}>
{item?.start && <div slot="start">{item.start}</div>}
{item?.title && <div slot="headline">{item.title}</div>}
{item?.description && <div slot="supporting-text">{item.description}</div>}
Expand Down Expand Up @@ -195,3 +195,22 @@ export function ChipSet({ chips = [], removable = false, className, ...rest }) {
</md-chip-set>
);
}

export function EmptyPage({ icon = "error", title, message, actions = [] }) {
return (
<div className="flex h-full w-full items-center justify-center">
<div className="text-center">
<Icon style={{ color: "var(--md-sys-color-outline)" }} className="h-32 w-32 text-9xl" name={icon} />
{title && <h3>{title}</h3>}
{message && <p>{message}</p>}
{actions.length !== 0 && (
<div className="flex justify-center gap-2">
{actions.map((action) => {
return <FilledButton onClick={action[1]}>{action[0]}</FilledButton>;
})}
</div>
)}
</div>
</div>
);
}
9 changes: 7 additions & 2 deletions src/data/store/slices/settingsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PREBUILT_TAGS = [
{ label: "Discontinued", color: TAG_COLORS.GRAY, id: "builtin-discontinued" },
];

const initialState = { tags: PREBUILT_TAGS };
const initialState = { tags: PREBUILT_TAGS, tryingToJoinBib: null };

async function saveToIndexedDB(newState) {
const serializedState = JSON.stringify(newState);
Expand Down Expand Up @@ -88,6 +88,10 @@ const settingsSlice = createSlice({
saveToIndexedDB(newState);
return newState;
},
setTryingToJoinBib: (settings, action) => {
const newState = { ...settings, tryingToJoinBib: action.payload.bibId };
return newState;
},
resetAllSettings: () => {
saveToIndexedDB(initialState);
return initialState;
Expand All @@ -98,6 +102,7 @@ const settingsSlice = createSlice({
},
});

export const { replaceAllSettings, restoreDefaultTags, addTag, deleteTag, resetAllSettings } = settingsSlice.actions;
export const { replaceAllSettings, restoreDefaultTags, addTag, deleteTag, setTryingToJoinBib, resetAllSettings } =
settingsSlice.actions;

export default settingsSlice.reducer;
4 changes: 2 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
--md-sys-color-on-error-container: #410002;

--md-sys-color-background: #ffd60a;
--md-sys-color-surface: #fff8ef;
--md-sys-color-surface-bright: #ffffff;
--md-sys-color-surface: #fff8f0;
--md-sys-color-surface-bright: #fffdfa;
--md-sys-color-surface-dim: #e0d9cc;

--md-sys-color-surface-container-lowest: #ffffff;
Expand Down
Loading

0 comments on commit c13b950

Please sign in to comment.