From 89c58d209c64c983eb943635dd1aa68098be9f55 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Wed, 31 Jan 2024 17:25:46 +1100 Subject: [PATCH] thread age limit --- client/src/components/Board.tsx | 3 ++- client/src/components/Home.tsx | 3 ++- client/src/components/Settings.tsx | 20 ++++++++++++++++++-- client/src/utils/subscriptions.ts | 7 ++++--- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/client/src/components/Board.tsx b/client/src/components/Board.tsx index 1db30fe..d534862 100644 --- a/client/src/components/Board.tsx +++ b/client/src/components/Board.tsx @@ -15,6 +15,7 @@ const DEFAULT_DIFFICULTY = 20; const Board = () => { const { id } = useParams(); const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; + const age = Number(localStorage.getItem("age")) || 24; const [sortByTime, setSortByTime] = useState(localStorage.getItem('sortBy') !== 'false'); const [setAnon, setSetAnon] = useState(localStorage.getItem('anonMode') !== 'false'); @@ -27,7 +28,7 @@ const Board = () => { useEffect(() => { const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]); console.log(events) - const unsubscribe = subBoardFeed(pubkey, onEvent); + const unsubscribe = subBoardFeed(pubkey, onEvent, age); subProfile(pubkey, onEvent) return unsubscribe; diff --git a/client/src/components/Home.tsx b/client/src/components/Home.tsx index a9a4cf2..1a56f26 100644 --- a/client/src/components/Home.tsx +++ b/client/src/components/Home.tsx @@ -12,10 +12,11 @@ const DEFAULT_DIFFICULTY = 20; const useUniqEvents = () => { const [events, setEvents] = useState([]); + const age = Number(localStorage.getItem("age")) || 24; useEffect(() => { const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]); - const unsubscribe = subGlobalFeed(onEvent); + const unsubscribe = subGlobalFeed(onEvent, age); return unsubscribe; }, []); diff --git a/client/src/components/Settings.tsx b/client/src/components/Settings.tsx index c297c39..3a04cb9 100644 --- a/client/src/components/Settings.tsx +++ b/client/src/components/Settings.tsx @@ -10,6 +10,7 @@ type TestResponse = { const Settings = () => { const [filterDifficulty, setFilterDifficulty] = useState(localStorage.getItem('filterDifficulty') || 20); const [difficulty, setDifficulty] = useState(localStorage.getItem('difficulty') || 21); + const [age, setAge] = useState(localStorage.getItem('age') || 24); const [showAdvancedSettings, setShowAdvancedSettings] = useState(false); const [powServer, setPowServer] = useState(localStorage.getItem('powserver') || ''); const [testDiff, setTestDiff] = useState('21') @@ -22,11 +23,13 @@ const Settings = () => { localStorage.setItem('filterDifficulty', String(filterDifficulty)); localStorage.setItem('difficulty', String(difficulty)); localStorage.setItem('powserver', String(powServer)); + localStorage.setItem('age', String(age)); const eventData = { difficulty: String(difficulty), filterDifficulty: String(filterDifficulty), powServer: String(powServer), + age: String(age), }; const event = new CustomEvent('settingsChanged', { detail: eventData }); window.dispatchEvent(event); @@ -68,7 +71,7 @@ const Settings = () => {
{ className="w-full px-3 py-2 border rounded-md bg-black" />
-
+
+ + setAge(e.target.value)} + className="w-full px-3 py-2 border rounded-md bg-black" + /> +
setShowAdvancedSettings(!showAdvancedSettings)} className=""> diff --git a/client/src/utils/subscriptions.ts b/client/src/utils/subscriptions.ts index ef3baf3..1ad3d29 100644 --- a/client/src/utils/subscriptions.ts +++ b/client/src/utils/subscriptions.ts @@ -7,7 +7,7 @@ type SubCallback = ( ) => void; /** subscribe to global feed */ -export const subGlobalFeed = (onEvent: SubCallback) => { +export const subGlobalFeed = (onEvent: SubCallback, age: number) => { console.info('subscribe to global feed'); unsubAll(); const now = Math.floor(Date.now() * 0.001); @@ -23,7 +23,7 @@ export const subGlobalFeed = (onEvent: SubCallback) => { filter: { ...(prefix && { ids: ['0'.repeat(prefix)] }), kinds: [1, 6], - since: Math.floor((Date.now() * 0.001) - (24 * 60 * 60)), + since: Math.floor((Date.now() * 0.001) - (age * 60 * 60)), limit: 500, }, unsub: true @@ -266,6 +266,7 @@ export const subNotifications = ( export const subBoardFeed = ( board: string, onEvent: SubCallback, + age: number ) => { console.info('subscribe to board'); unsubAll(); @@ -283,7 +284,7 @@ export const subBoardFeed = ( ...(prefix && { ids: ['0'.repeat(prefix)] }), "#d": [board], kinds: [1, 6], - since: Math.floor((Date.now() * 0.001) - (24 * 60 * 60)), + since: Math.floor((Date.now() * 0.001) - (age * 60 * 60)), limit: 500, }, unsub: true