feat(web): group space settings into basic, content and join tabs
This commit is contained in:
1 parent
79bfd560cb
commit
b847916a5b
2 files changed
+147
-62
No files matched your search
@@ -15,10 +15,72 @@
|
|||||||
color: var(--text);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.form {
|
.layout {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 148px minmax(0, 1fr);
|
||||||
|
gap: var(--space-6);
|
||||||
|
height: min(360px, 70dvh);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
align-self: start;
|
||||||
|
gap: var(--space-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-3);
|
||||||
|
min-height: 40px;
|
||||||
|
padding: 0 var(--space-3);
|
||||||
|
border: 0;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--text-dim);
|
||||||
|
font: inherit;
|
||||||
|
font-size: 14px;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button:hover {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button[aria-selected='true'] {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-3);
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pane {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: column;
|
||||||
gap: var(--space-4);
|
gap: var(--space-4);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.check {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
min-height: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.check input {
|
||||||
|
accent-color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.field {
|
.field {
|
||||||
@@ -41,24 +103,35 @@
|
|||||||
font: inherit;
|
font: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.check {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: var(--space-2);
|
|
||||||
min-height: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.check input {
|
|
||||||
accent-color: var(--accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
.field input:disabled,
|
.field input:disabled,
|
||||||
.field select:disabled {
|
.field select:disabled {
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: var(--space-3);
|
||||||
|
padding-top: var(--space-3);
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (width <= 720px) {
|
||||||
|
.layout {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
gap: var(--space-4);
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
flex-direction: row;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.note {
|
.note {
|
||||||
margin: 0;
|
margin: calc(-1 * var(--space-2)) 0 0;
|
||||||
color: var(--text-dim);
|
color: var(--text-dim);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import type { ChannelInfo, ChannelSettingsPatch } from '@/core-bridge/types';
|
import type { ChannelInfo, ChannelSettingsPatch } from '@/core-bridge/types';
|
||||||
import { Button } from '@/ui/Button';
|
import { Button } from '@/ui/Button';
|
||||||
|
import { Icon, type IconName } from '@/ui/Icon';
|
||||||
import { Sheet } from '@/ui/Sheet';
|
import { Sheet } from '@/ui/Sheet';
|
||||||
import styles from './ChannelSettingsSheet.module.css';
|
import styles from './ChannelSettingsSheet.module.css';
|
||||||
|
|
||||||
@@ -8,6 +9,13 @@ import { useServerSettings } from '@/store/server';
|
|||||||
import type { ServerInfoBody } from '@/core-bridge/generated/api';
|
import type { ServerInfoBody } from '@/core-bridge/generated/api';
|
||||||
import { ttlLabel, withCurrent } from '@/lib/settingOptions';
|
import { ttlLabel, withCurrent } from '@/lib/settingOptions';
|
||||||
|
|
||||||
|
type Tab = 'basic' | 'content' | 'join';
|
||||||
|
const TABS: { id: Tab; label: string; icon: IconName }[] = [
|
||||||
|
{ id: 'basic', label: '基本', icon: 'edit' },
|
||||||
|
{ id: 'content', label: '内容', icon: 'history' },
|
||||||
|
{ id: 'join', label: '加入', icon: 'users' },
|
||||||
|
];
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
channel: ChannelInfo;
|
channel: ChannelInfo;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -31,6 +39,7 @@ function SettingsForm({ channel, onClose, onSave, info }: Props & { info: Server
|
|||||||
const [joinPolicy, setJoinPolicy] = useState<'open' | 'invite'>(channel.joinPolicy!);
|
const [joinPolicy, setJoinPolicy] = useState<'open' | 'invite'>(channel.joinPolicy!);
|
||||||
const [joinPassword, setJoinPassword] = useState('');
|
const [joinPassword, setJoinPassword] = useState('');
|
||||||
const [clearPassword, setClearPassword] = useState(false);
|
const [clearPassword, setClearPassword] = useState(false);
|
||||||
|
const [tab, setTab] = useState<Tab>('basic');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [failed, setFailed] = useState(false);
|
const [failed, setFailed] = useState(false);
|
||||||
const ttlOptions = withCurrent(info.choices.ttl_seconds, ttlSeconds);
|
const ttlOptions = withCurrent(info.choices.ttl_seconds, ttlSeconds);
|
||||||
@@ -51,56 +60,59 @@ function SettingsForm({ channel, onClose, onSave, info }: Props & { info: Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dirty = name.trim() !== (channel.name ?? '') || maxMembers !== channel.maxMembers || membersCanUpload !== channel.membersCanUpload
|
||||||
|
|| ttlSeconds !== channel.ttlSeconds || fileMaxDownloads !== channel.maxDownloads || joinPolicy !== channel.joinPolicy || joinPassword !== '' || clearPassword;
|
||||||
|
const invalid = maxMembers < 1 || maxMembers > info.limits.max_members || ttlSeconds < info.limits.min_ttl_seconds || ttlSeconds > info.limits.max_ttl_seconds || Boolean(joinPassword && joinPassword.length < 8);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet title="空间设置" onClose={onClose}>
|
<Sheet title="空间设置" onClose={onClose} wide>
|
||||||
<div className={styles.form}>
|
<div className={styles.layout}>
|
||||||
<label className={styles.field}>
|
<div className={styles.tabs} role="tablist" aria-orientation="vertical" aria-label="空间设置分类">
|
||||||
<span>空间名称</span>
|
{TABS.map((item) => <button key={item.id} type="button" role="tab" aria-selected={tab === item.id} onClick={() => setTab(item.id)}>
|
||||||
<input type="text" maxLength={48} value={name} disabled={!owner} placeholder="例如:项目组" onChange={(event) => setName(event.target.value)} />
|
<Icon name={item.icon} size={18} /><span>{item.label}</span></button>)}
|
||||||
<span className={styles.note}>空间名称和设置对加入者及服务端可见。</span>
|
</div>
|
||||||
</label>
|
<div className={styles.content}>
|
||||||
|
<section className={styles.pane} role="tabpanel" aria-label={TABS.find((item) => item.id === tab)?.label}>
|
||||||
<label className={styles.field}>
|
{tab === 'basic' ? <>
|
||||||
<span>成员人数上限</span>
|
<label className={styles.field}><span>空间名称</span>
|
||||||
<input type="number" min={1} max={info.limits.max_members} step={1} value={maxMembers} disabled={!owner} onChange={(event) => setMaxMembers(Number(event.target.value))} />
|
<input type="text" maxLength={48} value={name} disabled={!owner} placeholder="例如:项目组" onChange={(event) => setName(event.target.value)} /></label>
|
||||||
</label>
|
<p className={styles.note}>空间名称和设置对加入者及服务端可见。</p>
|
||||||
|
<label className={styles.field}><span>成员人数上限</span>
|
||||||
<label className={styles.field}>
|
<input type="number" min={1} max={info.limits.max_members} step={1} value={maxMembers} disabled={!owner} onChange={(event) => setMaxMembers(Number(event.target.value))} /></label>
|
||||||
<span>内容保留时间</span>
|
<p className={styles.note}>成员与邀请请在右侧栏的「成员」页管理。</p>
|
||||||
<select value={ttlSeconds} disabled={!owner} onChange={(event) => setTtlSeconds(Number(event.target.value))}>
|
</> : null}
|
||||||
{ttlOptions.map(value => <option key={value} value={value}>{ttlLabel(value)}</option>)}
|
{tab === 'content' ? <>
|
||||||
</select>
|
<label className={styles.field}><span>内容保留时间</span>
|
||||||
</label>
|
<select value={ttlSeconds} disabled={!owner} onChange={(event) => setTtlSeconds(Number(event.target.value))}>
|
||||||
|
{ttlOptions.map((value) => <option key={value} value={value}>{ttlLabel(value)}</option>)}
|
||||||
<label className={styles.field}>
|
</select></label>
|
||||||
<span>受限文件下载次数</span>
|
<label className={styles.field}><span>受限文件下载次数</span>
|
||||||
<select value={fileMaxDownloads} disabled={!owner} onChange={(event) => setFileMaxDownloads(Number(event.target.value))}>
|
<select value={fileMaxDownloads} disabled={!owner} onChange={(event) => setFileMaxDownloads(Number(event.target.value))}>
|
||||||
{downloadOptions.map((value) => <option key={value} value={value}>{value === 0 ? '不限' : `${value} 次`}</option>)}
|
{downloadOptions.map((value) => <option key={value} value={value}>{value === 0 ? '不限' : `${value} 次`}</option>)}
|
||||||
</select>
|
</select></label>
|
||||||
</label>
|
<label className={styles.check}>
|
||||||
|
<input type="checkbox" checked={membersCanUpload} disabled={!owner} onChange={(event) => setMembersCanUpload(event.target.checked)} />
|
||||||
<label className={styles.check}>
|
<span>允许成员上传</span></label>
|
||||||
<input type="checkbox" checked={membersCanUpload} disabled={!owner} onChange={(event) => setMembersCanUpload(event.target.checked)} />
|
</> : null}
|
||||||
<span>允许成员上传</span>
|
{tab === 'join' ? <>
|
||||||
</label>
|
<label className={styles.field}><span>加入方式</span>
|
||||||
|
<select value={joinPolicy} disabled={!owner} onChange={(event) => setJoinPolicy(event.target.value as 'open' | 'invite')}>
|
||||||
<label className={styles.field}><span>加入方式</span>
|
<option value="open">登录后持链接加入</option><option value="invite">仅受邀账号加入</option>
|
||||||
<select value={joinPolicy} disabled={!owner} onChange={(event) => setJoinPolicy(event.target.value as 'open' | 'invite')}>
|
</select></label>
|
||||||
<option value="open">登录后持链接加入</option><option value="invite">仅受邀账号加入</option>
|
<label className={styles.field}><span>{channel.passwordRequired ? '更换加入密码' : '加入密码(可选)'}</span>
|
||||||
</select>
|
<input type="password" autoComplete="new-password" minLength={8} maxLength={256} value={joinPassword} disabled={!owner || clearPassword} placeholder="至少 8 个字符,留空不修改" onChange={(event) => setJoinPassword(event.target.value)} /></label>
|
||||||
</label>
|
{owner && channel.passwordRequired ? <label className={styles.check}>
|
||||||
<label className={styles.field}><span>{channel.passwordRequired ? '更换空间加入密码' : '空间加入密码(可选)'}</span>
|
<input type="checkbox" checked={clearPassword} onChange={(event) => setClearPassword(event.target.checked)} /><span>移除加入密码</span></label> : null}
|
||||||
<input type="password" autoComplete="new-password" minLength={8} maxLength={256} value={joinPassword} disabled={!owner || clearPassword} placeholder="至少 8 个字符,留空不修改" onChange={(event) => setJoinPassword(event.target.value)} />
|
<p className={styles.note}>空间主及受邀用户无需加入密码。修改规则不会移除已加入成员。</p>
|
||||||
<span className={styles.note}>空间主及受邀用户无需加入密码。修改规则不移除已加入成员。</span>
|
</> : null}
|
||||||
</label>
|
</section>
|
||||||
{owner && channel.passwordRequired ? <label className={styles.check}><input type="checkbox" checked={clearPassword} onChange={(event) => setClearPassword(event.target.checked)} /><span>移除空间加入密码</span></label> : null}
|
{owner ? (
|
||||||
<p className={styles.note}>成员与邀请请在右侧栏的「成员」页管理。</p>
|
<div className={styles.footer}>
|
||||||
{owner ? (
|
{failed ? <p className={styles.error} role="alert">保存失败,请检查名称和设置后重试。</p> : null}
|
||||||
<>
|
<Button variant="primary" disabled={saving || !dirty || invalid} onClick={() => void save()}>{saving ? '保存中…' : '保存'}</Button>
|
||||||
{failed ? <p className={styles.error} role="alert">保存失败,请检查名称和设置后重试。</p> : null}
|
</div>
|
||||||
<Button variant="primary" disabled={saving || maxMembers < 1 || maxMembers > info.limits.max_members || ttlSeconds < info.limits.min_ttl_seconds || ttlSeconds > info.limits.max_ttl_seconds || Boolean(joinPassword && joinPassword.length < 8)} onClick={() => void save()}>{saving ? '保存中…' : '保存设置'}</Button>
|
) : <p className={styles.note}>只有所有者可以修改空间设置。</p>}
|
||||||
</>
|
</div>
|
||||||
) : <p className={styles.note}>只有所有者可以修改空间设置。</p>}
|
|
||||||
</div>
|
</div>
|
||||||
</Sheet>
|
</Sheet>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user