mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-23 09:42:56 +00:00
Merge branch 'master' of https://github.com/naturalcrit/homebrewery into change-metadata-ui-theme
This commit is contained in:
@@ -83,7 +83,7 @@ const insertTab = (view)=>{
|
|||||||
changes,
|
changes,
|
||||||
selection : EditorSelection.create(
|
selection : EditorSelection.create(
|
||||||
view.state.selection.ranges.map((range)=>EditorSelection.cursor(
|
view.state.selection.ranges.map((range)=>EditorSelection.cursor(
|
||||||
mappedChanges.changes.mapPos(range.from, 1) + 2
|
mappedChanges.changes.mapPos(range.from, -1) + 2
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -247,57 +247,57 @@ const Snippetbar = createReactClass({
|
|||||||
return (
|
return (
|
||||||
<div className='editors'>
|
<div className='editors'>
|
||||||
{this.props.view !== 'meta' && <><div className='historyTools'>
|
{this.props.view !== 'meta' && <><div className='historyTools'>
|
||||||
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
<button className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
||||||
onClick={this.toggleHistoryMenu} >
|
onClick={this.toggleHistoryMenu} >
|
||||||
<i className='fas fa-clock-rotate-left' />
|
<i className='fas fa-clock-rotate-left' />
|
||||||
{ this.state.showHistory && this.renderHistoryItems() }
|
{ this.state.showHistory && this.renderHistoryItems() }
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTool undo ${this.props.historySize.done ? 'active' : ''}`}
|
<button className={`editorTool undo ${this.props.historySize.done ? 'active' : ''}`}
|
||||||
onClick={this.props.undo} >
|
onClick={this.props.undo} >
|
||||||
<i className='fas fa-undo' />
|
<i className='fas fa-undo' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTool redo ${this.props.historySize.undone ? 'active' : ''}`}
|
<button className={`editorTool redo ${this.props.historySize.undone ? 'active' : ''}`}
|
||||||
onClick={this.props.redo} >
|
onClick={this.props.redo} >
|
||||||
<i className='fas fa-redo' />
|
<i className='fas fa-redo' />
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className='codeTools'>
|
<div className='codeTools'>
|
||||||
<div className={`editorTool foldAll ${this.props.foldCode ? 'active' : ''}`}
|
<button className={`editorTool foldAll ${this.props.foldCode ? 'active' : ''}`}
|
||||||
onClick={this.props.foldCode} >
|
onClick={this.props.foldCode} >
|
||||||
<i className='fas fa-compress-alt' />
|
<i className='fas fa-compress-alt' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTool unfoldAll ${this.props.unfoldCode ? 'active' : ''}`}
|
<button className={`editorTool unfoldAll ${this.props.unfoldCode ? 'active' : ''}`}
|
||||||
onClick={this.props.unfoldCode} >
|
onClick={this.props.unfoldCode} >
|
||||||
<i className='fas fa-expand-alt' />
|
<i className='fas fa-expand-alt' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTool formatCode ${this.props.formatCode ? 'active' : ''}`}
|
<button className={`editorTool formatCode ${this.props.formatCode ? 'active' : ''}`}
|
||||||
onClick={this.props.formatCode} >
|
onClick={this.props.formatCode} >
|
||||||
<i className='fas fa-wand-magic-sparkles' />
|
<i className='fas fa-wand-magic-sparkles' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
<button className={`editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
||||||
onClick={this.toggleThemeSelector} >
|
onClick={this.toggleThemeSelector} >
|
||||||
<i className='fas fa-palette' />
|
<i className='fas fa-palette' />
|
||||||
{this.state.themeSelector && this.renderThemeSelector()}
|
{this.state.themeSelector && this.renderThemeSelector()}
|
||||||
</div>
|
</button>
|
||||||
</div></>}
|
</div></>}
|
||||||
|
|
||||||
<div className='tabs'>
|
<div className='tabs'>
|
||||||
<div className={cx('text', { selected: this.props.view === 'text' })}
|
<button className={cx('text', { selected: this.props.view === 'text' })}
|
||||||
onClick={()=>this.props.onViewChange('text')}>
|
onClick={()=>this.props.onViewChange('text')}>
|
||||||
<i className='fa fa-beer' />
|
<i className='fa fa-beer' />
|
||||||
</div>
|
</button>
|
||||||
<div className={cx('style', { selected: this.props.view === 'style' })}
|
<button className={cx('style', { selected: this.props.view === 'style' })}
|
||||||
onClick={()=>this.props.onViewChange('style')}>
|
onClick={()=>this.props.onViewChange('style')}>
|
||||||
<i className='fa fa-paint-brush' />
|
<i className='fa fa-paint-brush' />
|
||||||
</div>
|
</button>
|
||||||
<div className={cx('snippet', { selected: this.props.view === 'snippet' })}
|
<button className={cx('snippet', { selected: this.props.view === 'snippet' })}
|
||||||
onClick={()=>this.props.onViewChange('snippet')}>
|
onClick={()=>this.props.onViewChange('snippet')}>
|
||||||
<i className='fas fa-th-list' />
|
<i className='fas fa-th-list' />
|
||||||
</div>
|
</button>
|
||||||
<div className={cx('meta', { selected: this.props.view === 'meta' })}
|
<button className={cx('meta', { selected: this.props.view === 'meta' })}
|
||||||
onClick={()=>this.props.onViewChange('meta')}>
|
onClick={()=>this.props.onViewChange('meta')}>
|
||||||
<i className='fas fa-info-circle' />
|
<i className='fas fa-info-circle' />
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
position : relative;
|
position : relative;
|
||||||
display : flex;
|
display : flex;
|
||||||
flex-wrap : wrap-reverse;
|
flex-wrap : wrap-reverse;
|
||||||
|
reading-flow : flex-visual;
|
||||||
justify-content : space-between;
|
justify-content : space-between;
|
||||||
height : auto;
|
height : auto;
|
||||||
color : var(--textColor);
|
color : var(--textColor);
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
min-width : 275px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
min-width : 275px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
||||||
font-size: .85rem;
|
font-size: .85rem;
|
||||||
&:only-child {min-width : unset; margin-left : auto;}
|
&:only-child {min-width : unset; margin-left : auto;}
|
||||||
|
reading-order : 2;
|
||||||
|
|
||||||
>div {
|
>div {
|
||||||
display : flex;
|
display : flex;
|
||||||
@@ -36,7 +38,7 @@
|
|||||||
|
|
||||||
&:first-child { border-left : none; }
|
&:first-child { border-left : none; }
|
||||||
|
|
||||||
& > div {
|
& > button {
|
||||||
position : relative;
|
position : relative;
|
||||||
width : @menuHeight;
|
width : @menuHeight;
|
||||||
height : @menuHeight;
|
height : @menuHeight;
|
||||||
@@ -136,6 +138,7 @@
|
|||||||
display : flex;
|
display : flex;
|
||||||
justify-content : flex-start;
|
justify-content : flex-start;
|
||||||
min-width : 565.95px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
min-width : 565.95px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
||||||
|
reading-order : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// removed caret for top level items, by request (makes buttons too wide).
|
// removed caret for top level items, by request (makes buttons too wide).
|
||||||
@@ -223,10 +226,12 @@
|
|||||||
flex : 1;
|
flex : 1;
|
||||||
justify-content : space-between;
|
justify-content : space-between;
|
||||||
border-bottom : 1px solid;
|
border-bottom : 1px solid;
|
||||||
|
reading-order : 1;
|
||||||
}
|
}
|
||||||
.snippets {
|
.snippets {
|
||||||
flex : 1;
|
flex : 1;
|
||||||
justify-content : space-evenly;
|
justify-content : space-evenly;
|
||||||
|
reading-order : 2;
|
||||||
}
|
}
|
||||||
.editors > div.history > .dropdown { right : unset; }
|
.editors > div.history > .dropdown { right : unset; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
import './listPage.less';
|
import './listPage.less';
|
||||||
import React from 'react';
|
import React, { useEffect, useState, useRef, useMemo } from 'react';
|
||||||
import createReactClass from 'create-react-class';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import BrewItem from './brewItem/brewItem.jsx';
|
import BrewItem from './brewItem/brewItem.jsx';
|
||||||
|
|
||||||
@@ -14,132 +13,116 @@ const USERPAGE_GROUP_VISIBILITY_PREFIX = 'HB_listPage_visibility_group';
|
|||||||
const DEFAULT_SORT_TYPE = 'alpha';
|
const DEFAULT_SORT_TYPE = 'alpha';
|
||||||
const DEFAULT_SORT_DIR = 'asc';
|
const DEFAULT_SORT_DIR = 'asc';
|
||||||
|
|
||||||
const ListPage = createReactClass({
|
const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navItems = <></>, reportError = null, query })=>{
|
||||||
displayName : 'ListPage',
|
const [filterString, setFilterString] = useState(query?.filter || '');
|
||||||
getDefaultProps : function() {
|
const [filterTags, setFilterTags] = useState([]);
|
||||||
return {
|
const [sortType, setSortType] = useState(query?.sort || null);
|
||||||
brewCollection : [
|
const [sortDir, setSortDir] = useState(query?.dir || null);
|
||||||
{
|
const [groupVisibility, setGroupVisibility] = useState({});
|
||||||
title : '',
|
|
||||||
class : '',
|
const groupVisibilityRef = useRef(groupVisibility);
|
||||||
brews : []
|
const sortTypeRef = useRef(sortType);
|
||||||
}
|
const sortDirRef = useRef(sortDir);
|
||||||
],
|
|
||||||
navItems : <></>,
|
useEffect(()=>{
|
||||||
reportError : null
|
groupVisibilityRef.current = groupVisibility;
|
||||||
|
}, [groupVisibility]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
sortTypeRef.current = sortType;
|
||||||
|
}, [sortType]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
sortDirRef.current = sortDir;
|
||||||
|
}, [sortDir]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
window.onbeforeunload = saveToLocalStorage;
|
||||||
|
if(typeof window === 'undefined') return;
|
||||||
|
|
||||||
|
const newSortType = sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE);
|
||||||
|
const newSortDir = sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR);
|
||||||
|
updateUrl(filterString, newSortType, newSortDir);
|
||||||
|
|
||||||
|
const namedBrewCollection = brewCollection.reduce((visibility, brewGroup)=>{
|
||||||
|
visibility[brewGroup.class] = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true') == 'true';
|
||||||
|
return visibility;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
setGroupVisibility(namedBrewCollection);
|
||||||
|
setSortType(newSortType);
|
||||||
|
setSortDir(newSortDir);
|
||||||
|
|
||||||
|
return ()=>{
|
||||||
|
window.onbeforeunload = null;
|
||||||
};
|
};
|
||||||
},
|
}, []);
|
||||||
getInitialState : function() {
|
|
||||||
// HIDE ALL GROUPS UNTIL LOADED
|
const saveToLocalStorage = ()=>{
|
||||||
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
brewCollection.forEach((brewGroup)=>{
|
||||||
brewGroup.visible = false;
|
localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`, `${groupVisibilityRef.current[brewGroup.class]}`);
|
||||||
return brewGroup;
|
|
||||||
});
|
});
|
||||||
|
localStorage.setItem(USERPAGE_SORT_TYPE, sortTypeRef.current);
|
||||||
|
localStorage.setItem(USERPAGE_SORT_DIR, sortDirRef.current);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
const renderBrews = (brews)=>{
|
||||||
filterString : this.props.query?.filter || '',
|
|
||||||
filterTags : [],
|
|
||||||
sortType : this.props.query?.sort || null,
|
|
||||||
sortDir : this.props.query?.dir || null,
|
|
||||||
query : this.props.query,
|
|
||||||
brewCollection : brewCollection
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidMount : function() {
|
|
||||||
// SAVE TO LOCAL STORAGE WHEN LEAVING PAGE
|
|
||||||
window.onbeforeunload = this.saveToLocalStorage;
|
|
||||||
|
|
||||||
// LOAD FROM LOCAL STORAGE
|
|
||||||
if(typeof window !== 'undefined') {
|
|
||||||
const newSortType = (this.state.sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE));
|
|
||||||
const newSortDir = (this.state.sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR));
|
|
||||||
this.updateUrl(this.state.filterString, newSortType, newSortDir);
|
|
||||||
|
|
||||||
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
|
||||||
brewGroup.visible = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true')=='true';
|
|
||||||
return brewGroup;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
brewCollection : brewCollection,
|
|
||||||
sortType : newSortType,
|
|
||||||
sortDir : newSortDir
|
|
||||||
});
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount : function() {
|
|
||||||
window.onbeforeunload = function(){};
|
|
||||||
},
|
|
||||||
|
|
||||||
saveToLocalStorage : function() {
|
|
||||||
this.state.brewCollection.map((brewGroup)=>{
|
|
||||||
localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`, `${brewGroup.visible}`);
|
|
||||||
});
|
|
||||||
localStorage.setItem(USERPAGE_SORT_TYPE, this.state.sortType);
|
|
||||||
localStorage.setItem(USERPAGE_SORT_DIR, this.state.sortDir);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderBrews : function(brews){
|
|
||||||
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
||||||
|
|
||||||
return _.map(brews, (brew, idx)=>{
|
return _.map(brews, (brew, idx)=>(
|
||||||
return <BrewItem brew={brew} key={idx} reportError={this.props.reportError} updateListFilter={ (tag)=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}/>;
|
<BrewItem
|
||||||
});
|
brew={brew}
|
||||||
},
|
key={idx}
|
||||||
|
reportError={reportError}
|
||||||
|
updateListFilter={(tag)=>{
|
||||||
|
updateUrl(filterString, sortType, sortDir, tag);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
sortBrewOrder : function(brew){
|
const sortBrewOrder = (brew)=>{
|
||||||
if(!brew.title){brew.title = 'No Title';}
|
const title = brew.title || 'No Title';
|
||||||
const mapping = {
|
const mapping = {
|
||||||
'alpha' : _.deburr(brew.title.trim().toLowerCase()),
|
'alpha' : _.deburr(title.trim().toLowerCase()),
|
||||||
'created' : moment(brew.createdAt).format(),
|
'created' : moment(brew.createdAt).format(),
|
||||||
'updated' : moment(brew.updatedAt).format(),
|
'updated' : moment(brew.updatedAt).format(),
|
||||||
'views' : brew.views,
|
'views' : brew.views,
|
||||||
'latest' : moment(brew.lastViewed).format()
|
'latest' : moment(brew.lastViewed).format(),
|
||||||
};
|
};
|
||||||
return mapping[this.state.sortType];
|
return mapping[sortType];
|
||||||
},
|
};
|
||||||
|
|
||||||
handleSortOptionChange : function(event){
|
const handleSortOptionChange = (event)=>{
|
||||||
this.updateUrl(this.state.filterString, event.target.value, this.state.sortDir);
|
updateUrl(filterString, event.target.value, sortDir);
|
||||||
this.setState({
|
setSortType(event.target.value);
|
||||||
sortType : event.target.value
|
};
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSortDirChange : function(event){
|
const handleSortDirChange = (event)=>{
|
||||||
const newDir = this.state.sortDir == 'asc' ? 'desc' : 'asc';
|
const newDir = sortDir == 'asc' ? 'desc' : 'asc';
|
||||||
|
|
||||||
this.updateUrl(this.state.filterString, this.state.sortType, newDir);
|
updateUrl(filterString, sortType, newDir);
|
||||||
this.setState({
|
setSortDir(newDir);
|
||||||
sortDir : newDir
|
};
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
renderSortOption : function(sortTitle, sortValue){
|
const renderSortOption = (sortTitle, sortValue)=>{
|
||||||
return <div className={`sort-option ${(this.state.sortType == sortValue ? 'active' : '')}`}>
|
return (
|
||||||
<button
|
<div className={`sort-option ${sortType == sortValue ? 'active' : ''}`}>
|
||||||
value={`${sortValue}`}
|
<button value={`${sortValue}`} onClick={sortType == sortValue ? handleSortDirChange : handleSortOptionChange}>
|
||||||
onClick={this.state.sortType == sortValue ? this.handleSortDirChange : this.handleSortOptionChange}
|
{`${sortTitle}`}
|
||||||
>
|
</button>
|
||||||
{`${sortTitle}`}
|
{sortType == sortValue && <i className={`sortDir fas ${sortDir == 'asc' ? 'fa-sort-up' : 'fa-sort-down'}`}></i>}
|
||||||
</button>
|
</div>
|
||||||
{this.state.sortType == sortValue &&
|
);
|
||||||
<i className={`sortDir fas ${this.state.sortDir == 'asc' ? 'fa-sort-up' : 'fa-sort-down'}`}></i>
|
};
|
||||||
}
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
handleFilterTextChange : function(e){
|
const handleFilterTextChange = (e)=>{
|
||||||
this.setState({
|
setFilterString(e.target.value);
|
||||||
filterString : e.target.value,
|
updateUrl(e.target.value, sortType, sortDir);
|
||||||
});
|
|
||||||
this.updateUrl(e.target.value, this.state.sortType, this.state.sortDir);
|
|
||||||
return;
|
return;
|
||||||
},
|
};
|
||||||
|
|
||||||
updateUrl : function(filterTerm, sortType, sortDir, filterTag=''){
|
const updateUrl = (filterTerm, sortType, sortDir, filterTag = '')=>{
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams(url.search);
|
const urlParams = new URLSearchParams(url.search);
|
||||||
|
|
||||||
@@ -148,135 +131,162 @@ const ListPage = createReactClass({
|
|||||||
|
|
||||||
let filterTags = urlParams.getAll('tag');
|
let filterTags = urlParams.getAll('tag');
|
||||||
if(filterTag != '') {
|
if(filterTag != '') {
|
||||||
if(filterTags.findIndex((tag)=>{return tag.toLowerCase()==filterTag.toLowerCase();}) == -1){
|
if(
|
||||||
|
filterTags.findIndex((tag)=>{
|
||||||
|
return tag.toLowerCase() == filterTag.toLowerCase();
|
||||||
|
}) == -1
|
||||||
|
) {
|
||||||
filterTags.push(filterTag);
|
filterTags.push(filterTag);
|
||||||
} else {
|
} else {
|
||||||
filterTags = filterTags.filter((tag)=>{ return tag.toLowerCase() != filterTag.toLowerCase(); });
|
filterTags = filterTags.filter((tag)=>{
|
||||||
|
return tag.toLowerCase() != filterTag.toLowerCase();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
urlParams.delete('tag');
|
urlParams.delete('tag');
|
||||||
// Add tags to URL in the order they were clicked
|
// Add tags to URL in the order they were clicked
|
||||||
filterTags.forEach((tag)=>{ urlParams.append('tag', tag); });
|
filterTags.forEach((tag)=>urlParams.append('tag', tag));
|
||||||
// Sort tags before updating state
|
// Sort tags before updating state
|
||||||
filterTags.sort((a, b)=>{
|
filterTags.sort((a, b)=>{
|
||||||
return a.indexOf(':') - b.indexOf(':') != 0 ? a.indexOf(':') - b.indexOf(':') : a.toLowerCase().localeCompare(b.toLowerCase());
|
return a.indexOf(':') - b.indexOf(':') != 0 ? a.indexOf(':') - b.indexOf(':') : a.toLowerCase().localeCompare(b.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
setFilterTags(filterTags);
|
||||||
filterTags
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!filterTerm)
|
if(!filterTerm) urlParams.delete('filter');
|
||||||
urlParams.delete('filter');
|
else urlParams.set('filter', filterTerm);
|
||||||
else
|
|
||||||
urlParams.set('filter', filterTerm);
|
|
||||||
|
|
||||||
url.search = urlParams;
|
url.search = urlParams;
|
||||||
window.history.replaceState(null, null, url);
|
window.history.replaceState(null, null, url);
|
||||||
},
|
};
|
||||||
|
|
||||||
renderFilterOption : function(){
|
const renderFilterOption = ()=>{
|
||||||
return <div className='filter-option'>
|
return (
|
||||||
<label>
|
<div className='filter-option'>
|
||||||
<i className='fas fa-search'></i>
|
<label>
|
||||||
<input
|
<i className='fas fa-search'></i>
|
||||||
type='search'
|
<input type='search' placeholder='filter title/description/tags' onChange={handleFilterTextChange} value={filterString} />
|
||||||
placeholder='filter title/description'
|
</label>
|
||||||
onChange={this.handleFilterTextChange}
|
</div>
|
||||||
value={this.state.filterString}
|
);
|
||||||
/>
|
};
|
||||||
</label>
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderTagsOptions : function(){
|
const renderTagsOptions = ()=>{
|
||||||
if(this.state.filterTags?.length == 0) return;
|
if(filterTags?.length == 0) return;
|
||||||
return <div className='tags-container'>
|
return (
|
||||||
{_.map(this.state.filterTags, (tag, idx)=>{
|
<div className='tags-container'>
|
||||||
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
{_.map(filterTags, (tag, idx)=>{
|
||||||
return <span key={idx} className={matches[1]} onClick={()=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}>{matches[2]}</span>;
|
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
||||||
})}
|
return (
|
||||||
</div>;
|
<span
|
||||||
},
|
key={idx}
|
||||||
|
className={matches[1]}
|
||||||
|
onClick={()=>{
|
||||||
|
updateUrl(filterString, sortType, sortDir, tag);
|
||||||
|
}}>
|
||||||
|
{matches[2]}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
renderSortOptions : function(){
|
const renderSortOptions = ()=>{
|
||||||
return <div className='sort-container'>
|
return (
|
||||||
<h6>Sort by :</h6>
|
<div className='sort-container'>
|
||||||
{this.renderSortOption('Title', 'alpha')}
|
<h6>Sort by :</h6>
|
||||||
{this.renderSortOption('Created Date', 'created')}
|
{renderSortOption('Title', 'alpha')}
|
||||||
{this.renderSortOption('Updated Date', 'updated')}
|
{renderSortOption('Created Date', 'created')}
|
||||||
{this.renderSortOption('Views', 'views')}
|
{renderSortOption('Updated Date', 'updated')}
|
||||||
{/* {this.renderSortOption('Latest', 'latest')} */}
|
{renderSortOption('Views', 'views')}
|
||||||
|
{/* {renderSortOption('Latest', 'latest')} */}
|
||||||
|
{renderFilterOption()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
{this.renderFilterOption()}
|
const getSortedBrews = (brews)=>{
|
||||||
</div>;
|
const testString = _.deburr(filterString).toLowerCase();
|
||||||
},
|
|
||||||
|
|
||||||
getSortedBrews : function(brews){
|
|
||||||
const testString = _.deburr(this.state.filterString).toLowerCase();
|
|
||||||
|
|
||||||
brews = _.filter(brews, (brew)=>{
|
brews = _.filter(brews, (brew)=>{
|
||||||
// Filter by user entered text
|
// Filter by user entered text
|
||||||
const brewStrings = _.deburr([
|
const brewStrings = _.deburr([brew.title, brew.description, brew.tags].join('\n').toLowerCase());
|
||||||
brew.title,
|
|
||||||
brew.description,
|
|
||||||
brew.tags].join('\n')
|
|
||||||
.toLowerCase());
|
|
||||||
|
|
||||||
const filterTextTest = brewStrings.includes(testString);
|
const filterTextTest = brewStrings.includes(testString);
|
||||||
|
|
||||||
// Filter by user selected tags
|
// Filter by user selected tags
|
||||||
let filterTagTest = true;
|
let filterTagTest = true;
|
||||||
if(this.state.filterTags.length > 0){
|
if(filterTags.length > 0) {
|
||||||
filterTagTest = Array.isArray(brew.tags) && this.state.filterTags?.every((tag)=>{
|
filterTagTest =
|
||||||
return brew.tags.findIndex((brewTag)=>{
|
Array.isArray(brew.tags) &&
|
||||||
return brewTag.toLowerCase() == tag.toLowerCase();
|
filterTags?.every((tag)=>{
|
||||||
}) >= 0;
|
return (
|
||||||
});
|
brew.tags.findIndex((brewTag)=>{
|
||||||
|
return brewTag.toLowerCase() == tag.toLowerCase();
|
||||||
|
}) >= 0
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterTextTest && filterTagTest;
|
return filterTextTest && filterTagTest;
|
||||||
});
|
});
|
||||||
|
|
||||||
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
|
return _.orderBy(
|
||||||
},
|
brews,
|
||||||
|
(brew)=>{
|
||||||
|
return sortBrewOrder(brew);
|
||||||
|
},
|
||||||
|
sortDir,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
toggleBrewCollectionState : function(brewGroupClass) {
|
const sortedBrewCollection = useMemo(()=>{
|
||||||
this.setState((prevState)=>({
|
return brewCollection.map((brewGroup)=>({ ...brewGroup, brews: getSortedBrews(brewGroup.brews) }));
|
||||||
brewCollection : prevState.brewCollection.map(
|
}, [brewCollection, filterString, filterTags, sortType, sortDir]);
|
||||||
(brewGroup)=>brewGroup.class === brewGroupClass ? { ...brewGroup, visible: !brewGroup.visible } : brewGroup
|
|
||||||
)
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
|
|
||||||
renderBrewCollection : function(brewCollection){
|
const toggleBrewCollectionState = (brewGroupClass)=>{
|
||||||
if(brewCollection == []) return <div className='brewCollection'>
|
setGroupVisibility((prevVisibility)=>({ ...prevVisibility, [brewGroupClass]: !prevVisibility[brewGroupClass] }));
|
||||||
<h1>No Brews</h1>
|
};
|
||||||
</div>;
|
|
||||||
|
const renderBrewCollection = (brewCollection)=>{
|
||||||
|
if(brewCollection.length === 0)
|
||||||
|
return (
|
||||||
|
<div className='brewCollection'>
|
||||||
|
<h1>No Brews</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
return _.map(brewCollection, (brewGroup, idx)=>{
|
return _.map(brewCollection, (brewGroup, idx)=>{
|
||||||
return <div key={idx} className={`brewCollection ${brewGroup.class ?? ''}`}>
|
const sortedBrewGroup = sortedBrewCollection[idx];
|
||||||
<h1 className={brewGroup.visible ? 'active' : 'inactive'} onClick={()=>{this.toggleBrewCollectionState(brewGroup.class);}}>{brewGroup.title || 'No Title'}</h1>
|
const visible = groupVisibility[brewGroup.class];
|
||||||
{brewGroup.visible ? this.renderBrews(this.getSortedBrews(brewGroup.brews)) : <></>}
|
|
||||||
</div>;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
return (
|
||||||
return <div className='listPage sitePage'>
|
<div key={idx} className={`brewCollection ${brewGroup.class ?? ''}`}>
|
||||||
{/*<style>@layer V3_5ePHB, bundle;</style>*/}
|
<h1
|
||||||
<link href='/themes/V3/Blank/style.css' type='text/css' rel='stylesheet'/>
|
className={visible ? 'active' : 'inactive'}
|
||||||
<link href='/themes/V3/5ePHB/style.css' type='text/css' rel='stylesheet'/>
|
onClick={()=>{
|
||||||
{this.props.navItems}
|
toggleBrewCollectionState(brewGroup.class);
|
||||||
{this.renderSortOptions()}
|
}}>
|
||||||
{this.renderTagsOptions()}
|
{brewGroup.title || 'No Title'}
|
||||||
|
</h1>
|
||||||
|
{visible ? renderBrews(sortedBrewGroup.brews) : <></>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='listPage sitePage'>
|
||||||
|
<link href='/themes/V3/Blank/style.css' type='text/css' rel='stylesheet' />
|
||||||
|
<link href='/themes/V3/5ePHB/style.css' type='text/css' rel='stylesheet' />
|
||||||
|
{navItems}
|
||||||
|
{renderSortOptions()}
|
||||||
|
{renderTagsOptions()}
|
||||||
|
|
||||||
<div className='content V3'>
|
<div className='content V3'>
|
||||||
<div className='page'>
|
<div className='page'>{renderBrewCollection(brewCollection)}</div>
|
||||||
{this.renderBrewCollection(this.state.brewCollection)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
export default ListPage;
|
export default ListPage;
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ const EditPage = (props)=>{
|
|||||||
const [themeBundle, setThemeBundle] = useState({});
|
const [themeBundle, setThemeBundle] = useState({});
|
||||||
const [unsavedChanges, setUnsavedChanges] = useState(false);
|
const [unsavedChanges, setUnsavedChanges] = useState(false);
|
||||||
const [alertTrashedGoogleBrew, setAlertTrashedGoogleBrew] = useState(props.brew.trashed);
|
const [alertTrashedGoogleBrew, setAlertTrashedGoogleBrew] = useState(props.brew.trashed);
|
||||||
const [alertLoginToTransfer, setAlertLoginToTransfer] = useState(false);
|
const [alertNoGoogleToTransfer, setAlertNoGoogleToTransfer] = useState(false);
|
||||||
|
const [alertOwnershipToTransfer, setAlertOwnershipToTransfer] = useState(false);
|
||||||
const [confirmGoogleTransfer, setConfirmGoogleTransfer] = useState(false);
|
const [confirmGoogleTransfer, setConfirmGoogleTransfer] = useState(false);
|
||||||
const [autoSaveEnabled, setAutoSaveEnabled] = useState(true);
|
const [autoSaveEnabled, setAutoSaveEnabled] = useState(true);
|
||||||
const [warnUnsavedChanges, setWarnUnsavedChanges] = useState(true);
|
const [warnUnsavedChanges, setWarnUnsavedChanges] = useState(true);
|
||||||
@@ -105,7 +106,7 @@ const EditPage = (props)=>{
|
|||||||
};
|
};
|
||||||
return ()=>{
|
return ()=>{
|
||||||
document.removeEventListener('keydown', handleControlKeys);
|
document.removeEventListener('keydown', handleControlKeys);
|
||||||
window.onBeforeUnload = null;
|
window.onbeforeunload = null;
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -162,8 +163,12 @@ const EditPage = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleGoogleClick = ()=>{
|
const handleGoogleClick = ()=>{
|
||||||
|
if(global.account !== currentBrew.authors[0]) {
|
||||||
|
setalertOwnershipToTransfer(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!global.account?.googleId) {
|
if(!global.account?.googleId) {
|
||||||
setAlertLoginToTransfer(true);
|
setAlertNoGoogleToTransfer(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,11 +179,13 @@ const EditPage = (props)=>{
|
|||||||
const closeAlerts = (e)=>{
|
const closeAlerts = (e)=>{
|
||||||
e.stopPropagation(); //Only handle click once so alert doesn't reopen
|
e.stopPropagation(); //Only handle click once so alert doesn't reopen
|
||||||
setAlertTrashedGoogleBrew(false);
|
setAlertTrashedGoogleBrew(false);
|
||||||
setAlertLoginToTransfer(false);
|
setAlertNoGoogleToTransfer(false);
|
||||||
setConfirmGoogleTransfer(false);
|
setConfirmGoogleTransfer(false);
|
||||||
|
setalertOwnershipToTransfer(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleGoogleStorage = ()=>{
|
const toggleGoogleStorage = (e)=>{
|
||||||
|
closeAlerts(e);
|
||||||
const newSaveGoogle = !saveGoogle;
|
const newSaveGoogle = !saveGoogle;
|
||||||
setSaveGoogle((prev)=>!prev);
|
setSaveGoogle((prev)=>!prev);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -260,32 +267,42 @@ const EditPage = (props)=>{
|
|||||||
<Nav.item className='googleDriveStorage' onClick={handleGoogleClick}>
|
<Nav.item className='googleDriveStorage' onClick={handleGoogleClick}>
|
||||||
<img src={googleDriveIcon} className={saveGoogle ? '' : 'inactive'} alt='Google Drive icon' />
|
<img src={googleDriveIcon} className={saveGoogle ? '' : 'inactive'} alt='Google Drive icon' />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{alertOwnershipToTransfer && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
You must be the Owner to transfer between the Homebrewery and Google Drive!
|
||||||
|
The owner of this file is {currentBrew.authors[0]}
|
||||||
|
<div className='confirm' onClick={closeAlerts}> Okay </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{alertNoGoogleToTransfer && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
You must be signed in to a Google account to transfer between the Homebrewery and Google Drive!
|
||||||
|
<a target='_blank' rel='noopener noreferrer' href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}>
|
||||||
|
<div className='confirm' onClick={closeAlerts}> Sign In </div>
|
||||||
|
</a>
|
||||||
|
<div className='deny' onClick={closeAlerts}> Not Now </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{alertTrashedGoogleBrew && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
This brew is currently in your Trash folder on Google Drive!<br />
|
||||||
|
If you want to keep it, make sure to move it before it is deleted permanently!<br />
|
||||||
|
<div className='confirm' onClick={toggleGoogleStorage}> Save my brew </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{confirmGoogleTransfer && (
|
{confirmGoogleTransfer && (
|
||||||
<div className='errorContainer' onClick={closeAlerts}>
|
<div className='errorContainer'>
|
||||||
{saveGoogle
|
{saveGoogle
|
||||||
? 'Would you like to transfer this brew from your Google Drive storage back to the Homebrewery?'
|
? 'Would you like to transfer this brew from your Google Drive storage back to the Homebrewery?'
|
||||||
: 'Would you like to transfer this brew from the Homebrewery to your personal Google Drive storage?'}
|
: 'Would you like to transfer this brew from the Homebrewery to your personal Google Drive storage?'}
|
||||||
<br />
|
<br />
|
||||||
<div className='confirm' onClick={toggleGoogleStorage}> Yes </div>
|
<div className='confirm' onClick={toggleGoogleStorage}> Yes </div>
|
||||||
<div className='deny'> No </div>
|
<div className='deny' onClick={closeAlerts}> No </div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{alertLoginToTransfer && (
|
|
||||||
<div className='errorContainer' onClick={closeAlerts}>
|
|
||||||
You must be signed in to a Google account to transfer between the homebrewery and Google Drive!
|
|
||||||
<a target='_blank' rel='noopener noreferrer' href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}>
|
|
||||||
<div className='confirm'> Sign In </div>
|
|
||||||
</a>
|
|
||||||
<div className='deny'> Not Now </div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{alertTrashedGoogleBrew && (
|
|
||||||
<div className='errorContainer' onClick={closeAlerts}>
|
|
||||||
This brew is currently in your Trash folder on Google Drive!<br />
|
|
||||||
If you want to keep it, make sure to move it before it is deleted permanently!<br />
|
|
||||||
<div className='confirm'> OK </div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
|
|||||||
Generated
+345
-345
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user