From 067b32826dd622b1127b586877717015e941ca94 Mon Sep 17 00:00:00 2001 From: Carl Tibule Date: Sun, 5 Mar 2023 18:34:25 -0600 Subject: [PATCH] Redirected Home page to Bookmarks list page when authenticated and login page when not Also modified to have 200 returned when only tags are changed and not the bookmark itself --- YABA.Service/BookmarkService.cs | 12 +++----- yaba-web/src/components/header.jsx | 4 +-- yaba-web/src/views/bookmarksListView.jsx | 2 +- yaba-web/src/views/homeView.jsx | 35 ++++++++++++++++-------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/YABA.Service/BookmarkService.cs b/YABA.Service/BookmarkService.cs index cb85dbe..4564122 100644 --- a/YABA.Service/BookmarkService.cs +++ b/YABA.Service/BookmarkService.cs @@ -113,14 +113,10 @@ namespace YABA.Service bookmark.Url = !string.IsNullOrEmpty(request.Url) ? request.Url : bookmark.Url; UpdateBookmarkWithMetaData(bookmark); - if (await _context.SaveChangesAsync() > 0) - { - var bookmarkDTO = _mapper.Map(bookmark); - bookmarkDTO.Tags = tags; - return bookmarkDTO; - } - - return null; + await _context.SaveChangesAsync(); + var bookmarkDTO = _mapper.Map(bookmark); + bookmarkDTO.Tags = tags; + return bookmarkDTO; } public async Task?> UpdateBookmarkTags(int id, IEnumerable tags) diff --git a/yaba-web/src/components/header.jsx b/yaba-web/src/components/header.jsx index c93a198..b5ff55c 100644 --- a/yaba-web/src/components/header.jsx +++ b/yaba-web/src/components/header.jsx @@ -11,7 +11,7 @@ export function Header(props) { const handleLogin = async () => { await loginWithRedirect({ appState: { - returnTo: "/", + returnTo: "/bookmarks", }, }); }; @@ -19,7 +19,7 @@ export function Header(props) { const handleSignUp = async () => { await loginWithRedirect({ appState: { - returnTo: "/", + returnTo: "/bookmarks", }, authorizationParams: { screen_hint: "signup", diff --git a/yaba-web/src/views/bookmarksListView.jsx b/yaba-web/src/views/bookmarksListView.jsx index 1cddf0a..3e97fe4 100644 --- a/yaba-web/src/views/bookmarksListView.jsx +++ b/yaba-web/src/views/bookmarksListView.jsx @@ -1,5 +1,5 @@ import React, { useEffect, useReducer, useState } from "react"; -import { Alert, Col, Container, Row, Button, Modal, Dropdown, DropdownButton } from "../components/external"; +import { Alert, Col, Container, Row, Button, Modal } from "../components/external"; import { Bookmark } from "../components"; import { useAuth0 } from "@auth0/auth0-react"; import { deleteBookmarks, getAllBookmarks, hideBookmarks } from "../api"; diff --git a/yaba-web/src/views/homeView.jsx b/yaba-web/src/views/homeView.jsx index 33e4ee1..ab3a079 100644 --- a/yaba-web/src/views/homeView.jsx +++ b/yaba-web/src/views/homeView.jsx @@ -1,20 +1,31 @@ -import React from "react"; +import React, { useEffect } from "react"; import Container from 'react-bootstrap/Container'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; +import { useAuth0 } from "@auth0/auth0-react"; +import { useNavigate } from "react-router-dom"; export function HomeView(props) { + const { isAuthenticated, loginWithRedirect } = useAuth0(); + const navigate = useNavigate(); + + const navigateToLogin = async () => { + await loginWithRedirect({ + appState: { + returnTo: "/bookmarks", + }, + }); + }; + + useEffect(() => { + if(isAuthenticated) { + navigate("/bookmarks"); + } else { + navigateToLogin(); + } + }, []); + return( - -
- - - -

This is the Home View

- -
-
-
-
+ <> ); } \ No newline at end of file