chore: unify runDB calls
This commit is contained in:
parent
89e7345b8c
commit
d6e39fb07c
@ -151,11 +151,11 @@ siteLayout' overrideHeading widget = do
|
|||||||
|
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
|
||||||
|
muid <- maybeAuthPair
|
||||||
-- Lookup Favourites, Breadcrumbs, Headline, & Theme if possible
|
-- Lookup Favourites, Breadcrumbs, Headline, & Theme if possible
|
||||||
(favourites', (title, parents), nav', contentHeadline, mmsgs, maxFavouriteTerms, currentTheme) <- do
|
(favourites', (title, parents), nav', contentHeadline, mmsgs, maxFavouriteTerms, currentTheme, storedReasonAndToggleRoute) <- do
|
||||||
muid <- maybeAuthPair
|
|
||||||
|
|
||||||
(favCourses, breadcrumbs'', nav', contentHeadline, mmsgs) <- runDB $ do
|
(favCourses, breadcrumbs'', nav', contentHeadline, mmsgs, storedReasonAndToggleRoute) <- runDB $ do
|
||||||
favCourses'' <- withReaderT (projectBackend @SqlReadBackend) . E.select . E.from $ \(course `E.LeftOuterJoin` courseFavourite) -> do
|
favCourses'' <- withReaderT (projectBackend @SqlReadBackend) . E.select . E.from $ \(course `E.LeftOuterJoin` courseFavourite) -> do
|
||||||
E.on $ E.just (course E.^. CourseId) E.==. courseFavourite E.?. CourseFavouriteCourse
|
E.on $ E.just (course E.^. CourseId) E.==. courseFavourite E.?. CourseFavouriteCourse
|
||||||
E.&&. courseFavourite E.?. CourseFavouriteUser E.==. E.val (view _1 <$> muid)
|
E.&&. courseFavourite E.?. CourseFavouriteUser E.==. E.val (view _1 <$> muid)
|
||||||
@ -246,8 +246,12 @@ siteLayout' overrideHeading widget = do
|
|||||||
forM_ authTagPivots $
|
forM_ authTagPivots $
|
||||||
\authTag -> addMessageWidget Info $ msgModal [whamlet|_{MsgUnauthorizedDisabledTag authTag}|] (Left $ SomeRoute (AuthPredsR, catMaybes [(toPathPiece GetReferer, ) . toPathPiece <$> mcurrentRoute]))
|
\authTag -> addMessageWidget Info $ msgModal [whamlet|_{MsgUnauthorizedDisabledTag authTag}|] (Left $ SomeRoute (AuthPredsR, catMaybes [(toPathPiece GetReferer, ) . toPathPiece <$> mcurrentRoute]))
|
||||||
getMessages
|
getMessages
|
||||||
|
|
||||||
|
storedReasonAndToggleRoute <- case mcurrentRoute of
|
||||||
|
(Just (CourseR tid ssh csh _)) -> (, Just . SomeRoute $ CourseR tid ssh csh CFavouriteR) <$> storedFavouriteReason tid ssh csh muid
|
||||||
|
_otherwise -> pure (Nothing, Nothing)
|
||||||
|
|
||||||
return (favCourses, breadcrumbs'', nav', contentHeadline, mmsgs)
|
return (favCourses, breadcrumbs'', nav', contentHeadline, mmsgs, storedReasonAndToggleRoute)
|
||||||
|
|
||||||
return ( favCourses
|
return ( favCourses
|
||||||
, breadcrumbs''
|
, breadcrumbs''
|
||||||
@ -256,13 +260,11 @@ siteLayout' overrideHeading widget = do
|
|||||||
, mmsgs
|
, mmsgs
|
||||||
, maybe userDefaultMaxFavouriteTerms userMaxFavouriteTerms $ view _2 <$> muid
|
, maybe userDefaultMaxFavouriteTerms userMaxFavouriteTerms $ view _2 <$> muid
|
||||||
, maybe userDefaultTheme userTheme $ view _2 <$> muid
|
, maybe userDefaultTheme userTheme $ view _2 <$> muid
|
||||||
|
, storedReasonAndToggleRoute
|
||||||
)
|
)
|
||||||
|
|
||||||
muid <- maybeAuthPair
|
let (currentReason', maybeRoute) = storedReasonAndToggleRoute
|
||||||
(currentReason', maybeRoute) <- case mcurrentRoute of
|
currentReason = case currentReason' of
|
||||||
(Just (CourseR tid ssh csh _)) -> (, Just . SomeRoute $ CourseR tid ssh csh CFavouriteR) <$> runDB (storedFavouriteReason tid ssh csh muid)
|
|
||||||
_otherwise -> pure (Nothing, Nothing)
|
|
||||||
let currentReason = case currentReason' of
|
|
||||||
-- (reason, blacklist)
|
-- (reason, blacklist)
|
||||||
(Just (_reason, True)) -> Nothing
|
(Just (_reason, True)) -> Nothing
|
||||||
(Just (Just reason, False)) -> Just reason
|
(Just (Just reason, False)) -> Just reason
|
||||||
|
|||||||
Reference in New Issue
Block a user