-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from wwsalmon/redirects
Redirects
- Loading branch information
Showing
10 changed files
with
133 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,62 @@ | ||
import { useTheme } from 'next-themes'; | ||
import Select from 'react-select' | ||
|
||
export default function CustomSelect(props) { | ||
const { theme, setTheme } = useTheme(); | ||
const customStyles = { | ||
option: (provided, state) => { | ||
const optionBackgroundColor = state.isSelected | ||
? 'rgb(38, 132, 255)' /* default */ | ||
: theme === 'dark' | ||
? '#000' | ||
: '#FFF'; | ||
|
||
return { | ||
...provided, | ||
padding: 8, | ||
paddingRight: 16, | ||
paddingLeft: 16, | ||
backgroundColor: optionBackgroundColor, | ||
|
||
':hover': { | ||
backgroundColor: state.isSelected | ||
? optionBackgroundColor | ||
: theme === 'dark' | ||
? 'rgba(243, 244, 246, 0.2)' | ||
: 'rgba(243, 244, 246, 1)', // tailwind gray 100, just like moremenu on hover | ||
}, | ||
}; | ||
}, | ||
|
||
valueContainer: provided => ({ | ||
export const getCustomStyles = (theme) => ({ | ||
option: (provided, state) => { | ||
const optionBackgroundColor = state.isSelected | ||
? 'rgb(38, 132, 255)' /* default */ | ||
: theme === 'dark' | ||
? '#000' | ||
: '#FFF'; | ||
|
||
return { | ||
...provided, | ||
padding: 8, | ||
paddingRight: 16, | ||
paddingLeft: 16, | ||
}), | ||
|
||
control: provided => ({ | ||
...provided, | ||
borderColor: '#e5e7eb', | ||
backgroundColor: theme === 'dark' ? 'rgba(0, 0, 0, 0)' : '#FFF', | ||
}), | ||
|
||
container: provided => ({ | ||
...provided, | ||
marginBottom: 8, | ||
}), | ||
backgroundColor: optionBackgroundColor, | ||
|
||
':hover': { | ||
backgroundColor: state.isSelected | ||
? optionBackgroundColor | ||
: theme === 'dark' | ||
? 'rgba(243, 244, 246, 0.2)' | ||
: 'rgba(243, 244, 246, 1)', // tailwind gray 100, just like moremenu on hover | ||
}, | ||
}; | ||
}, | ||
|
||
valueContainer: provided => ({ | ||
...provided, | ||
padding: 8, | ||
paddingRight: 16, | ||
paddingLeft: 16, | ||
}), | ||
|
||
control: provided => ({ | ||
...provided, | ||
borderColor: '#e5e7eb', | ||
backgroundColor: theme === 'dark' ? 'rgba(0, 0, 0, 0)' : '#FFF', | ||
}), | ||
|
||
container: provided => ({ | ||
...provided, | ||
marginBottom: 8, | ||
}), | ||
|
||
menu: provided => ({ | ||
...provided, | ||
backgroundColor: theme === 'dark' ? '#000' : '#FFF', | ||
}), | ||
|
||
singleValue: provided => ({ | ||
...provided, | ||
color: theme === 'dark' ? '#FFF' : '#000', | ||
}), | ||
}); | ||
|
||
menu: provided => ({ | ||
...provided, | ||
backgroundColor: theme === 'dark' ? '#000' : '#FFF', | ||
}), | ||
|
||
singleValue: provided => ({ | ||
...provided, | ||
color: theme === 'dark' ? '#FFF' : '#000', | ||
}), | ||
}; | ||
return <Select {...props} customStyles={customStyles} /> | ||
export default function CustomSelect(props) { | ||
const { theme, setTheme } = useTheme(); | ||
const customStyles = getCustomStyles(theme); | ||
return <Select {...props} customStyles={customStyles} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { GetServerSideProps } from "next"; | ||
import { getSession } from "next-auth/react"; | ||
import { userModel } from "../../models/models"; | ||
import getLookup from "../../utils/getLookup"; | ||
import { ssrRedirect } from "next-response-helpers"; | ||
|
||
export default function Random() { | ||
return ( | ||
<></> | ||
) | ||
} | ||
|
||
export const getServerSideProps: GetServerSideProps = async (context) => { | ||
if (Array.isArray(context.params.username) || context.params.username.substring(0, 1) !== "@") return { notFound: true }; | ||
|
||
const username: string = context.params.username.substring(1); | ||
|
||
const pageUserArr = await userModel.aggregate([ | ||
{$match: {urlName: username}}, | ||
getLookup("users", "_id", "following", "followingArr"), | ||
getLookup("users", "email", "followers", "followersArr"), | ||
{ | ||
$lookup: { | ||
from: "updates", | ||
as: "updatesArr", | ||
let: {userId: "$_id"}, | ||
pipeline: [ | ||
{$match: {$expr: {$eq: ["$userId", "$$userId"]}}}, | ||
{$sample: {size: 1}}, | ||
], | ||
} | ||
} | ||
]); | ||
|
||
const pageUser = pageUserArr[0]; | ||
|
||
console.log(pageUser); | ||
|
||
if (!pageUser) return {notFound: true}; | ||
|
||
const session = await getSession(context); | ||
const thisUser = session ? await userModel.findOne({email: session.user.email}) : null; | ||
|
||
const isPrivate = (pageUser.truePrivate || pageUser.private); | ||
|
||
const canAccess = (!isPrivate || (thisUser && ( | ||
// following user | ||
pageUser.followers.includes(thisUser.email) || | ||
// or are the user | ||
pageUser._id.toString() === thisUser._id.toString() | ||
))); | ||
|
||
if (!canAccess || !pageUser.updatesArr.length) return ssrRedirect(`/@${username}`); | ||
|
||
return ssrRedirect(`/@${username}/${pageUser.updatesArr[0].url}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5568be2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
updately – ./
updately-wwsalmon.vercel.app
updately-git-main-wwsalmon.vercel.app