Skip to content

Commit

Permalink
Updated React and added Dark Reader detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalloriff committed Sep 10, 2023
1 parent 4bac032 commit 64c38c5
Show file tree
Hide file tree
Showing 20 changed files with 1,356 additions and 1,812 deletions.
2 changes: 1 addition & 1 deletion docs/assets/scripts/main.js

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions docs/assets/scripts/main.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/

/**
* @license
* Copyright 2017 Google LLC
Expand Down Expand Up @@ -149,26 +143,29 @@ object-assign
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/

/** @license React v0.20.2
* scheduler.production.min.js
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-dom.production.min.js
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react.production.min.js
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
Expand Down
8 changes: 4 additions & 4 deletions docs/assets/styles/main.css

Large diffs are not rendered by default.

Binary file modified docs/thumbs.db
Binary file not shown.
2,871 changes: 1,140 additions & 1,731 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@
},
"private": false,
"dependencies": {
"firebase": "^9.0.1",
"firebase": "^10.3.1",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-feather": "^2.0.9",
"regenerator-runtime": "^0.13.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-feather": "^2.0.10",
"regenerator-runtime": "^0.14.0",
"sagiri": "^3.4.0"
},
"devDependencies": {
"@svgr/webpack": "^5.5.0",
"@swc/cli": "^0.1.51",
"@swc/core": "^1.2.93",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^6.3.0",
"@svgr/webpack": "^8.1.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.83",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.2",
"mini-css-extract-plugin": "^2.4.2",
"html-webpack-plugin": "^5.5.3",
"mini-css-extract-plugin": "^2.7.6",
"node-polyfill-webpack-plugin": "^2.0.1",
"sass": "^1.42.1",
"sass-loader": "^12.1.0",
"style-loader": "^3.3.0",
"swc-loader": "^0.1.15",
"webpack": "^5.58.0",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "^4.3.1",
"sass": "^1.66.1",
"sass-loader": "^13.3.2",
"style-loader": "^3.3.3",
"swc-loader": "^0.2.3",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-pwa-manifest": "^4.3.0"
},
"scripts": {
"start": "npx webpack serve --open",
"open": "lt --port 3000 --local-host localhost",
"build": "npx webpack --mode production --env=mode=production"
}
}
}
Binary file modified public/thumbs.db
Binary file not shown.
4 changes: 3 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import _ from "lodash";
import React from "react";
import { ChevronsUp } from "react-feather";
import "./App.scss";
import "./city-fog-theme.css";
import { ActionTypes, joinClassNames } from "./Classes/Constants";
import { dispatcher } from "./Classes/Dispatcher";
import { useEventListener, useMediaQuery } from "./Classes/Hooks";
import RoutesStore from "./Classes/Stores/RoutesStore";
import UserStore from "./Classes/Stores/UserStore";
import ContextMenu from "./Components/ContextMenuHandler";
import DarkReaderDetector from "./Components/DarkReaderDetector";
import { Modals } from "./Components/Modals";
import AuthModal from "./Components/Modals/AuthModal";
import PageFooter from "./Components/PageElements/PageFooter";
Expand All @@ -19,6 +19,7 @@ import PostPage from "./Pages/PostPage";
import PostsPage from "./Pages/PostsPage";
import { SetsPage } from "./Pages/SetsPage";
import SettingsPage, { SettingsRenderer } from "./Pages/SettingsPage";
import "./city-fog-theme.css";

window.history.scrollRestoration = "manual";

Expand Down Expand Up @@ -141,6 +142,7 @@ export default function App() {
<Modals />
<Toasts />
<ContextMenu.Handler />
<DarkReaderDetector />

<SettingsRenderer />
</div>
Expand Down
Binary file added src/Assets/thumbs.db
Binary file not shown.
66 changes: 66 additions & 0 deletions src/Components/DarkReaderDetector.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import _ from "lodash";
import { useCallback, useEffect } from "react";
import { Modals } from "./Modals";

let hasShown = false;
export default function DarkReaderDetector() {
const openDarkReaderNotice = useCallback(_.debounce(() => {
if (hasShown) return;
hasShown = true;

Modals.push(
<div
className="BaseModal DarkReaderNoticeModal"
style={{
background: "var(--primary-bg)",
padding: 20
}}
>
<style>
{"h1 { margin-top: 0; }"}
</style>

<h1>Dark reader detected!</h1>

<p>
This website is already respectful to your eyes, and Dark Reader may ruin the intended experience. Please disable dark reader on this site to see its intended design.
</p>

<h1>How?</h1>

<p>
Navigate to your extensions, and click the Dark Reader icon.
</p>

<img src="https://i.imgur.com/W6sxhj4.png" alt="1" />

<p>
Then press the site URI at the top-left, this will disable for only this website, keeping your eyes safe on other websites.
</p>

<img src="https://i.imgur.com/3ENgzRS.png" alt="2" />
</div>
)
}, 200), []);

const checkForDarkReader = useCallback(() => {
const [html] = document.getElementsByTagName("html");

if (Object.values(html.attributes).some(attr => attr.localName.startsWith("data-darkreader"))) {
openDarkReaderNotice();
}
}, []);

useEffect(() => {
checkForDarkReader();

const observer = new MutationObserver(() => {
checkForDarkReader();
});

observer.observe(document.getElementsByTagName("html")[0], { attributes: true });
return () => observer.disconnect();
}, []);

return null;
}
26 changes: 19 additions & 7 deletions src/Components/Modals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ function ImagePostComponent({ image, setLoaded, setFailed, className, onClick, i
);
}

function SwfPlayer({ src }) {
return (
<div className="SwfPlayer FlexCenter AbsoluteCover" style={{ background: "var(--primary-bg)" }}>
SWF FILES CANNOT BE PLAYED ON SUCRALOSE
</div>
);
}

export function ImageModal({ url, getSources, buttons }) {
// Get the sources or create a single-item array
const sources = typeof (getSources) === "function" ? getSources().filter(u => u) : [url];
Expand Down Expand Up @@ -581,13 +589,17 @@ export function PostModal({ startPost, posts, buttons }) {
isPreview
/>

<ImagePostComponent
key={getRandomKey()}
image={sources[index]}
setLoaded={setLoaded}
setFailed={setFailed}
notes={notes}
/>
{sources[index].full.endsWith(".swf") ? (
<SwfPlayer src={sources[index].full} />
) : (
<ImagePostComponent
key={getRandomKey()}
image={sources[index]}
setLoaded={setLoaded}
setFailed={setFailed}
notes={notes}
/>
)}

<ImageComponent
key={getRandomKey()}
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Posts/BlacklistDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Modals } from "../Modals";
import CreateBlacklistModal from "../Modals/CreateBlacklistModal";

export default function BlacklistDropdown({ forceUpdate }) {

const onChangeBlacklist = selection => {
if (selection.startsWith("action.")) {
switch (selection) {
Expand Down Expand Up @@ -55,5 +54,5 @@ export default function BlacklistDropdown({ forceUpdate }) {
<DropdownItem value="action.create">CREATE NEW BLACKLIST</DropdownItem>
</Dropdown>
</div>
)
);
}
27 changes: 27 additions & 0 deletions src/Components/Posts/OrderDropdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Dropdown, { DropdownItem } from "../Dropdown";

export const OrderTypes = {
Default: "",
Random: "order:random",
Score: "order:score",
FavCount: "order:favcount",
TagCount: "order:tagcount",
NewestFirst: "order:id_desc",
OldestFirst: "order:id",
Resolution: "order:mpixels",
FileSize: "order:filesize"
};

export default function OrderDropdown({ onChange }) {
return (
<div className="Order FlexCenter">
<h2 className="Label">Order</h2>

<Dropdown onChange={onChange}>
{Object.keys(OrderTypes).map(key => (
<DropdownItem key={key} value={OrderTypes[key]}>{key}</DropdownItem>
))}
</Dropdown>
</div>
);
}
59 changes: 40 additions & 19 deletions src/Components/Posts/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ export default function Post({ post }) {
const conditionalDnp = tags.artist.indexOf("conditional_dnp");
!!~conditionalDnp && tags.artist.splice(conditionalDnp, 1);

// Render me harder, daddy.
return previewImage && file.ext !== "swf" ? (
return previewImage ? (
<PostsContext.Consumer>
{context => (
<div className="Post">
Expand All @@ -147,25 +146,47 @@ export default function Post({ post }) {
)}
</div>

{!previewLoaded && (
{!previewLoaded && file.ext !== "swf" && (
<div className="Preview Flex Loading">
<InlineLoading />
</div>
)}

<ContextMenu.Wrapper menu={<PostContextMenu post={post} />}>
<img src={previewImage} className="Preview" alt="Preview"
onLoad={() => setPreviewLoaded(true)}
onClick={() =>
Modals.push(
<PostModal
startPost={post}
posts={context.posts.filter(postFilter)}
buttons={post => <PostModalButtons post={post} />}
/>
)
} />
</ContextMenu.Wrapper>
{file.ext === "swf" ? (
<ContextMenu.Wrapper menu={<PostContextMenu post={post} />}>
<div className="VideoOverlay" style={{ pointerEvents: "none" }}>
<Feather.Box />
<h2 style={{ marginLeft: 5 }}>Flash Game</h2>
</div>

<div
className="Preview AbsoluteCover"
onClick={() =>
Modals.push(
<PostModal
startPost={post}
posts={context.posts.filter(postFilter)}
buttons={post => <PostModalButtons post={post} />}
/>
)
}
/>
</ContextMenu.Wrapper>
) : (
<ContextMenu.Wrapper menu={<PostContextMenu post={post} />}>
<img src={previewImage} className="Preview" alt="Preview"
onLoad={() => setPreviewLoaded(true)}
onClick={() =>
Modals.push(
<PostModal
startPost={post}
posts={context.posts.filter(postFilter)}
buttons={post => <PostModalButtons post={post} />}
/>
)
} />
</ContextMenu.Wrapper>
)}

{file.ext === "webm" && (
<div className="VideoOverlay">
Expand Down Expand Up @@ -386,7 +407,7 @@ export function PostModalButtons({ post }) {
<React.Fragment>
<div className="Button Flex" style={{
alignItems: "center", justifyContent: "center",
color: score.our_score === 1 ? "var(--primary-color)" : null
color: score.our_score === 1 ? "var(--green)" : null
}} onClick={events.vote.bind(null, 1)}>
<Feather.ThumbsUp />
<div style={{ marginLeft: 5 }}>{score.up}</div>
Expand All @@ -396,7 +417,7 @@ export function PostModalButtons({ post }) {

<div className="Button Flex" style={{
alignItems: "center", justifyContent: "center",
color: score.our_score === -1 ? "var(--primary-color)" : null
color: score.our_score === -1 ? "var(--red)" : null
}} onClick={events.vote.bind(null, -1)}>
<Feather.ThumbsDown />
<div style={{ marginLeft: 5 }}>{-score.down}</div>
Expand All @@ -406,7 +427,7 @@ export function PostModalButtons({ post }) {

<div className="Button Flex" style={{
alignItems: "center", justifyContent: "center",
color: is_favorited ? "var(--red)" : null
color: is_favorited ? "var(--pink)" : null
}} onClick={events.favorite}>
<Feather.Heart />
<div style={{ marginLeft: 5 }}>{fav_count}</div>
Expand Down
Loading

0 comments on commit 64c38c5

Please sign in to comment.