2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2019-06-28 19:00:29 +02:00
|
|
|
import React, { useState } from 'react';
|
2019-05-07 04:35:04 +02:00
|
|
|
import { parseURI } from 'lbry-redux';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Page from 'component/page';
|
2019-05-07 04:35:04 +02:00
|
|
|
import SubscribeButton from 'component/subscribeButton';
|
|
|
|
import ShareButton from 'component/shareButton';
|
|
|
|
import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'component/common/tabs';
|
|
|
|
import { withRouter } from 'react-router';
|
2019-06-28 19:00:29 +02:00
|
|
|
import Button from 'component/button';
|
2019-05-07 04:35:04 +02:00
|
|
|
import { formatLbryUriForWeb } from 'util/uri';
|
|
|
|
import ChannelContent from 'component/channelContent';
|
|
|
|
import ChannelAbout from 'component/channelAbout';
|
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
2019-07-02 19:54:42 +02:00
|
|
|
import ChannelEdit from 'component/channelEdit';
|
2019-06-28 19:00:29 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2019-05-07 04:35:04 +02:00
|
|
|
|
|
|
|
const PAGE_VIEW_QUERY = `view`;
|
|
|
|
const ABOUT_PAGE = `about`;
|
2017-05-04 05:44:08 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2019-05-07 04:35:04 +02:00
|
|
|
title: ?string,
|
|
|
|
cover: ?string,
|
|
|
|
thumbnail: ?string,
|
2019-05-14 07:12:24 +02:00
|
|
|
page: number,
|
2019-05-07 04:35:04 +02:00
|
|
|
location: { search: string },
|
2019-04-04 23:05:23 +02:00
|
|
|
history: { push: string => void },
|
2019-05-07 04:35:04 +02:00
|
|
|
match: { params: { attribute: ?string } },
|
2019-06-28 19:00:29 +02:00
|
|
|
channelIsMine: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
function ChannelPage(props: Props) {
|
2019-06-28 19:00:29 +02:00
|
|
|
const { uri, title, cover, history, location, page, channelIsMine, thumbnail } = props;
|
2019-05-07 04:35:04 +02:00
|
|
|
const { channelName, claimName, claimId } = parseURI(uri);
|
2019-03-28 17:53:13 +01:00
|
|
|
const { search } = location;
|
|
|
|
const urlParams = new URLSearchParams(search);
|
2019-05-07 04:35:04 +02:00
|
|
|
const currentView = urlParams.get(PAGE_VIEW_QUERY) || undefined;
|
2019-03-28 17:53:13 +01:00
|
|
|
|
2019-06-28 19:00:29 +02:00
|
|
|
const [editing, setEditing] = useState(false);
|
|
|
|
const [thumbPreview, setThumbPreview] = useState(thumbnail);
|
|
|
|
const [coverPreview, setCoverPreview] = useState(cover);
|
|
|
|
|
2019-05-07 04:35:04 +02:00
|
|
|
// If a user changes tabs, update the url so it stays on the same page if they refresh.
|
|
|
|
// We don't want to use links here because we can't animate the tab change and using links
|
|
|
|
// would alter the Tab label's role attribute, which should stay role="tab" to work with keyboards/screen readers.
|
2019-07-02 19:54:42 +02:00
|
|
|
const tabIndex = currentView === ABOUT_PAGE || editing ? 1 : 0;
|
2019-05-07 04:35:04 +02:00
|
|
|
const onTabChange = newTabIndex => {
|
|
|
|
let url = formatLbryUriForWeb(uri);
|
2019-05-14 07:12:24 +02:00
|
|
|
let search = '?';
|
2019-05-07 04:35:04 +02:00
|
|
|
if (newTabIndex !== 0) {
|
2019-05-14 07:12:24 +02:00
|
|
|
search += `${PAGE_VIEW_QUERY}=${ABOUT_PAGE}`;
|
|
|
|
} else {
|
|
|
|
search += `page=${page}`;
|
2017-08-24 23:12:23 +02:00
|
|
|
}
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2019-05-14 07:12:24 +02:00
|
|
|
history.push(`${url}${search}`);
|
2019-03-28 17:53:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2019-06-11 20:10:58 +02:00
|
|
|
<Page>
|
|
|
|
<div className="card">
|
|
|
|
<header className="channel-cover">
|
2019-06-28 19:00:29 +02:00
|
|
|
{!editing && cover && <img className="channel-cover__custom" src={cover} />}
|
|
|
|
{editing && <img className="channel-cover__custom" src={coverPreview} />}
|
|
|
|
{/* component that offers select/upload */}
|
|
|
|
<div className="channel__primary-info ">
|
|
|
|
{!editing && <ChannelThumbnail className="channel__thumbnail--channel-page" uri={uri} />}
|
|
|
|
{editing && (
|
|
|
|
<ChannelThumbnail
|
|
|
|
className="channel__thumbnail--channel-page"
|
|
|
|
uri={uri}
|
|
|
|
thumbnailPreview={thumbPreview}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<h1 className="channel__title">
|
|
|
|
{title || channelName}
|
|
|
|
{channelIsMine && !editing && (
|
2019-07-02 19:54:42 +02:00
|
|
|
<Button title={__('Edit')} onClick={() => setEditing(!editing)} icon={ICONS.EDIT} iconSize={49} />
|
2019-06-28 19:00:29 +02:00
|
|
|
)}
|
|
|
|
</h1>
|
|
|
|
<h2 className="channel__url">
|
|
|
|
{claimName}
|
|
|
|
{claimId && `#${claimId}`}
|
|
|
|
</h2>
|
2019-05-07 04:35:04 +02:00
|
|
|
</div>
|
2019-06-11 20:10:58 +02:00
|
|
|
</header>
|
2019-07-02 19:54:42 +02:00
|
|
|
<Tabs onChange={onTabChange} index={tabIndex}>
|
|
|
|
<TabList className="tabs__list--channel-page">
|
|
|
|
<Tab disabled={editing}>{__('Content')}</Tab>
|
|
|
|
<Tab>{editing ? __('Editing Your Channel') : __('About')}</Tab>
|
|
|
|
<div className="card__actions">
|
|
|
|
<ShareButton uri={uri} />
|
|
|
|
<SubscribeButton uri={uri} />
|
|
|
|
</div>
|
|
|
|
</TabList>
|
2019-03-28 17:53:13 +01:00
|
|
|
|
2019-07-02 19:54:42 +02:00
|
|
|
<TabPanels>
|
|
|
|
<TabPanel>
|
|
|
|
<ChannelContent uri={uri} />
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel>
|
|
|
|
{editing ? (
|
|
|
|
<ChannelEdit
|
|
|
|
uri={uri}
|
|
|
|
setEditing={setEditing}
|
|
|
|
updateThumb={v => setThumbPreview(v)}
|
|
|
|
updateCover={v => setCoverPreview(v)}
|
|
|
|
/>
|
|
|
|
) : (
|
2019-06-28 19:00:29 +02:00
|
|
|
<ChannelAbout uri={uri} />
|
2019-07-02 19:54:42 +02:00
|
|
|
)}
|
|
|
|
</TabPanel>
|
|
|
|
</TabPanels>
|
|
|
|
</Tabs>
|
2019-06-11 20:10:58 +02:00
|
|
|
</div>
|
2019-03-28 17:53:13 +01:00
|
|
|
</Page>
|
|
|
|
);
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
export default withRouter(ChannelPage);
|