Skip to content

Commit

Permalink
Merge pull request #2133 from Sefaria/feature/sc-29228/library-integr…
Browse files Browse the repository at this point in the history
…ating-notes-into-history-saved

Integrating Notes into History & Saved
  • Loading branch information
yitzhakc authored Dec 11, 2024
2 parents e8c713b + acfd76a commit a5e28ee
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 14 deletions.
5 changes: 5 additions & 0 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,11 @@ def user_history(request):
desc = _("See your user history on Sefaria")
return menu_page(request, props, page="history", title=title, desc=desc)

@login_required
def notes(request):
title = _("My Notes")
desc = _("See your notes on Sefaria")
return menu_page(request, page="notes", title=title, desc=desc)

@login_required
def user_stats(request):
Expand Down
1 change: 1 addition & 0 deletions sefaria/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
url(r'^$', reader_views.home, name="home"),
url(r'^texts/?$', reader_views.texts_list, name="table_of_contents"),
url(r'^texts/saved/?$', reader_views.saved),
url(r'^texts/notes/?$', reader_views.notes),
url(r'^texts/history/?$', reader_views.user_history),
url(r'^texts/recent/?$', reader_views.old_recent_redirect),
url(r'^texts/(?P<cats>.+)?$', reader_views.texts_category_list),
Expand Down
1 change: 1 addition & 0 deletions static/css/s2.css
Original file line number Diff line number Diff line change
Expand Up @@ -9180,6 +9180,7 @@ div.aboutSheetMetadata span:not(:first-child)::before{
.noteListing {
margin-bottom: 30px;
border-bottom: 1px solid #ccc;
padding-bottom: 10px;
}
.noteListing a:hover {
text-decoration: none;
Expand Down
3 changes: 3 additions & 0 deletions static/icons/notes-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 11 additions & 5 deletions static/js/NoteListing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import $ from './sefaria/sefariaJquery';
import Sefaria from './sefaria/sefaria';
import { AddToSourceSheetWindow } from './AddToSourceSheet';
import { Note } from './Misc';
import { Note, LoadingMessage } from './Misc';
import PropTypes from 'prop-types';
import Component from 'react-class';

Expand Down Expand Up @@ -59,11 +59,17 @@ class NoteListing extends Component {
}
NoteListing.propTypes = {
data: PropTypes.object.isRequired,
showText: PropTypes.bool,
onDeleteNote: PropTypes.func,
};
NoteListing.defaultProps = {
showText: true
};

const NotesList = ({notes}) => {
return (
notes && notes.length ?
notes.map((item, i) => (
<NoteListing data={item} key={i} />
))
: <LoadingMessage message="You haven't written any notes yet." heMessage="טרם הוספת רשומות משלך" />)};


export default NoteListing;
export { NotesList };
12 changes: 12 additions & 0 deletions static/js/ReaderApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ class ReaderApp extends Component {
hist.title = Sefaria._("My Reading History");
hist.url = "texts/history";
hist.mode = "history";
break;
case "notes":
hist.title = Sefaria._("My Notes");
hist.url = "texts/notes";
hist.mode = "notes";
break;
}
hist.url = addTab(hist.url)
} else if (state.mode === "Text") {
Expand Down Expand Up @@ -1131,6 +1137,9 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) {
} else if (path === "/texts/saved") {
this.showSaved();

} else if (path === "/texts/notes") {
this.showNotes();

} else if (path.match(/\/texts\/.+/)) {
this.showLibrary(path.slice(7).split("/"));

Expand Down Expand Up @@ -1757,6 +1766,9 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) {
showSaved() {
this.setSinglePanelState({menuOpen: "saved"});
}
showNotes() {
this.setSinglePanelState({menuOpen: "notes"});
}
showHistory() {
this.setSinglePanelState({menuOpen: "history"});
}
Expand Down
2 changes: 1 addition & 1 deletion static/js/ReaderPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ class ReaderPanel extends Component {
interfaceLang={this.props.interfaceLang} />
);

} else if (this.state.menuOpen === "saved" || this.state.menuOpen === "history") {
} else if (["saved", "history", "notes"].includes(this.state.menuOpen)) {
menu = (
<UserHistoryPanel
multiPanel={this.props.multiPanel}
Expand Down
40 changes: 32 additions & 8 deletions static/js/UserHistoryPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Component from 'react-class';
import Sefaria from './sefaria/sefaria';
import { useScrollToLoad } from "./Hooks";
import { NavSidebar } from './NavSidebar';
import { NotesList } from './NoteListing';
import {
SheetBlock,
TextPassage
Expand All @@ -21,9 +22,23 @@ import {


const UserHistoryPanel = ({menuOpen, toggleLanguage, openDisplaySettings, openNav, compare, toggleSignUpModal}) => {
const store = menuOpen === "saved" ? Sefaria.saved : Sefaria.userHistory;
const [notes, setNotes] = useState(null);
const contentRef = useRef();

useEffect(() => {
Sefaria.allPrivateNotes((data) => {
if (Array.isArray(data)) {
const flattenedNotes = data.map(note => ({
ref: note.ref,
text: note.text
}));
setNotes(flattenedNotes);
} else {
console.error("Unexpected data format:", data);
}
});
}, []);

const title = (
<span className="sans-serif">
<a href="/texts/saved" className={"navTitleTab" + (menuOpen === "saved" ? " current" : "")}>
Expand All @@ -34,6 +49,10 @@ const UserHistoryPanel = ({menuOpen, toggleLanguage, openDisplaySettings, openNa
<img src="/static/icons/clock.svg" />
<InterfaceText>History</InterfaceText>
</a>
<a href="/texts/notes" className={"navTitleTab" + (menuOpen === "notes" ? " current" : "")}>
<img src="/static/icons/notes-icon.svg" />
<InterfaceText>Notes</InterfaceText>
</a>
</span>
);

Expand All @@ -55,19 +74,24 @@ const UserHistoryPanel = ({menuOpen, toggleLanguage, openDisplaySettings, openNa
{Sefaria.interfaceLang !== "hebrew" && Sefaria._siteSettings.TORAH_SPECIFIC ?
<LanguageToggleButton toggleLanguage={toggleLanguage} /> : null}
</div>
<UserHistoryList
store={store}
scrollableRef={contentRef}
menuOpen={menuOpen}
toggleSignUpModal={toggleSignUpModal}
key={menuOpen}/>
{ menuOpen === "notes" ?
<NotesList notes={notes} />
:
<UserHistoryList
store={menuOpen === "saved" ? Sefaria.saved : Sefaria.userHistory}
scrollableRef={contentRef}
menuOpen={menuOpen}
toggleSignUpModal={toggleSignUpModal}
key={menuOpen}/>
}
</div>
<NavSidebar modules={sidebarModules} />
</div>
</div>
</div>
);
);
};

UserHistoryPanel.propTypes = {
toggleLanguage: PropTypes.func.isRequired,
openDisplaySettings: PropTypes.func.isRequired,
Expand Down

0 comments on commit a5e28ee

Please sign in to comment.