forked from Qortal/q-share
update #1
@@ -50,6 +50,8 @@ interface Props {
|
|||||||
userAvatar: string;
|
userAvatar: string;
|
||||||
authenticate: () => void;
|
authenticate: () => void;
|
||||||
setTheme: (val: string) => void;
|
setTheme: (val: string) => void;
|
||||||
|
accountNames: { name: string }[];
|
||||||
|
setActiveName: (name: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NavBar: React.FC<Props> = ({
|
const NavBar: React.FC<Props> = ({
|
||||||
@@ -58,6 +60,8 @@ const NavBar: React.FC<Props> = ({
|
|||||||
userAvatar,
|
userAvatar,
|
||||||
authenticate,
|
authenticate,
|
||||||
setTheme,
|
setTheme,
|
||||||
|
accountNames,
|
||||||
|
setActiveName,
|
||||||
}) => {
|
}) => {
|
||||||
const windowSize = useWindowSize();
|
const windowSize = useWindowSize();
|
||||||
const searchValRef = useRef("");
|
const searchValRef = useRef("");
|
||||||
@@ -426,6 +430,22 @@ const NavBar: React.FC<Props> = ({
|
|||||||
horizontal: "left",
|
horizontal: "left",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{accountNames
|
||||||
|
.filter(n => n.name)
|
||||||
|
.map(n => (
|
||||||
|
<DropdownContainer
|
||||||
|
key={n.name}
|
||||||
|
onClick={() => {
|
||||||
|
setActiveName(n.name);
|
||||||
|
handleCloseUserDropdown();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownText>
|
||||||
|
{n.name === userName ? "✔︎ " : ""}
|
||||||
|
{n.name}
|
||||||
|
</DropdownText>
|
||||||
|
</DropdownContainer>
|
||||||
|
))}
|
||||||
<DropdownContainer
|
<DropdownContainer
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsOpenBlockedNamesModal(true);
|
setIsOpenBlockedNamesModal(true);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export const FileListComponentLevel = ({ mode }: VideoListProps) => {
|
|||||||
const getVideos = React.useCallback(async () => {
|
const getVideos = React.useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const offset = videos.length;
|
const offset = videos.length;
|
||||||
const url = `/arbitrary/resources/search?mode=ALL&service=DOCUMENT&query=${QSHARE_FILE_BASE}_&limit=50&includemetadata=false&reverse=true&excludeblocked=true&name=${paramName}&exactmatchnames=true&offset=${offset}`;
|
const url = `/arbitrary/resources/search?mode=ALL&service=DOCUMENT&query=${QSHARE_FILE_BASE}&limit=50&includemetadata=false&reverse=true&excludeblocked=true&name=${paramName}&exactmatchnames=true&offset=${offset}`;
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
import { createSlice } from '@reduxjs/toolkit';
|
import { createSlice } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
|
export interface NameRecord {
|
||||||
|
name: string
|
||||||
|
owner: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface User {
|
||||||
|
address: string
|
||||||
|
publicKey: string
|
||||||
|
name?: string
|
||||||
|
names?: NameRecord[]
|
||||||
|
}
|
||||||
|
|
||||||
interface AuthState {
|
interface AuthState {
|
||||||
user: {
|
user: User | null
|
||||||
address: string;
|
|
||||||
publicKey: string;
|
|
||||||
name?: string;
|
|
||||||
} | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: AuthState = {
|
const initialState: AuthState = {
|
||||||
user: null
|
user: null
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
export interface NameRecord {
|
||||||
|
name: string;
|
||||||
|
owner: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAccountNames(address: string): Promise<NameRecord[]> {
|
||||||
|
try {
|
||||||
|
const list = await qortalRequest({
|
||||||
|
action: 'GET_ACCOUNT_NAMES',
|
||||||
|
address,
|
||||||
|
});
|
||||||
|
if (Array.isArray(list) && list.length) return list;
|
||||||
|
return [{ name: '', owner: address }];
|
||||||
|
} catch {
|
||||||
|
return [{ name: '', owner: address }];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPrimaryAccountName(address: string): Promise<string> {
|
||||||
|
try {
|
||||||
|
const res = await qortalRequest({
|
||||||
|
action: 'GET_PRIMARY_NAME',
|
||||||
|
address,
|
||||||
|
});
|
||||||
|
return typeof res === 'string' ? res : '';
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,11 @@ import React, {
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
import { addUser } from "../state/features/authSlice";
|
import { addUser } from "../state/features/authSlice";
|
||||||
|
import {
|
||||||
|
getAccountNames,
|
||||||
|
getPrimaryAccountName,
|
||||||
|
NameRecord,
|
||||||
|
} from "../utils/qortalRequestFunctions";
|
||||||
import NavBar from "../components/layout/Navbar/Navbar";
|
import NavBar from "../components/layout/Navbar/Navbar";
|
||||||
import PageLoader from "../components/common/PageLoader";
|
import PageLoader from "../components/common/PageLoader";
|
||||||
import { RootState } from "../state/store";
|
import { RootState } from "../state/store";
|
||||||
@@ -69,10 +74,17 @@ const GlobalWrapper: React.FC<Props> = ({ children, setTheme }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!username) return;
|
if (!username) return;
|
||||||
|
|
||||||
getAvatar(username);
|
getAvatar(username);
|
||||||
}, [username, getAvatar]);
|
}, [username, getAvatar]);
|
||||||
|
|
||||||
|
const switchActiveName = useCallback(
|
||||||
|
(newName: string) => {
|
||||||
|
if (!user) return;
|
||||||
|
dispatch(addUser({ ...user, name: newName }));
|
||||||
|
},
|
||||||
|
[user, dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
const { isLoadingGlobal } = useSelector((state: RootState) => state.global);
|
const { isLoadingGlobal } = useSelector((state: RootState) => state.global);
|
||||||
|
|
||||||
async function getNameInfo(address: string) {
|
async function getNameInfo(address: string) {
|
||||||
@@ -95,8 +107,9 @@ const GlobalWrapper: React.FC<Props> = ({ children, setTheme }) => {
|
|||||||
action: "GET_USER_ACCOUNT",
|
action: "GET_USER_ACCOUNT",
|
||||||
});
|
});
|
||||||
|
|
||||||
const name = await getNameInfo(account.address);
|
const names = await getAccountNames(account.address);
|
||||||
dispatch(addUser({ ...account, name }));
|
const primary = await getPrimaryAccountName(account.address);
|
||||||
|
dispatch(addUser({ ...account, name: primary, names }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
@@ -136,6 +149,8 @@ const GlobalWrapper: React.FC<Props> = ({ children, setTheme }) => {
|
|||||||
setTheme={(val: string) => setTheme(val)}
|
setTheme={(val: string) => setTheme(val)}
|
||||||
isAuthenticated={!!user?.name}
|
isAuthenticated={!!user?.name}
|
||||||
userName={user?.name || ""}
|
userName={user?.name || ""}
|
||||||
|
accountNames={user?.names || []}
|
||||||
|
setActiveName={switchActiveName}
|
||||||
userAvatar={userAvatar}
|
userAvatar={userAvatar}
|
||||||
authenticate={askForAccountInformation}
|
authenticate={askForAccountInformation}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user