Skip to content

Commit

Permalink
Disable or enable pull to refresh when appropriate. Don't show ID whe…
Browse files Browse the repository at this point in the history
…n adding WL or WLI. Fix bug in isAdmin check() in lib.tsx & in data context.
  • Loading branch information
SegiH committed Jan 16, 2025
1 parent 693a53a commit 8ac34b2
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion public/build-info.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"buildDate": "2025-01-15T02:50:51.815Z"
"buildDate": "2025-01-16T04:26:01.501Z"
}
2 changes: 1 addition & 1 deletion public/sw.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/app/Admin/ManageUserAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ const ManageUserAccounts = () => {
if (res.data[0] === "OK") {
setUsers(res.data[1]);
} else {
alert(res.data[1])
setErrorMessage(res.data[1]);
setIsError(true);
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/Items/Dtl/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function WatchListItemsDtl() {
setErrorMessage,
setWatchListItemsLoadingStarted,
setWatchListItemsLoadingComplete,
pullToRefreshEnabled,
watchListTypes
} = useContext(DataContext) as DataContextType

Expand Down Expand Up @@ -82,6 +83,8 @@ export default function WatchListItemsDtl() {
setWatchListItemsLoadingComplete(false);
}

pullToRefreshEnabled(true);

if (isVisible("Items")) {
router.push("/Items");
} else {
Expand Down Expand Up @@ -411,7 +414,9 @@ ${typeof IMDB_JSON.totalSeasons !== "undefined" ? `Seasons: ${IMDB_JSON.totalSea
}
</div>

<div className="narrow card"><div>ID: {watchListItemDtl?.WatchListItemID}</div></div>
{!isAdding &&
<div className="narrow card"><div>ID: {watchListItemDtl?.WatchListItemID}</div></div>
}

<div className="narrow card rightAligned">
{!isAdding && !isEditing &&
Expand Down
7 changes: 6 additions & 1 deletion src/app/WatchList/Dtl/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function WatchListDetail() {
setWatchListLoadingComplete,
setWatchListSortingComplete,
showSearch,
pullToRefreshEnabled,
watchListItems,
watchListSortDirection,
watchListSources
Expand Down Expand Up @@ -178,6 +179,8 @@ export default function WatchListDetail() {
setWatchListSortingComplete(false);
}

pullToRefreshEnabled(true);

router.push("/WatchList");
};

Expand Down Expand Up @@ -707,7 +710,9 @@ ${typeof IMDB_JSON.totalSeasons !== "undefined" ? `Seasons: ${IMDB_JSON.totalSea
</div>

<div className="narrow card rightAligned">
<div>ID: {watchListDtl?.WatchListID}</div>
{!isAdding &&
<div>ID: {watchListDtl?.WatchListID}</div>
}

{!isAdding && !isEditing &&
<span className={`clickable closeButton ${!darkMode ? " lightMode" : "darkMode"}`} onClick={closeDetail}>
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const isUserAdmin = async (req: NextRequest) => {

if (typeof userSession === "undefined" || (typeof userSession !== "undefined" && userSession.Admin === 0)) {
return false;
} else if (userSession.Admin === 1) {
} else if (userSession.Admin === true) {
return true;
} else {
return false;
Expand Down
1 change: 0 additions & 1 deletion src/app/components/SearchIMDB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default function SearchIMDB() {
const router = useRouter();

const addIMDBSearchResultClickHandler = (index: number) => {
debugger
let itemType = 0; ``

if (imdbSearchResults[index].Type === "movie") {
Expand Down
3 changes: 3 additions & 0 deletions src/app/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Settings = () => {
hideTabs,
isLoggedIn,
LogOutIconComponent,
pullToRefreshEnabled,
setActiveRoute,
setActiveRouteDisplayName,
setArchivedVisible,
Expand Down Expand Up @@ -55,6 +56,8 @@ const Settings = () => {
}

const closeDetail = async () => {
pullToRefreshEnabled(true);

setSettingsVisible(false);
};

Expand Down
7 changes: 7 additions & 0 deletions src/app/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Tabs = () => {
isLoggedIn,
isLoggedInCheckComplete,
isVisible,
pullToRefreshEnabled,
routeList,
setActiveRoute,
setActiveRouteDisplayName,
Expand All @@ -34,6 +35,12 @@ const Tabs = () => {

const path = getPath(tabClicked.replace("/", ""));

if (tabClicked === "Admin") {
pullToRefreshEnabled(false);
} else {
pullToRefreshEnabled(true);
}

router.push(path);

const displayName = getDisplayName(tabClicked.replace("/", ""));
Expand Down
34 changes: 33 additions & 1 deletion src/app/data-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export interface DataContextType {
signOut: () => void;
sourceFilter: number;
stillWatching: boolean;
pullToRefreshEnabled: (value: boolean) => void;
typeFilter: number;
users: IUser[],
userData: IUserData;
Expand All @@ -183,6 +184,7 @@ export interface DataContextType {
watchListSourcesLoadingComplete: boolean;
watchListTypesLoadingComplete: boolean;
}

const DataContext = createContext({} as DataContextType);

const DataProvider = ({ children }) => {
Expand Down Expand Up @@ -350,11 +352,13 @@ const DataProvider = ({ children }) => {
axios.get(`/api/IsLoggedIn${params}`)
.then(async (res: AxiosResponse<IUser>) => {
if (res.data[0] === "OK") {
pullToRefreshEnabled(true);

const newUserData = Object.assign({}, userData);
newUserData.UserID = res.data[1].UserID;
newUserData.Username = res.data[1].Username;
newUserData.RealName = res.data[1].RealName;
newUserData.Admin = res.data[1].Admin === 1 ? true : false;
newUserData.Admin = res.data[1].Admin;

localStorage.setItem("WatchList.Token", res.data[1].Token);
localStorage.setItem("WatchList.TokenExpiration", res.data[1].TokenExpiration);
Expand All @@ -372,6 +376,8 @@ const DataProvider = ({ children }) => {

router.push("/WatchList");
} else {
pullToRefreshEnabled(false);

if (res.data[1] === false) {
setActiveRoute("Setup");
setActiveRouteDisplayName("Setup");
Expand Down Expand Up @@ -401,6 +407,9 @@ const DataProvider = ({ children }) => {
}

const openDetailClickHandler = useCallback((Id: number) => {
// Disable pull to refresh
pullToRefreshEnabled(false);

if (activeRoute === "WatchList" && Id !== null) {
if (Id === -1) {
setIsAdding(true);
Expand Down Expand Up @@ -459,6 +468,8 @@ const DataProvider = ({ children }) => {
};

const showSettings = () => {
pullToRefreshEnabled(false);

setSettingsVisible(true);
};

Expand Down Expand Up @@ -523,6 +534,14 @@ const DataProvider = ({ children }) => {
router.push("/Login");
}

const pullToRefreshEnabled = (enabled: boolean) => {
if (enabled) {
document.getElementsByTagName("html")[0].classList.remove("no-pull-to-refresh");
} else {
document.getElementsByTagName("html")[0].classList.add("no-pull-to-refresh");
}
}

const validatePassword = (value: string) => {
// 1 lowercase alphabetical character, 1 uppercase alphabetical character, 1 numeric, 1 special char, 8 chars long minimum
const strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})");
Expand Down Expand Up @@ -769,12 +788,16 @@ const DataProvider = ({ children }) => {
let newRoute = "";

if (!isLoggedIn) {
pullToRefreshEnabled(false);

if (activeRoute === "Setup" || activeRoute === "Login") {
newRoute = activeRoute;
} else {
newRoute = "Login";
}
} else {
pullToRefreshEnabled(true);

const currentPath = location.pathname !== "" ? location.pathname : "";

if (currentPath === routeList["Login"].Path && isLoggedIn) {
Expand Down Expand Up @@ -908,6 +931,14 @@ const DataProvider = ({ children }) => {
};
}, []);

useEffect(() => {
if (isAdding || isEditing) {
pullToRefreshEnabled(false);
} else {
pullToRefreshEnabled(true);
}
}, [isAdding, isEditing]);

const routeList = {
WatchList: {
Name: "WatchList",
Expand Down Expand Up @@ -1069,6 +1100,7 @@ const DataProvider = ({ children }) => {
signOut: signOut,
sourceFilter: sourceFilter,
stillWatching: stillWatching,
pullToRefreshEnabled: pullToRefreshEnabled,
typeFilter: typeFilter,
users: users,
userData: userData,
Expand Down
10 changes: 5 additions & 5 deletions src/app/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
}
}

html.no-pull-to-refresh {
overflow: hidden;
overscroll-behavior: none;
}

#multiselectContainerReact.lightMode .optionListContainer {
color: var(--light-mode-foregroundColor) !important;
background-color: var(--light-mode-backgroundColor) !important;
Expand Down Expand Up @@ -457,11 +462,6 @@ input:checked+.slider:before {
font-family: none !important;
}

.no-pull-to-refresh {
overflow: hidden;
overscroll-behavior: none;
}

.no-width {
width: unset;
}
Expand Down

0 comments on commit 8ac34b2

Please sign in to comment.