From d8ae6ecb047e2b4b479011be24d8c6293eaeb726 Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 20 May 2021 14:41:21 -0500 Subject: [PATCH] direct user to login on certain actions --- components/header.js | 20 ++++++++++++++------ components/item.js | 2 +- components/upvote.js | 22 ++++++++++++++-------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/components/header.js b/components/header.js index bd256319..fcc4941a 100644 --- a/components/header.js +++ b/components/header.js @@ -47,9 +47,13 @@ export default function Header () { recent - - post - + {session + ? ( + + post + + ) + : post} jobs @@ -84,9 +88,13 @@ export default function Header () { - - post - + {session + ? ( + + post + + ) + : post} jobs diff --git a/components/item.js b/components/item.js index 810ce5f8..349b7063 100644 --- a/components/item.js +++ b/components/item.js @@ -20,7 +20,7 @@ export default function Item ({ item, rank, children }) { {item.title} {item.url && - 5 ? null : 'nofollow'}> + = 10 ? null : 'nofollow'}> {item.url.replace(/(^https?:|^)\/\//, '')} } diff --git a/components/upvote.js b/components/upvote.js index 73f1632a..8b97d68f 100644 --- a/components/upvote.js +++ b/components/upvote.js @@ -2,8 +2,10 @@ import { LightningConsumer } from './lightning' import UpArrow from '../svgs/lightning-arrow.svg' import styles from './upvote.module.css' import { gql, useMutation } from '@apollo/client' +import { signIn, useSession } from 'next-auth/client' export default function UpVote ({ itemId, meSats, className }) { + const [session] = useSession() const [vote] = useMutation( gql` mutation vote($id: ID!, $sats: Int!) { @@ -39,15 +41,19 @@ export default function UpVote ({ itemId, meSats, className }) { ${className || ''} ${meSats ? (meSats > 1 ? styles.stimi : styles.voted) : ''}` } - onClick={async () => { - if (!itemId) return - const { error } = await vote({ variables: { id: itemId, sats: 1 } }) - if (error) { - throw new Error({ message: error.toString() }) - } + onClick={ + session + ? async () => { + if (!itemId) return + const { error } = await vote({ variables: { id: itemId, sats: 1 } }) + if (error) { + throw new Error({ message: error.toString() }) + } - strike() - }} + strike() + } + : signIn + } />} )