Compare commits

..

No commits in common. "staging" and "wot-fixes" have entirely different histories.

12 changed files with 39 additions and 134 deletions

View File

@ -110,7 +110,7 @@ export const ModFilter = React.memo(
data-bs-toggle='dropdown'
type='button'
>
Trust: {filterOptions.wot}
{filterOptions.wot}
</button>
<div className='dropdown-menu dropdownMainMenu'>
{Object.values(WOTFilterOptions).map((item, index) => {
@ -125,19 +125,18 @@ export const ModFilter = React.memo(
// when logged in user not admin
if (
item === WOTFilterOptions.None ||
item === WOTFilterOptions.Mine_Only ||
item === WOTFilterOptions.Exclude
item === WOTFilterOptions.Mine_Only
) {
const isWoTNpub =
const isAdmin =
userState.user?.npub ===
import.meta.env.VITE_SITE_WOT_NPUB
import.meta.env.VITE_REPORTING_NPUB
const isOwnProfile =
author &&
userState.auth &&
userState.user?.pubkey === author
if (!(isWoTNpub || isOwnProfile)) return null
if (!(isAdmin || isOwnProfile)) return null
}
return (

View File

@ -74,6 +74,7 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => {
useEffect(() => {
window.onunhandledrejection = async (event: PromiseRejectionEvent) => {
event.preventDefault()
console.log(event.reason)
if (event.reason?.name === Dexie.errnames.DatabaseClosed) {
console.log(
'Could not open Dexie DB, probably version change. Deleting old DB and reloading...'
@ -244,7 +245,7 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => {
// Find the user's relays (10s timeout).
const relayUrls = await Promise.race([
getRelayListForUser(hexKey, ndk),
timeout(3000)
timeout(10000)
])
.then((ndkRelayList) => {
if (ndkRelayList) return ndkRelayList[userRelaysType]
@ -264,9 +265,7 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => {
.fetchEvents(
filter,
{ closeOnEose: true, cacheUsage: NDKSubscriptionCacheUsage.PARALLEL },
relayUrls.length
? NDKRelaySet.fromRelayUrls(relayUrls, ndk, true)
: undefined
NDKRelaySet.fromRelayUrls(relayUrls, ndk, true)
)
.then((ndkEventSet) => {
const ndkEvents = Array.from(ndkEventSet)

View File

@ -66,9 +66,7 @@ export const useComments = (
closeOnEose: false,
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
},
relayUrls.size
? NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk)
: undefined
NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk)
)
subscription.on('event', (ndkEvent) => {

View File

@ -54,35 +54,18 @@ export const useFilteredMods = (
}
const wotFilter = (mods: ModDetails[]) => {
// Determine the filtering logic based on the WOT filter option and user state
// when user is not logged in use Site_Only
if (!userState.auth) {
return mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author))
}
// when user is logged, allow other filter selections
const isWoTNpub =
userState.user?.npub === import.meta.env.VITE_SITE_WOT_NPUB
// Determine the filtering logic based on the WOT filter option
switch (filterOptions.wot) {
case WOTFilterOptions.None:
// Only admins can choose None, use siteWoT for others
return isWoTNpub
? mods
: mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author))
case WOTFilterOptions.Exclude:
// Only admins can choose Exlude, use siteWot for others
// Exlude returns the mods not in the site's WoT
return isWoTNpub
? mods.filter((mod) => !isInWoT(siteWot, siteWotLevel, mod.author))
: mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author))
return mods
case WOTFilterOptions.Site_Only:
return mods.filter((mod) =>
isInWoT(siteWot, siteWotLevel, mod.author)
)
case WOTFilterOptions.Mine_Only:
// Only admins can choose Mine_Only, use siteWoT for others
return isWoTNpub
? mods.filter((mod) => isInWoT(userWot, userWotLevel, mod.author))
: mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author))
return mods.filter((mod) =>
isInWoT(userWot, userWotLevel, mod.author)
)
case WOTFilterOptions.Site_And_Mine:
return mods.filter(
(mod) =>
@ -129,7 +112,6 @@ export const useFilteredMods = (
return filtered
}, [
userState.auth,
userState.user?.npub,
filterOptions.sort,
filterOptions.moderated,

View File

@ -24,7 +24,9 @@ export const Layout = () => {
const dispatch = useAppDispatch()
const { ndk, fetchEventFromUserRelays } = useNDKContext()
const userState = useAppSelector((state) => state.user)
const { siteWotStatus } = useAppSelector((state) => state.wot)
const { siteWotStatus, siteWotLevel, userWotLevel } = useAppSelector(
(state) => state.wot
)
// calculate site's wot
useEffect(() => {
@ -44,7 +46,7 @@ export const Layout = () => {
})
}
}
}, [ndk, dispatch])
}, [ndk, siteWotLevel, dispatch])
// calculate user's wot
useEffect(() => {
@ -60,7 +62,7 @@ export const Layout = () => {
toast.error('An error occurred in calculating user web-of-trust!')
})
}
}, [ndk, userState.user, dispatch])
}, [ndk, userState.user, userWotLevel, dispatch])
// get site's wot level
useEffect(() => {
@ -70,8 +72,7 @@ export const Layout = () => {
fetchEventFromUserRelays(
{
kinds: [NDKKind.AppSpecificData],
'#d': ['degmods'],
authors: [hexPubkey]
'#d': ['degmods']
},
hexPubkey,
UserRelaysType.Both
@ -93,8 +94,7 @@ export const Layout = () => {
fetchEventFromUserRelays(
{
kinds: [NDKKind.AppSpecificData],
'#d': ['degmods'],
authors: [hexPubkey]
'#d': ['degmods']
},
hexPubkey,
UserRelaysType.Both

View File

@ -22,6 +22,7 @@ export const ReportPopup = ({ handleClose }: ReportPopupProps) => {
useEffect(() => {
if (fetcher.data) {
const { isSent } = fetcher.data
console.log(fetcher.data)
if (isSent) {
handleClose()
}

View File

@ -922,13 +922,11 @@ const Body = ({
<div
ref={postBodyRef}
className='IBMSMSMBSSPostBody'
style={{ maxHeight: '250px', padding: '10px 18px' }}
style={{ maxHeight: '250px', padding: '0 10px' }}
>
<EditorContent editor={editor} />
<div ref={viewFullPostBtnRef} className='IBMSMSMBSSPostBodyHide'>
<div className='IBMSMSMBSSPostBodyHideText'>
<p onClick={viewFullPost}>Read Full</p>
</div>
<p onClick={viewFullPost}>View</p>
</div>
</div>
<div className='IBMSMSMBSSShots'>

View File

@ -4,9 +4,9 @@ import { useAppDispatch, useAppSelector, useNDKContext } from 'hooks'
import { kinds, UnsignedEvent, Event } from 'nostr-tools'
import { useEffect, useState } from 'react'
import { toast } from 'react-toastify'
import { setSiteWotLevel, setUserWotLevel } from 'store/reducers/wot'
import { setUserWotLevel } from 'store/reducers/wot'
import { UserRelaysType } from 'types'
import { log, LogType, now, npubToHex } from 'utils'
import { log, LogType, now } from 'utils'
// todo: use components from Input.tsx
export const PreferencesSetting = () => {
@ -21,17 +21,16 @@ export const PreferencesSetting = () => {
useEffect(() => {
if (user?.pubkey) {
const hexPubkey = user.pubkey as string
fetchEventFromUserRelays(
{
kinds: [NDKKind.AppSpecificData],
'#d': ['degmods'],
authors: [hexPubkey]
'#d': ['degmods']
},
hexPubkey,
user.pubkey as string,
UserRelaysType.Both
).then((event) => {
if (event) {
console.log('event :>> ', event)
const wot = event.tagValue('wot')
if (wot) setWotLevel(parseInt(wot))
}
@ -91,13 +90,6 @@ export const PreferencesSetting = () => {
)
dispatch(setUserWotLevel(wotLevel))
// If wot admin, update site wot level too
const SITE_WOT_NPUB = import.meta.env.VITE_SITE_WOT_NPUB
const siteWotPubkey = npubToHex(SITE_WOT_NPUB)
if (siteWotPubkey === hexPubkey) {
dispatch(setSiteWotLevel(wotLevel))
}
})
.catch((err) => {
console.error(err)
@ -127,7 +119,6 @@ export const PreferencesSetting = () => {
className='CheckboxMain'
name='notificationsSettings'
checked
readOnly
/>
</div>
<div className='inputLabelWrapperMain inputLabelWrapperMainAlt inputLabelWrapperMainAltStylized'>
@ -139,7 +130,6 @@ export const PreferencesSetting = () => {
className='CheckboxMain'
name='notificationsSettings'
checked
readOnly
/>
</div>
<div className='inputLabelWrapperMain inputLabelWrapperMainAlt inputLabelWrapperMainAltStylized'>
@ -151,7 +141,6 @@ export const PreferencesSetting = () => {
className='CheckboxMain'
name='notificationsSettings'
checked
readOnly
/>
</div>
<div className='inputLabelWrapperMain inputLabelWrapperMainAlt inputLabelWrapperMainAltStylized'>
@ -163,7 +152,6 @@ export const PreferencesSetting = () => {
className='CheckboxMain'
name='notificationsSettings'
checked
readOnly
/>
</div>
<div className='inputLabelWrapperMain inputLabelWrapperMainAlt inputLabelWrapperMainAltStylized'>
@ -175,7 +163,6 @@ export const PreferencesSetting = () => {
className='CheckboxMain'
name='notificationsSettings'
checked
readOnly
/>
</div>
</div>
@ -225,7 +212,6 @@ export const PreferencesSetting = () => {
className='CheckboxMain'
name='WoTZap'
checked
readOnly
/>
</div>
</div>

View File

@ -11,7 +11,7 @@ import { Event, kinds, UnsignedEvent } from 'nostr-tools'
import { useEffect, useState } from 'react'
import { toast } from 'react-toastify'
import { UserRelaysType } from 'types'
import { log, LogType, normalizeWebSocketURL, now, timeout } from 'utils'
import { log, LogType, normalizeWebSocketURL, now } from 'utils'
const READ_MARKER = 'read'
const WRITE_MARKER = 'write'
@ -21,16 +21,12 @@ export const RelaySettings = () => {
const userState = useAppSelector((state) => state.user)
const [ndkRelayList, setNDKRelayList] = useState<NDKRelayList | null>(null)
const [isPublishing, setIsPublishing] = useState(false)
const [isLoading, setIsLoading] = useState(true)
const [inputValue, setInputValue] = useState('')
useEffect(() => {
if (userState.auth && userState.user?.pubkey) {
setIsLoading(true)
Promise.race([
getRelayListForUser(userState.user?.pubkey as string, ndk),
timeout(10000)
])
getRelayListForUser(userState.user.pubkey as string, ndk)
.then((res) => {
setNDKRelayList(res)
})
@ -40,13 +36,9 @@ export const RelaySettings = () => {
err.message || err
}`
)
setNDKRelayList(new NDKRelayList(ndk))
})
.finally(() => {
setIsLoading(false)
setNDKRelayList(null)
})
} else {
setIsLoading(false)
setNDKRelayList(null)
}
}, [userState, ndk])
@ -232,14 +224,6 @@ export const RelaySettings = () => {
setIsPublishing(false)
}
if (isLoading)
return (
<>
<div></div>
<LoadingSpinner desc='Loading' />
</>
)
if (!ndkRelayList)
return <div>Could not fetch user relay list or user is not logged in </div>
@ -274,12 +258,6 @@ export const RelaySettings = () => {
<div className='inputLabelWrapperMain'>
<label className='form-label labelMain'>Your relays</label>
</div>
{relayEntries.length === 0 && (
<>
We recommend adding one of our relays if you're planning to
frequently use DEG Mods, for a better experience.
</>
)}
{relayEntries.map(([relayUrl, relayType]) => (
<RelayListItem
key={relayUrl}

View File

@ -163,21 +163,11 @@
flex-direction: column;
justify-content: end;
align-items: center;
padding: 15px;
color: rgba(255,255,255,0.75);
font-weight: bold;
box-shadow: inset 0 0 8px 0 rgb(0,0,0,0.1);
overflow: hidden;
margin-bottom: -1px;
}
.IBMSMSMBSSPostBodyHideText {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgb(55 55 55);
cursor: pointer;
box-shadow: inset 0 0 8px 0 rgb(0,0,0,0.1);
}
.IBMSMSMBSSModFor {
@ -252,7 +242,7 @@
padding: 2px;
}
.IBMSMSMBSSPostBody > div:first-child > div > p {
.IBMSMSMBSSPostBody > div > div > p {
margin-bottom: 10px;
}
@ -261,31 +251,4 @@
border-bottom: solid 1px rgb(255 255 255 / 10%);
padding: 0px 0 10px 0;
line-height: 1.5 !important;
}
.dropdown.dropdownMain.dropdownMainBlogpost {
flex-grow: unset;
position: absolute;
top: 10px;
right: 10px;
background: rgba(0,0,0,0.1);
border-radius: 6px;
padding: 2px;
}
.IBMSMSMBSSWarning {
width: 100%;
border-radius: 8px;
padding: 10px 15px;
border: solid 2px tomato;
background: rgba(255,80,80,0.15);
color: rgba(255,255,255,0.95);
text-align: center;
}
.IBMSMSMBSSPostBodyHideText > * {
width: 100%;
text-align: center;
margin: 0;
padding: 10px;
}

View File

@ -21,8 +21,7 @@ export enum WOTFilterOptions {
Site_And_Mine = 'Site & Mine',
Site_Only = 'Site Only',
Mine_Only = 'Mine Only',
None = 'None',
Exclude = 'Exclude'
None = 'None'
}
export interface FilterOptions {

View File

@ -98,7 +98,9 @@ export const findFollowsAndMuteUsers = async (
follows.add(f)
})
}
})
events.forEach((event) => {
if (event.kind === NDKKind.MuteList) {
filterValidPTags(event.tags).forEach((f) => {
muted.add(f)