mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 01:11:25 +00:00
thread age limit
This commit is contained in:
parent
5661d9da0e
commit
89c58d209c
@ -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<boolean>(localStorage.getItem('sortBy') !== 'false');
|
||||
const [setAnon, setSetAnon] = useState<boolean>(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;
|
||||
|
@ -12,10 +12,11 @@ const DEFAULT_DIFFICULTY = 20;
|
||||
|
||||
const useUniqEvents = () => {
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
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;
|
||||
}, []);
|
||||
|
@ -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 = () => {
|
||||
<div className="w-full md:w-1/3 px-2 mb-4 md:mb-0">
|
||||
<label className="block text-xs mb-2" htmlFor="filterDifficulty">
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center' }}>
|
||||
Proof-of-Work Difficulty Filter {'('}<CpuChipIcon className="h-4 w-4" />{'>'}X to appear on feed{')'}:
|
||||
Proof-of-Work Filter:
|
||||
</span>
|
||||
</label>
|
||||
<input
|
||||
@ -79,7 +82,6 @@ const Settings = () => {
|
||||
className="w-full px-3 py-2 border rounded-md bg-black"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="w-full md:w-1/3 px-2 mb-4 md:mb-0">
|
||||
<label className="block text-xs mb-2" htmlFor="difficulty">
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center' }}>
|
||||
@ -94,6 +96,20 @@ const Settings = () => {
|
||||
className="w-full px-3 py-2 border rounded-md bg-black"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full md:w-1/3 px-2 mb-4 md:mb-0">
|
||||
<label className="block text-xs mb-2" htmlFor="difficulty">
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center' }}>
|
||||
Thread Age Limit (hrs):
|
||||
</span>
|
||||
</label>
|
||||
<input
|
||||
id="age"
|
||||
type="number"
|
||||
value={age}
|
||||
onChange={e => setAge(e.target.value)}
|
||||
className="w-full px-3 py-2 border rounded-md bg-black"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className='pb-4'>
|
||||
<span onClick={() => setShowAdvancedSettings(!showAdvancedSettings)} className="">
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user