mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
fix #46 removes quotes around hex, hopefully
This commit is contained in:
1 parent
e05ba70439
commit
81bf4ffdd8
3 files changed
+20
-5
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
- Fixed/updated unknown extended profile keys rendering.
|
||||
- Added support for `---`, `-#`, and fixed `-` to be unordered.
|
||||
- Fix quotes around colors for tuwunel homeservers ([#46](https://github.com/7w1/sable/issues/46))
|
||||
|
||||
## 1.2.1
|
||||
|
||||
|
||||
@@ -10,18 +10,27 @@ type NameColorEditorProps = {
|
||||
};
|
||||
|
||||
export function NameColorEditor({ current, onSave }: NameColorEditorProps) {
|
||||
const [tempColor, setTempColor] = useState(current || '#FFFFFF');
|
||||
const stripQuotes = (str?: string) => {
|
||||
if (!str) return '';
|
||||
// to solve the silly tuwunel
|
||||
return str.replace(/^["']|["']$/g, '');
|
||||
};
|
||||
|
||||
const [tempColor, setTempColor] = useState(stripQuotes(current) || '#FFFFFF');
|
||||
const [hasChanged, setHasChanged] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (current) setTempColor(current);
|
||||
const sanitized = stripQuotes(current);
|
||||
if (sanitized) setTempColor(sanitized);
|
||||
else setTempColor('#FFFFFF');
|
||||
}, [current]);
|
||||
|
||||
const handleUpdate = (newColor: string) => {
|
||||
const sanitized = newColor.startsWith('#') ? newColor : `#${newColor}`;
|
||||
let sanitized = stripQuotes(newColor);
|
||||
sanitized = sanitized.startsWith('#') ? sanitized : `#${sanitized}`;
|
||||
setTempColor(sanitized);
|
||||
setHasChanged(sanitized.toUpperCase() !== (current?.toUpperCase() || '#FFFFFF'));
|
||||
const currentSanitized = stripQuotes(current) || '#FFFFFF';
|
||||
setHasChanged(sanitized.toUpperCase() !== currentSanitized.toUpperCase());
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
|
||||
@@ -56,7 +56,12 @@ const normalizeInfo = (info: any): UserProfile => {
|
||||
};
|
||||
};
|
||||
|
||||
const isValidHex = (c: string) => /^#[0-9A-F]{6}$/i.test(c);
|
||||
const isValidHex = (c: any): string | undefined => {
|
||||
if (typeof c !== 'string') return undefined;
|
||||
// silly tuwunel smh
|
||||
const cleaned = c.replace(/["']/g, '').trim();
|
||||
return /^#([0-9A-F]{3,6})$/i.test(cleaned) ? cleaned : undefined;
|
||||
};
|
||||
const sanitizeFont = (f: string) => f.replace(/[;{}<>]/g, '').slice(0, 32);
|
||||
|
||||
export const useUserProfile = (
|
||||
|
||||
Reference in new issue
Block a user