Skip to content

Commit

Permalink
JS-4421: library usecase banner
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3orblade committed Apr 20, 2024
1 parent 6b4bbb0 commit 991bc1b
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/img/icon/header/banner/close.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icon/header/banner/pic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/json/text.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@
"pageMainStoreRelationsEmpty": "<b>Your Relation list is empty</b>Add some from the Anytype Library using the search icon or create your own using the button above",
"pageMainStoreMyTypes": "My Types",
"pageMainStoreMyRelations": "My Relations",
"pageMainStoreBannerTitle": "What can I build with Anytype?",
"pageMainStoreBannerButton": "Explore",

"pageMainTypeRecommendedLayout": "Recommended layout",
"pageMainTypeNewSetOfObjects": "New Set of Objects",
Expand Down
27 changes: 27 additions & 0 deletions src/scss/component/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@ html:not(.bodyIndexIndex):not(.bodyAuthSelect) {
.icon.btn-settings { background-image: url('~img/icon/dataview/button/settings.svg'); }
}

.header.mainStore.withBanner { flex-direction: column; height: auto !important; }
.header.mainStore.withBanner {
.sides { display: flex; flex-direction: row; align-items: center; justify-content: stretch; height: 52px; }

.bannerWrapper { width: 100%; padding: 16px 80px; }
.bannerWrapper {
.banner {
background-image: linear-gradient(180deg, #fef2c6 0%, #f8f8f8 100%); display: flex; align-items: center;
color: var(--color-control-accent); height: 116px; border-radius: 11px; position: relative; justify-content: space-evenly;
padding: 0px 116px; overflow: hidden;
}
.banner {
.side { width: calc(50% - 46px); }
.side.left { display: flex; flex-direction: column; padding: 0px; align-items: flex-start; justify-content: center; gap: 8px 0px; }
.side.right { min-width: 424px; }

.icon.close { position: absolute; width: 20px; height: 20px; background-image: url('~img/icon/header/banner/close.svg'); right: 10px; top: 10px; }
.title { @include text-header3; @include text-overflow-nw; width: 100%; }
.pic {
width: 100%; height: 100%; background: url('~img/icon/header/banner/pic.png') no-repeat; background-size: contain;
background-position: bottom right;
}
.button { @include text-small; height: 24px; line-height: 24px; }
}
}
}

.popup {
.header { position: sticky; padding: 0px; top: 0px !important; }
.header {
Expand Down
5 changes: 3 additions & 2 deletions src/scss/page/main/store.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@import "~scss/_vars";

.pageMainStore {
.content { height: 100%; padding-top: 40px; }
.wrapper.withBanner { padding-top: 200px; }


.body { display: flex; flex-direction: column; }
.body {
Expand Down Expand Up @@ -42,7 +43,7 @@
}

.loaderWrapper { position: relative !important; }
.ReactVirtualized__List { padding: 48px 80px 80px 80px; }
.ReactVirtualized__List { padding: 0px 80px 80px 80px; }

.emptySearch { padding: 56px 0px; border: 1px solid var(--color-shape-primary); border-radius: 12px; height: auto; @include text-paragraph; }
.emptySearch {
Expand Down
9 changes: 9 additions & 0 deletions src/scss/theme/dark/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ html.themeDark {
}
}

.header.mainStore.withBanner {
.bannerWrapper {
.banner { color: var(--color-text-inversion); }
.banner {
.button { background-color: var(--color-bg-primary); color: var(--color-text-primary); }
}
}
}

/* Sidebar */

.sidebar { background-color: var(--color-bg-secondary); box-shadow: 0px 4px 16px rgba(0,0,0,0.2); }
Expand Down
8 changes: 6 additions & 2 deletions src/ts/component/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ class Header extends React.Component<Props> {
};

render () {
const { component, className, rootId } = this.props;
const { component, className, withBanner } = this.props;
const Component = Components[component] || null;
const cn = [ 'header', component, className ];

if (![ 'authIndex', 'mainIndex' ].includes(component)) {
if (![ 'authIndex' ].includes(component)) {
cn.push('isCommon');
};

if (withBanner) {
cn.push('withBanner');
};

return (
<div id="header" className={cn.join(' ')} onDoubleClick={this.onDoubleClick}>
<Component
Expand Down
35 changes: 30 additions & 5 deletions src/ts/component/header/main/store.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
import * as React from 'react';
import { I } from 'Lib';
import { Title, Button, Icon } from 'Component';
import { I, translate } from 'Lib';

class HeaderMainStore extends React.Component<I.HeaderComponent> {

render () {
const { renderLeftIcons, renderTabs } = this.props;
const { renderLeftIcons, renderTabs, withBanner, onBanner, onBannerClose } = this.props;

let banner = null;
if (withBanner) {
banner = (
<div className="bannerWrapper">
<div className="banner" onClick={onBanner}>
<Icon className="close" onClick={onBannerClose} />

<div className="side left">
<Title text={translate('pageMainStoreBannerTitle')} />
<Button text={translate('pageMainStoreBannerButton')} className="c28" />
</div>

<div className="side right">
<div className="pic" />
</div>
</div>
</div>
);
};

return (
<React.Fragment>
<div className="side left">{renderLeftIcons()}</div>
<div className="side center">{renderTabs()}</div>
<div className="side right" />
{banner}

<div className="sides">
<div className="side left">{renderLeftIcons()}</div>
<div className="side center">{renderTabs()}</div>
<div className="side right" />
</div>
</React.Fragment>
);
};
Expand Down
41 changes: 32 additions & 9 deletions src/ts/component/page/main/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { observer } from 'mobx-react';
import { AutoSizer, CellMeasurer, InfiniteLoader, List, CellMeasurerCache, WindowScroller } from 'react-virtualized';
import { Title, Icon, IconObject, Header, Footer, Filter, Button, EmptySearch } from 'Component';
import { I, C, UtilData, UtilObject, UtilCommon, Storage, Onboarding, analytics, Action, keyboard, translate, UtilSpace } from 'Lib';
import { dbStore, blockStore, commonStore, menuStore } from 'Store';
import { dbStore, blockStore, commonStore, menuStore, popupStore } from 'Store';
import Constant from 'json/constant.json';

interface State {
loading: boolean;
isLoading: boolean;
withBanner: boolean;
};

enum View {
Expand All @@ -22,7 +23,8 @@ const alt = keyboard.altSymbol();
const PageMainStore = observer(class PageMainStore extends React.Component<I.PageComponent, State> {

state = {
loading: false,
isLoading: false,
withBanner: false,
};

_isMounted = false;
Expand Down Expand Up @@ -51,13 +53,16 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
this.onFilterBlur = this.onFilterBlur.bind(this);
this.onFilterClear = this.onFilterClear.bind(this);
this.onFilterClick = this.onFilterClick.bind(this);
this.onBanner = this.onBanner.bind(this);
this.onBannerClose = this.onBannerClose.bind(this);
};

render () {
if (!this.cache) {
return null;
};

const { withBanner } = this.state;
const canWrite = UtilSpace.canMyParticipantWrite();
const { isPopup } = this.props;
const views = this.getViews();
Expand Down Expand Up @@ -212,15 +217,18 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
return (
<div
ref={node => this.node = node}
className={[ 'wrapper', this.tab, this.view ].join(' ')}
className={[ 'wrapper', this.tab, this.view, (withBanner ? 'withBanner' : '') ].join(' ')}
>
<Header
{...this.props}
component="mainStore"
tabs={tabs}
tab={this.tab}
layout={I.ObjectLayout.Store}
onTab={id => this.onTab(id, true)}
onTab={id => this.onTab(id, true)}
withBanner={withBanner}
onBanner={this.onBanner}
onBannerClose={this.onBannerClose}
/>

<div className="body">
Expand Down Expand Up @@ -281,6 +289,7 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
this.resize();
this.rebind();
this.onTab(Storage.get('tabStore') || I.StoreTab.Type, false);
this.setState({ withBanner: !Storage.get('storeBannerClosed') });
};

componentDidUpdate () {
Expand Down Expand Up @@ -493,7 +502,7 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
};

if (clear) {
this.setState({ loading: true });
this.setState({ isLoading: true });
dbStore.recordsSet(Constant.subId.store, '', []);
};

Expand All @@ -506,7 +515,7 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
ignoreDeleted: true,
ignoreHidden: true,
}, (message: any) => {
this.setState({ loading: false });
this.setState({ isLoading: false });

if (callBack) {
callBack(message);
Expand All @@ -526,7 +535,7 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
};

getItems () {
const { loading } = this.state;
const { isLoading } = this.state;
const records = dbStore.getRecords(Constant.subId.store);
const limit = this.getLimit();

Expand All @@ -537,7 +546,7 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
let n = 0;
let row = { children: [] };

if (!loading && !records.length) {
if (!isLoading && !records.length) {
ret.push({ id: 'empty', className: 'block', children: [ { id: 'empty' } ] },);
};

Expand Down Expand Up @@ -634,6 +643,20 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
return Math.max(1, Math.min(5, limit));
};

onBanner () {
popupStore.closeAll(null, () => {
popupStore.open('usecase', {});
});
};

onBannerClose (e: any) {
e.stopPropagation();
e.preventDefault();

this.setState({ withBanner: false });
Storage.set('storeBannerClosed', true);
};

resize () {
const node = $(this.node);
const limit = this.getLimit();
Expand Down
3 changes: 3 additions & 0 deletions src/ts/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@ export interface HeaderComponent extends RouteComponentProps<any> {
tab?: string;
text?: string;
layout?: I.ObjectLayout;
withBanner?: boolean;
renderLeftIcons?: (onOpen?: () => void) => any;
renderTabs?: () => any;
onTab?: (id: string) => void;
onSearch?: () => void;
onTooltipShow?: (e: any, text: string, caption?: string) => void;
onTooltipHide?: () => void;
menuOpen?: (id: string, elementId: string, param: Partial<I.MenuParam>) => void;
onBanner?: (e: any) => void;
onBannerClose?: (e: any) => void;
};

export interface PageComponent extends RouteComponentProps<any> {
Expand Down

0 comments on commit 991bc1b

Please sign in to comment.