feat(ui): tags and some bugfixes

This commit is contained in:
sylenien 2022-09-29 18:04:14 +02:00 committed by Delirium
parent 65a4b1ca93
commit 2216e75659
7 changed files with 78 additions and 16 deletions

View file

@ -30,7 +30,7 @@ function NoteEvent(props: Props) {
const onEdit = () => {};
const onCopy = () => {
copy(`${session(props.sessionId)}${props.timestamp > 0 ? '?jumpto=' + props.timestamp : ''}`);
copy(`${window.location.origin}${session(props.sessionId)}${props.timestamp > 0 ? '?jumpto=' + props.timestamp : ''}`);
toast.success('Note URL copied to clipboard');
};
@ -70,7 +70,7 @@ function NoteEvent(props: Props) {
</div>
</div>
<div className="cursor-pointer ml-auto">
<ItemMenu bolt items={menuItems} />
<ItemMenu bold items={menuItems} />
</div>
</div>
<div>{props.message}</div>

View file

@ -4,17 +4,37 @@ import { sliceListPerPage } from 'App/utils';
import NoteItem from './NoteItem';
import { observer } from 'mobx-react-lite';
import { useStore } from 'App/mstore';
import { Note } from 'App/services/NotesService';
function NotesList({ members }: {members: Array<Record<string, any>>}) {
const { notesStore } = useStore()
const [list, setList] = React.useState<Note[]>([])
React.useEffect(() => {
if (!notesStore.notes.length) {
notesStore.fetchNotes()
notesStore.fetchNotes().then(notes => setList(notes))
}
}, [])
const list = notesStore.notes
React.useEffect(() => {
if (notesStore.notes.length) {
if (notesStore.activeTags.length) {
const tagsLen = notesStore.activeTags.length
const filteredList: Note[] = notesStore.notes.filter(note => {
for (let i = 0; i < tagsLen; i++) {
const tag = notesStore.activeTags[i]
if (note.tags.includes(tag)) {
return note
}
}
})
setList(filteredList)
} else {
setList(notesStore.notes)
}
}
}, [notesStore.activeTags])
return (
<NoContent
show={list.length === 0}

View file

@ -0,0 +1,25 @@
import React from 'react';
import { TAGS, iTag } from 'App/services/NotesService';
import { TagItem } from '../SessionTags';
import { useStore } from 'App/mstore';
import { observer } from 'mobx-react-lite';
function NoteTags() {
const { notesStore } = useStore()
return (
<div className="flex items-center">
{TAGS.map((tag: iTag) => (
<div key={tag}>
<TagItem
onClick={() => notesStore.toggleTag(tag)}
label={tag}
isActive={notesStore.activeTags.includes(tag)}
/>
</div>
))}
</div>
);
}
export default observer(NoteTags);

View file

@ -4,6 +4,7 @@ import { applyFilter } from 'Duck/search';
import Period from 'Types/app/period';
import SelectDateRange from 'Shared/SelectDateRange';
import SessionTags from '../SessionTags';
import NoteTags from '../Notes/NoteTags';
import { connect } from 'react-redux';
import SessionSort from '../SessionSort';
import cn from 'classnames';
@ -69,14 +70,21 @@ function SessionHeader(props: Props) {
</div>
</div>
{activeTab === 'all' && <div className="flex items-center">
<SessionTags />
<div className="mx-4" />
<SelectDateRange period={period} onChange={onDateChange} right={true} />
<div className="mx-2" />
<SessionSort />
<SessionSettingButton />
</div>}
{activeTab === 'all' && (
<div className="flex items-center">
<SessionTags />
<div className="mx-4" />
<SelectDateRange period={period} onChange={onDateChange} right={true} />
<div className="mx-2" />
<SessionSort />
<SessionSettingButton />
</div>
)}
{activeTab === 'notes' && (
<div className="flex items-center">
<NoteTags />
</div>
)}
</div>
);
}

View file

@ -47,7 +47,7 @@ export default connect(
}
)(SessionTags);
function TagItem({ isActive, onClick, label, icon = '', disabled = false }: any) {
export function TagItem({ isActive, onClick, label, icon = '', disabled = false }: any) {
return (
<div>
<button

View file

@ -1 +1 @@
export { default } from './SessionTags';
export { default, TagItem } from './SessionTags';

View file

@ -1,6 +1,6 @@
import { makeAutoObservable } from "mobx"
import { notesService } from "App/services"
import { Note, WriteNote } from 'App/services/NotesService'
import { Note, WriteNote, iTag } from 'App/services/NotesService'
interface SessionNotes {
[sessionId: string]: Note[]
@ -12,7 +12,7 @@ export default class NotesStore {
loading: boolean
page = 1
pageSize = 15
activeTags: iTag[] = []
constructor() {
makeAutoObservable(this)
@ -23,6 +23,7 @@ export default class NotesStore {
try {
const notes = await notesService.getNotes()
this.notes = notes;
return notes;
} catch (e) {
console.error(e)
} finally {
@ -70,4 +71,12 @@ export default class NotesStore {
changePage(page: number) {
this.page = page
}
toggleTag(tag: iTag) {
if (this.activeTags.includes(tag)) {
this.activeTags = this.activeTags.filter(exTag => tag !== exTag)
} else {
this.activeTags = [...this.activeTags, tag]
}
}
}