Skip to content

Commit

Permalink
sql file linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Moebits committed Aug 30, 2024
1 parent 3d4dfc3 commit 7980fe3
Show file tree
Hide file tree
Showing 18 changed files with 420 additions and 217 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ COOKIE_SECRET=
EMAIL_ADDRESS=
EMAIL_PASSWORD=

#Local Folders
MOEPICTURES_LOCAL=
MOEPICTURES_LOCAL_UNVERIFIED=

#Database
PG_HOST=
PG_USER=
Expand All @@ -25,6 +29,4 @@ SAUCENAO_KEY=
PIXIV_TOKEN=
DEVIANTART_CLIENT_ID=
DEVIANTART_CLIENT_SECRET=
CAPTCHA_SECRET=
CAPTCHA_SITEKEY=
WDTAGGER_PATH=
12 changes: 12 additions & 0 deletions Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export const ShowBulkQuickEditDialogContext = React.createContext<any>(null)
export const ShowTakedownPostDialogContext = React.createContext<any>(null)
export const TakedownTagContext = React.createContext<any>(null)
export const ImageExpandContext = React.createContext<any>(null)
export const CommentIDContext = React.createContext<any>(null)
export const CommentJumpFlagContext = React.createContext<any>(null)
export const DMTargetContext = React.createContext<any>(null)

const Context: React.FunctionComponent = (props) => {
const [siteHue, setSiteHue] = useState(180)
Expand Down Expand Up @@ -286,9 +289,15 @@ const Context: React.FunctionComponent = (props) => {
const [selectionPosts, setSelectionPosts] = useState(new Map())
const [showBulkQuickEditDialog, setShowBulkQuickEditDialog] = useState(false)
const [imageExpand, setImageExpand] = useState(false)
const [dmTarget, setDMTarget] = useState(null)
const [commentID, setCommentID] = useState(0)
const [commentJumpFlag, setCommentJumpFlag] = useState(false)

return (
<>
<CommentJumpFlagContext.Provider value={{commentJumpFlag, setCommentJumpFlag}}>
<CommentIDContext.Provider value={{commentID, setCommentID}}>
<DMTargetContext.Provider value={{dmTarget, setDMTarget}}>
<ImageExpandContext.Provider value={{imageExpand, setImageExpand}}>
<TakedownTagContext.Provider value={{takedownTag, setTakedownTag}}>
<ShowTakedownPostDialogContext.Provider value={{showTakedownPostDialog, setShowTakedownPostDialog}}>
Expand Down Expand Up @@ -558,6 +567,9 @@ return (
</ShowTakedownPostDialogContext.Provider>
</TakedownTagContext.Provider>
</ImageExpandContext.Provider>
</DMTargetContext.Provider>
</CommentIDContext.Provider>
</CommentJumpFlagContext.Provider>
</>
)
}
Expand Down
Binary file added assets/icons/dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion components/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ const Comment: React.FunctionComponent<Props> = (props) => {
return <span className="comment-user-text">{functions.toProperCase(props.comment.username)}</span>
}

const commentJump = () => {
props.onCommentJump?.(Number(props.comment.commentID))
}

return (
<div className="comment" comment-id={props.comment.commentID}>
<div className="comment-container">
Expand All @@ -215,7 +219,7 @@ const Comment: React.FunctionComponent<Props> = (props) => {
</div>
</div>
<div className="comment-container" style={{width: "100%"}}>
<span className="comment-date-text">{functions.timeAgo(props.comment.postDate)}:</span>
<span className="comment-date-text" onClick={commentJump}>{functions.timeAgo(props.comment.postDate)}:</span>
{parseText()}
</div>
{session.username ? commentOptions() : null}
Expand Down
12 changes: 10 additions & 2 deletions components/CommentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useHistory} from "react-router-dom"
import {ThemeContext, QuoteTextContext, SessionContext, DeleteCommentIDContext, DeleteCommentFlagContext, MobileContext,
EditCommentFlagContext, EditCommentIDContext, EditCommentTextContext, ReportCommentIDContext, BrightnessContext, ContrastContext,
HueContext, SaturationContext, LightnessContext, BlurContext, SharpenContext, PixelateContext, SiteHueContext, SiteLightnessContext,
SiteSaturationContext} from "../Context"
SiteSaturationContext, CommentIDContext, CommentJumpFlagContext} from "../Context"
import {HashLink as Link} from "react-router-hash-link"
import functions from "../structures/Functions"
import cryptoFunctions from "../structures/CryptoFunctions"
Expand Down Expand Up @@ -46,6 +46,8 @@ const CommentRow: React.FunctionComponent<Props> = (props) => {
const {editCommentID, setEditCommentID} = useContext(EditCommentIDContext)
const {editCommentText, setEditCommentText} = useContext(EditCommentTextContext)
const {reportCommentID, setReportCommentID} = useContext(ReportCommentIDContext)
const {commentID, setCommentID} = useContext(CommentIDContext)
const {commentJumpFlag, setCommentJumpFlag} = useContext(CommentJumpFlagContext)
const [hover, setHover] = useState(false)
const history = useHistory()
const initialImg = functions.getThumbnailLink(props.comment.post.images[0].type, props.comment.postID, props.comment.post.images[0].order, props.comment.post.images[0].filename, "tiny")
Expand Down Expand Up @@ -265,6 +267,12 @@ const CommentRow: React.FunctionComponent<Props> = (props) => {
}
}

const commentJump = () => {
setCommentID(Number(props.comment.commentID))
setCommentJumpFlag(true)
history.push(`/post/${props.comment.postID}?comment=${props.comment.commentID}`)
}

useEffect(() => {
loadImage()
}, [img, brightness, contrast, hue, saturation, lightness, blur, sharpen, pixelate])
Expand All @@ -285,7 +293,7 @@ const CommentRow: React.FunctionComponent<Props> = (props) => {
</div>
</div>
<div className="commentrow-container" style={{width: "100%"}}>
<span className="commentrow-date-text">{functions.timeAgo(props.comment.postDate)}:</span>
<span className="commentrow-date-text" onClick={commentJump}>{functions.timeAgo(props.comment.postDate)}:</span>
{parseText()}
</div>
</div>
Expand Down
15 changes: 10 additions & 5 deletions components/Comments.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useContext, useEffect, useRef, useState} from "react"
import {useHistory} from "react-router-dom"
import {ThemeContext, EnableDragContext, SessionContext, QuoteTextContext} from "../Context"
import {ThemeContext, EnableDragContext, SessionContext, QuoteTextContext, CommentIDContext, CommentJumpFlagContext} from "../Context"
import functions from "../structures/Functions"
import Comment from "./Comment"
import axios from "axios"
Expand All @@ -19,15 +19,16 @@ const Comments: React.FunctionComponent<Props> = (props) => {
const [error, setError] = useState(false)
const [comments, setComments] = useState([]) as any
const [commentFlag, setCommentFlag] = useState(false)
const [commentID, setCommentID] = useState(0)
const [commentJumpFlag, setCommentJumpFlag] = useState(false)
const {commentID, setCommentID} = useContext(CommentIDContext)
const {commentJumpFlag, setCommentJumpFlag} = useContext(CommentJumpFlagContext)
const errorRef = useRef(null) as any
const history = useHistory()

useEffect(() => {
const commentParam = new URLSearchParams(window.location.search).get("comment")
const onDOMLoaded = async () => {
if (commentParam) {
await functions.timeout(500)
setCommentID(Number(commentParam))
setCommentJumpFlag(true)
}
Expand All @@ -45,8 +46,12 @@ const Comments: React.FunctionComponent<Props> = (props) => {
}
}, [comments, commentJumpFlag, commentID])

const onCommentJump = (commentID: number) => {
const element = document.querySelector(`[comment-id="${commentID}"]`)
const onCommentJump = async (commentID: number) => {
let element = document.querySelector(`[comment-id="${commentID}"]`)
if (!element) {
await functions.timeout(1000)
element = document.querySelector(`[comment-id="${commentID}"]`)
}
if (!element) return
const position = element.getBoundingClientRect()
const elementTop = position.top + window.scrollY
Expand Down
1 change: 0 additions & 1 deletion components/CutenessMeter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ const CutenessMeter: React.FunctionComponent<Props> = (props) => {
}

const getCutenessValue = () => {
console.log(cuteness)
if (isAverage) return averageCuteness
return cuteness
}
Expand Down
4 changes: 4 additions & 0 deletions components/styles/comment.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
font-family: Tahoma, sans-serif;
font-size: 18px;
color: var(--text-strong);
cursor: pointer;
&:hover {
filter: brightness(130%);
}
}

.comment-text {
Expand Down
4 changes: 4 additions & 0 deletions components/styles/commentrow.less
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
font-family: Tahoma, sans-serif;
font-size: 18px;
color: var(--text-strong);
cursor: pointer;
&:hover {
filter: brightness(130%);
}
}

.commentrow-text {
Expand Down
94 changes: 94 additions & 0 deletions dialogs/DMDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, {useEffect, useContext, useState, useRef} from "react"
import {useHistory} from "react-router-dom"
import {HashLink as Link} from "react-router-hash-link"
import {HideNavbarContext, HideSidebarContext, ThemeContext, EnableDragContext, DMTargetContext, HideTitlebarContext} from "../Context"
import functions from "../structures/Functions"
import "./styles/dialog.less"
import Draggable from "react-draggable"
import axios from "axios"

const DMDialog: React.FunctionComponent = (props) => {
const {theme, setTheme} = useContext(ThemeContext)
const {hideNavbar, setHideNavbar} = useContext(HideNavbarContext)
const {hideTitlebar, setHideTitlebar} = useContext(HideTitlebarContext)
const {hideSidebar, setHideSidebar} = useContext(HideSidebarContext)
const {enableDrag, setEnableDrag} = useContext(EnableDragContext)
const {dmTarget, setDMTarget} = useContext(DMTargetContext)
const [title, setTitle] = useState("")
const [content, setContent] = useState("")
const [error, setError] = useState(false)
const errorRef = useRef<any>(null)
const history = useHistory()

useEffect(() => {
document.title = "Send Message"
}, [])

useEffect(() => {
if (dmTarget) {
// document.body.style.overflowY = "hidden"
document.body.style.pointerEvents = "none"
} else {
// document.body.style.overflowY = "visible"
document.body.style.pointerEvents = "all"
setEnableDrag(true)
}
}, [dmTarget])

const sendMessage = async () => {
try {
const messageID = await axios.post("/api/message/create", {title, content, recipient: dmTarget}, {headers: {"x-csrf-token": functions.getCSRFToken()}, withCredentials: true})
setDMTarget(null)
console.log(messageID)
// history.go(0)
} catch {
setError(true)
if (!errorRef.current) await functions.timeout(20)
errorRef.current!.innerText = "Bad title or content."
await functions.timeout(2000)
setError(false)
}
}

const click = (button: "accept" | "reject") => {
if (button === "accept") {
sendMessage()
} else {
setDMTarget(null)
}
}

if (dmTarget) {
return (
<div className="dialog">
<Draggable handle=".dialog-title-container">
<div className="dialog-box" style={{width: "500px", height: "420px"}} onMouseEnter={() => setEnableDrag(false)} onMouseLeave={() => setEnableDrag(true)}>
<div className="dialog-container">
<div className="dialog-title-container">
<span className="dialog-title">Send Message</span>
</div>
<div className="dialog-row">
<span className="dialog-text">Title: </span>
<input className="dialog-input-taller" type="text" spellCheck={false} value={title} onChange={(event) => setTitle(event.target.value)}/>
</div>
<div className="dialog-row">
<span className="dialog-text">Content: </span>
</div>
<div className="dialog-row">
<textarea className="dialog-textarea" style={{height: "200px"}} spellCheck={false} value={content} onChange={(event) => setContent(event.target.value)}></textarea>
</div>
{error ? <div className="dialog-validation-container"><span className="dialog-validation" ref={errorRef}></span></div> : null}
<div className="dialog-row">
<button onClick={() => click("reject")} className="dialog-button">{"Cancel"}</button>
<button onClick={() => click("accept")} className="dialog-button">{"Send"}</button>
</div>
</div>
</div>
</Draggable>
</div>
)
}
return null
}

export default DMDialog
1 change: 0 additions & 1 deletion dialogs/styles/dialog.less
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
width: 100%;
font-family: Tahoma, sans-serif;
color: var(--text);
margin-left: 10px;
height: 120px;
resize: none;
font-size: 17px;
Expand Down
14 changes: 9 additions & 5 deletions pages/CommentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ReportCommentDialog from "../dialogs/ReportCommentDialog"
import {ThemeContext, EnableDragContext, HideNavbarContext, HideSidebarContext, MobileContext, SessionContext,
RelativeContext, HideTitlebarContext, ActiveDropdownContext, HeaderTextContext, SidebarTextContext,
CommentSearchFlagContext, SiteHueContext, SiteLightnessContext, SiteSaturationContext, ScrollContext, CommentsPageContext,
PageFlagContext, ShowPageDialogContext} from "../Context"
PageFlagContext, ShowPageDialogContext, CommentIDContext, CommentJumpFlagContext} from "../Context"
import permissions from "../structures/Permissions"
import scrollIcon from "../assets/icons/scroll.png"
import pageIcon from "../assets/icons/page.png"
Expand Down Expand Up @@ -54,8 +54,8 @@ const CommentsPage: React.FunctionComponent = (props) => {
const [ended, setEnded] = useState(false)
const [getSearchIconHover, setSearchIconHover] = useState(false)
const [queryPage, setQueryPage] = useState(1)
const [commentID, setCommentID] = useState(0)
const [commentJumpFlag, setCommentJumpFlag] = useState(false)
const {commentID, setCommentID} = useContext(CommentIDContext)
const {commentJumpFlag, setCommentJumpFlag} = useContext(CommentJumpFlagContext)
const sortRef = useRef(null) as any
const history = useHistory()

Expand Down Expand Up @@ -268,7 +268,7 @@ const CommentsPage: React.FunctionComponent = (props) => {
}
}, [scroll, searchQuery, commentsPage, commentID])

const onCommentJump = (commentID: number) => {
const onCommentJump = async (commentID: number) => {
let index = -1
for (let i = 0; i < comments.length; i++) {
if (comments[i].commentID === String(commentID)) {
Expand All @@ -279,7 +279,11 @@ const CommentsPage: React.FunctionComponent = (props) => {
if (index > -1) {
const pageNumber = Math.ceil(index / getPageAmount())
goToPage(pageNumber, true)
const element = document.querySelector(`[comment-id="${commentID}"]`)
let element = document.querySelector(`[comment-id="${commentID}"]`)
if (!element) {
await functions.timeout(500)
element = document.querySelector(`[comment-id="${commentID}"]`)
}
if (!element) return
const position = element.getBoundingClientRect()
const elementTop = position.top + window.scrollY
Expand Down
11 changes: 10 additions & 1 deletion pages/UserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Footer from "../components/Footer"
import DragAndDrop from "../components/DragAndDrop"
import {HideNavbarContext, HideSidebarContext, ThemeContext, EnableDragContext, RelativeContext, HideTitlebarContext, MobileContext, CommentSearchFlagContext,
HeaderTextContext, SidebarTextContext, SessionContext, RedirectContext, SessionFlagContext, ShowDeleteAccountDialogContext, SiteHueContext, SiteLightnessContext,
SiteSaturationContext, BanNameContext, UnbanNameContext, UpdateUserFlagContext} from "../Context"
SiteSaturationContext, BanNameContext, UnbanNameContext, UpdateUserFlagContext, DMTargetContext} from "../Context"
import functions from "../structures/Functions"
import permissions from "../structures/Permissions"
import Carousel from "../components/Carousel"
Expand All @@ -18,7 +18,9 @@ import adminLabel from "../assets/icons/admin-label.png"
import modLabel from "../assets/icons/mod-label.png"
import banIcon from "../assets/icons/ban.png"
import unbanIcon from "../assets/icons/unban.png"
import dmIcon from "../assets/icons/dm.png"
import BanDialog from "../dialogs/BanDialog"
import DMDialog from "../dialogs/DMDialog"
import UnbanDialog from "../dialogs/UnbanDialog"
import "./styles/userpage.less"
import axios from "axios"
Expand Down Expand Up @@ -49,6 +51,7 @@ const UserPage: React.FunctionComponent<Props> = (props) => {
const {commentSearchFlag, setCommentSearchFlag} = useContext(CommentSearchFlagContext)
const {banName, setBanName} = useContext(BanNameContext)
const {unbanName, setUnbanName} = useContext(UnbanNameContext)
const {dmTarget, setDMTarget} = useContext(DMTargetContext)
const [uploadIndex, setUploadIndex] = useState(0)
const [favoriteIndex, setFavoriteIndex] = useState(0) as any
const [uploads, setUploads] = useState([]) as any
Expand Down Expand Up @@ -205,6 +208,10 @@ const UserPage: React.FunctionComponent<Props> = (props) => {
}
}

const dmDialog = () => {
setDMTarget(username)
}

useEffect(() => {
if (updateUserFlag) {
fetchUser()
Expand All @@ -215,6 +222,7 @@ const UserPage: React.FunctionComponent<Props> = (props) => {
return (
<>
<DragAndDrop/>
<DMDialog/>
<BanDialog/>
<UnbanDialog/>
<TitleBar/>
Expand All @@ -227,6 +235,7 @@ const UserPage: React.FunctionComponent<Props> = (props) => {
<div className="user-top-container">
<img className="user-img" src={getUserImg()} onClick={userImgClick} onAuxClick={userImgClick} style={{filter: defaultIcon ? getFilter() : ""}}/>
{generateUsernameJSX()}
{session.username ? <img className="user-icon" src={dmIcon} onClick={dmDialog}/> : null}
{permissions.isElevated(session) && !permissions.isElevated(user)? <img className="user-icon" src={user.banned ? unbanIcon : banIcon} onClick={banDialog}/> : null}
</div>
{user.banned ? <span className="user-ban-text">Banned</span> : null}
Expand Down
Loading

0 comments on commit 7980fe3

Please sign in to comment.