feat(subplebbit): add automatic theme based on nsfw or sfw tags

This commit is contained in:
Tom (plebeius.eth)
2024-06-17 12:17:36 +02:00
parent 77ccf0c849
commit 22c1acdd3d
20 changed files with 189 additions and 87 deletions
+2 -2
View File
@@ -25,12 +25,12 @@ const Board = () => {
const location = useLocation();
const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>();
const isInAllView = isAllView(location.pathname);
const isInAllView = isAllView(location.pathname, useParams());
const defaultSubplebbitAddresses = useDefaultSubplebbitAddresses();
const account = useAccount();
const subscriptions = account?.subscriptions;
const isInSubscriptionsView = isSubscriptionsView(location.pathname);
const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams());
const subplebbitAddresses = useMemo(() => {
if (isInAllView) {
@@ -9,8 +9,9 @@ const FiltersModal = ({ closeModal }: { closeModal: () => void }) => {
const { t } = useTranslation();
const { showAdultBoards, setShowAdultBoards, showGoreBoards, setShowGoreBoards, showTextOnlyThreads, setShowTextOnlyThreads } = useCatalogFiltersStore();
const location = useLocation();
const isInCatalogView = isCatalogView(location.pathname, useParams());
const isInAllView = isAllView(location.pathname);
const params = useParams();
const isInCatalogView = isCatalogView(location.pathname, params);
const isInAllView = isAllView(location.pathname, params);
return (
<>
+3 -7
View File
@@ -27,7 +27,7 @@ const useFeedRows = (columnCount: number, feed: any, isFeedLoaded: boolean, subp
const { avatarUrl } = suggested || {};
const location = useLocation();
const isInAllView = isAllView(location.pathname);
const isInAllView = isAllView(location.pathname, useParams());
const multisub = useMultisubMetadata();
const feedWithDescriptionAndRules = useMemo(() => {
@@ -90,13 +90,13 @@ const Catalog = () => {
const location = useLocation();
const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>();
const isInAllView = isAllView(location.pathname);
const isInAllView = isAllView(location.pathname, useParams());
const defaultSubplebbits = useDefaultSubplebbits();
const { showAdultBoards, showGoreBoards } = useCatalogFiltersStore();
const account = useAccount();
const subscriptions = account?.subscriptions;
const isInSubscriptionsView = isSubscriptionsView(location.pathname);
const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams());
const subplebbitAddresses = useMemo(() => {
const filteredDefaultSubplebbits = defaultSubplebbits
@@ -121,10 +121,6 @@ const Catalog = () => {
return [subplebbitAddress];
}, [isInAllView, isInSubscriptionsView, subplebbitAddress, defaultSubplebbits, subscriptions, showAdultBoards, showGoreBoards]);
useEffect(() => {
console.log(showAdultBoards, showGoreBoards);
}, [showAdultBoards, showGoreBoards]);
const columnCount = Math.floor(useWindowWidth() / columnWidth);
// postPerPage based on columnCount for optimized feed, dont change value after first render
// eslint-disable-next-line
+1 -18
View File
@@ -1,9 +1,8 @@
import { useEffect, useState, useRef } from 'react';
import { useState } from 'react';
import { Link, useParams } from 'react-router-dom';
import { HomeLogo } from '../home';
import styles from './not-found.module.css';
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
import useTheme from '../../hooks/use-theme';
const totalNotFoundImages = 2;
@@ -20,22 +19,6 @@ const NotFound = () => {
const { subplebbitAddress } = useParams();
const isValidSubplebbitAddress = !subplebbitAddress || subplebbitAddress.includes('.') || /^12D3K[a-zA-Z0-9]{44}$/.test(subplebbitAddress);
const [theme, setTheme] = useTheme();
const previousThemeRef = useRef(theme);
useEffect(() => {
if (theme !== 'yotsuba') {
previousThemeRef.current = theme;
setTheme('yotsuba');
}
return () => {
if (theme === 'yotsuba') {
setTheme(previousThemeRef.current);
}
};
}, [theme, setTheme]);
return (
<div className={styles.wrapper}>
<div className={styles.content}>