Browse Source

可选允许搜索

pull/6/head
hole-thu 4 years ago
parent
commit
3fa49b9ad6
  1. 12
      src/Config.js
  2. 5
      src/Flows.js
  3. 4
      src/Message.js
  4. 2
      src/Title.js
  5. 1
      src/UserAction.css
  6. 24
      src/UserAction.js

12
src/Config.js

@ -3,8 +3,10 @@ import React, { PureComponent } from 'react';
import './Config.css'; import './Config.css';
const BUILTIN_IMGS = { const BUILTIN_IMGS = {
'https://www.tsinghua.edu.cn/images/footer.jpg': 'https://cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages/static/bg/gbp.jpg':
'清华紫(默认)', '怀旧背景(默认)',
'https://www.tsinghua.edu.cn/image/nav-bg.jpg':
'清华紫',
'https://cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages/static/bg/gbp.jpg': 'https://cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages/static/bg/gbp.jpg':
'寻觅繁星', '寻觅繁星',
'https://cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages/static/bg/eriri.jpg': 'https://cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages/static/bg/eriri.jpg':
@ -23,7 +25,7 @@ const BUILTIN_IMGS = {
const DEFAULT_CONFIG = { const DEFAULT_CONFIG = {
background_img: background_img:
'https://www.tsinghua.edu.cn/images/footer.jpg', '//cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages/static/bg/gbp.jpg',
background_color: '#113366', background_color: '#113366',
pressure: false, pressure: false,
easter_egg: true, easter_egg: true,
@ -452,10 +454,10 @@ export class ConfigUI extends PureComponent {
<p> <p>
新功能建议或问题反馈请在&nbsp; 新功能建议或问题反馈请在&nbsp;
<a <a
href="https://github.com/newthuhole/hole-backend/issues" href="https://git.thu.monster/newthuhole/hole_thu_backend/issues"
target="_blank" target="_blank"
> >
GitHub <span className="icon icon-github" /> Gitea
</a> </a>
&nbsp;提出 &nbsp;提出
</p> </p>

5
src/Flows.js

@ -271,6 +271,9 @@ class FlowItem extends PureComponent {
</div> </div>
) )
} }
{
info.allow_search && <span> 📢 </span>
}
<Time stamp={info.timestamp} short={!img_clickable} /> <Time stamp={info.timestamp} short={!img_clickable} />
</div> </div>
<div className="box-content"> <div className="box-content">
@ -1170,7 +1173,7 @@ export class Flow extends PureComponent {
})); }));
}) })
.catch(failed); .catch(failed);
} else if (this.state.mode === 'search') { } else if (this.state.mode === 'search' && this.state.search_param) {
API.get_search(page, this.state.search_param, this.props.token) API.get_search(page, this.state.search_param, this.props.token)
.then((json) => { .then((json) => {
const finished = json.data.length === 0; const finished = json.data.length === 0;

4
src/Message.js

@ -1,5 +1,5 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Time } from './Common'; import { Time, API_BASE } from './Common';
import { get_json } from './infrastructure/functions'; import { get_json } from './infrastructure/functions';
import './Message.css'; import './Message.css';
@ -26,7 +26,7 @@ export class MessageViewer extends PureComponent {
}, },
() => { () => {
fetch( fetch(
'/_api/v1/systemlog', API_BASE + '/systemlog',
{ {
headers: {'User-Token': this.props.token}, headers: {'User-Token': this.props.token},
} }

2
src/Title.js

@ -136,7 +136,7 @@ class ControlBar extends PureComponent {
className="control-search" className="control-search"
value={this.state.search_text} value={this.state.search_text}
placeholder={ placeholder={
this.props.mode === 'attention' ? '在关注列表中搜索' : '搜tag或 #树洞号, 如: 新手导引'} this.props.mode === 'attention' ? '在关注列表中搜索' : '关键词 / tag / #树洞号'}
onChange={this.on_change_bound} onChange={this.on_change_bound}
onKeyPress={this.on_keypress_bound} onKeyPress={this.on_keypress_bound}
/> />

1
src/UserAction.css

@ -40,6 +40,7 @@
.post-form-bar label { .post-form-bar label {
flex: 1; flex: 1;
margin: 0 0.5rem;
} }
.post-form-bar input[type=file] { .post-form-bar input[type=file] {

24
src/UserAction.js

@ -24,7 +24,7 @@ const MAX_IMG_DIAM = 8000;
const MAX_IMG_PX = 5000000; const MAX_IMG_PX = 5000000;
const MAX_IMG_FILESIZE = 450000 * BASE64_RATE; const MAX_IMG_FILESIZE = 450000 * BASE64_RATE;
const REPOSITORY = 'https://github.com/newthuhole'; const REPOSITORY = 'https://git.thu.monster/newthuhole/';
const EMAIL = '[email protected]'; const EMAIL = '[email protected]';
export const TokenCtx = React.createContext({ export const TokenCtx = React.createContext({
@ -99,7 +99,7 @@ export function InfoSidebar(props) {
</a> </a>
协议在{' '} 协议在{' '}
<a href={REPOSITORY} target="_blank"> <a href={REPOSITORY} target="_blank">
GitHub Gitea
</a>{' '} </a>{' '}
开源 开源
</p> </p>
@ -260,6 +260,7 @@ export class ReplyForm extends Component {
on_submit(event) { on_submit(event) {
if (event) event.preventDefault(); if (event) event.preventDefault();
if (this.state.loading_status === 'loading') return; if (this.state.loading_status === 'loading') return;
if (!this.state.text) return;
this.setState({ this.setState({
loading_status: 'loading', loading_status: 'loading',
}); });
@ -362,6 +363,7 @@ export class PostForm extends Component {
this.state = { this.state = {
text: '', text: '',
cw: '', cw: '',
allow_search: false,
loading_status: 'done', loading_status: 'done',
img_tip: null, img_tip: null,
preview: false, preview: false,
@ -369,6 +371,7 @@ export class PostForm extends Component {
this.img_ref = React.createRef(); this.img_ref = React.createRef();
this.area_ref = React.createRef(); this.area_ref = React.createRef();
this.on_change_bound = this.on_change.bind(this); this.on_change_bound = this.on_change.bind(this);
this.on_allow_search_change_bound = this.on_allow_search_change.bind(this);
this.on_cw_change_bound = this.on_cw_change.bind(this); this.on_cw_change_bound = this.on_cw_change.bind(this);
this.on_img_change_bound = this.on_img_change.bind(this); this.on_img_change_bound = this.on_img_change.bind(this);
this.color_picker = new ColorPicker(); this.color_picker = new ColorPicker();
@ -378,6 +381,12 @@ export class PostForm extends Component {
if (this.area_ref.current) this.area_ref.current.focus(); if (this.area_ref.current) this.area_ref.current.focus();
} }
on_allow_search_change(event) {
this.setState({
allow_search: event.target.checked,
});
}
on_cw_change(event) { on_cw_change(event) {
this.setState({ this.setState({
cw: event.target.value, cw: event.target.value,
@ -394,6 +403,7 @@ export class PostForm extends Component {
let data = new URLSearchParams(); let data = new URLSearchParams();
data.append('cw', this.state.cw); data.append('cw', this.state.cw);
data.append('text', this.state.text); data.append('text', this.state.text);
data.append('allow_search', this.state.allow_search ? '1' : '');
data.append('type', img ? 'image' : 'text'); data.append('type', img ? 'image' : 'text');
if (img) data.append('data', img); if (img) data.append('data', img);
@ -547,6 +557,7 @@ export class PostForm extends Component {
on_submit(event) { on_submit(event) {
if (event) event.preventDefault(); if (event) event.preventDefault();
if (this.state.loading_status === 'loading') return; if (this.state.loading_status === 'loading') return;
if (!this.state.text) return;
/* /*
if (this.img_ref.current.files.length) { if (this.img_ref.current.files.length) {
this.setState({ this.setState({
@ -628,6 +639,15 @@ export class PostForm extends Component {
&nbsp;发表 &nbsp;发表
</button> </button>
)} )}
<label>
<input
type="checkbox"
onChange={this.on_allow_search_change_bound}
/>
允许被搜索
</label>
</div> </div>
{!!this.state.img_tip && ( {!!this.state.img_tip && (
<p className="post-form-img-tip"> <p className="post-form-img-tip">

Loading…
Cancel
Save