mirror of https://github.com/msgbyte/tailchat
feat(admin): allow edit client config serverName edit in admin
parent
6c26fe1c15
commit
9c7448b7cb
@ -0,0 +1,7 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { parseUrlStr } from '../utils';
|
||||||
|
|
||||||
|
export const Image: React.FC<{ src: string }> = React.memo((props) => {
|
||||||
|
return <img src={parseUrlStr(props.src)} />;
|
||||||
|
});
|
||||||
|
Image.displayName = 'Image';
|
@ -0,0 +1,15 @@
|
|||||||
|
import { useCallback, useLayoutEffect, useState } from 'react';
|
||||||
|
|
||||||
|
export function useEditValue<T>(value: T, onChange: (val: T) => void) {
|
||||||
|
const [inner, setInner] = useState(value);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
setInner(value);
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
const onSave = useCallback(() => {
|
||||||
|
onChange(inner);
|
||||||
|
}, [inner, onChange]);
|
||||||
|
|
||||||
|
return [inner, setInner, onSave] as const;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* parse url, and replace some constants with variable
|
||||||
|
* @param originUrl 原始Url
|
||||||
|
* @returns 解析后的url
|
||||||
|
*/
|
||||||
|
export function parseUrlStr(originUrl: string): string {
|
||||||
|
return String(originUrl).replace('{BACKEND}', window.location.origin);
|
||||||
|
}
|
Loading…
Reference in New Issue