mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-29 06:15:29 -04:00
Restructure repository (#426)
organized repository Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Philip Molares <git@molar.es>
This commit is contained in:
parent
66258ca615
commit
0fadc09f2b
254 changed files with 384 additions and 403 deletions
|
@ -1,23 +0,0 @@
|
|||
import { getMe } from '../api/me'
|
||||
import { setUser } from '../redux/user/methods'
|
||||
import { store } from './store'
|
||||
|
||||
export const getAndSetUser: () => (Promise<void>) = async () => {
|
||||
const me = await getMe()
|
||||
setUser({
|
||||
id: me.id,
|
||||
name: me.name,
|
||||
photo: me.photo,
|
||||
provider: me.provider
|
||||
})
|
||||
}
|
||||
|
||||
export const getApiUrl = (): string => {
|
||||
return store.getState().apiUrl.apiUrl
|
||||
}
|
||||
|
||||
export const expectResponseCode = (response: Response, code = 200): void => {
|
||||
if (response.status !== code) {
|
||||
throw new Error(`response code is not ${code}`)
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { BaseEmoji, CustomEmoji, EmojiData } from 'emoji-mart'
|
||||
|
||||
export const getEmojiIcon = (emoji: EmojiData):string => {
|
||||
if ((emoji as BaseEmoji).native) {
|
||||
return (emoji as BaseEmoji).native
|
||||
} else if ((emoji as CustomEmoji).imageUrl) {
|
||||
// noinspection CheckTagEmptyBody
|
||||
return `<i class="fa ${(emoji as CustomEmoji).name}"></i>`
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
export const getEmojiShortCode = (emoji: EmojiData):string => {
|
||||
return (emoji as BaseEmoji).colons
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
import moment from 'moment'
|
||||
import { SortModeEnum } from '../components/common/sort-button/sort-button'
|
||||
import {
|
||||
HistoryEntry,
|
||||
HistoryEntryOrigin,
|
||||
HistoryJson,
|
||||
LocatedHistoryEntry
|
||||
} from '../components/landing/pages/history/history'
|
||||
import { HistoryToolbarState } from '../components/landing/pages/history/history-toolbar/history-toolbar'
|
||||
|
||||
export function collectEntries (localEntries: HistoryEntry[], remoteEntries: HistoryEntry[]): LocatedHistoryEntry[] {
|
||||
const locatedLocalEntries = locateEntries(localEntries, HistoryEntryOrigin.LOCAL)
|
||||
const locatedRemoteEntries = locateEntries(remoteEntries, HistoryEntryOrigin.REMOTE)
|
||||
return mergeEntryArrays(locatedLocalEntries, locatedRemoteEntries)
|
||||
}
|
||||
|
||||
export function sortAndFilterEntries (entries: LocatedHistoryEntry[], toolbarState: HistoryToolbarState): LocatedHistoryEntry[] {
|
||||
const filteredBySelectedTagsEntries = filterBySelectedTags(entries, toolbarState.selectedTags)
|
||||
const filteredByKeywordSearchEntries = filterByKeywordSearch(filteredBySelectedTagsEntries, toolbarState.keywordSearch)
|
||||
return sortEntries(filteredByKeywordSearchEntries, toolbarState)
|
||||
}
|
||||
|
||||
function locateEntries (entries: HistoryEntry[], location: HistoryEntryOrigin): LocatedHistoryEntry[] {
|
||||
return entries.map(entry => {
|
||||
return {
|
||||
...entry,
|
||||
location: location
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function mergeEntryArrays<T extends HistoryEntry> (localEntries: T[], remoteEntries: T[]): T[] {
|
||||
const filteredLocalEntries = localEntries.filter(localEntry => {
|
||||
const entry = remoteEntries.find(remoteEntry => remoteEntry.id === localEntry.id)
|
||||
return !entry
|
||||
})
|
||||
|
||||
return filteredLocalEntries.concat(remoteEntries)
|
||||
}
|
||||
|
||||
function filterBySelectedTags (entries: LocatedHistoryEntry[], selectedTags: string[]): LocatedHistoryEntry[] {
|
||||
return entries.filter(entry => {
|
||||
return (selectedTags.length === 0 || arrayCommonCheck(entry.tags, selectedTags))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function arrayCommonCheck<T> (array1: T[], array2: T[]): boolean {
|
||||
const foundElement = array1.find((element1) =>
|
||||
array2.find((element2) =>
|
||||
element2 === element1
|
||||
)
|
||||
)
|
||||
return !!foundElement
|
||||
}
|
||||
|
||||
function filterByKeywordSearch (entries: LocatedHistoryEntry[], keywords: string): LocatedHistoryEntry[] {
|
||||
const searchTerm = keywords.toLowerCase()
|
||||
return entries.filter(entry => entry.title.toLowerCase().indexOf(searchTerm) !== -1)
|
||||
}
|
||||
|
||||
function sortEntries (entries: LocatedHistoryEntry[], viewState: HistoryToolbarState): LocatedHistoryEntry[] {
|
||||
return entries.sort((firstEntry, secondEntry) => {
|
||||
if (firstEntry.pinned && !secondEntry.pinned) {
|
||||
return -1
|
||||
}
|
||||
if (!firstEntry.pinned && secondEntry.pinned) {
|
||||
return 1
|
||||
}
|
||||
|
||||
if (viewState.titleSortDirection !== SortModeEnum.no) {
|
||||
return firstEntry.title.localeCompare(secondEntry.title) * viewState.titleSortDirection
|
||||
}
|
||||
|
||||
if (viewState.lastVisitedSortDirection !== SortModeEnum.no) {
|
||||
if (firstEntry.lastVisited > secondEntry.lastVisited) {
|
||||
return 1 * viewState.lastVisitedSortDirection
|
||||
}
|
||||
if (firstEntry.lastVisited < secondEntry.lastVisited) {
|
||||
return -1 * viewState.lastVisitedSortDirection
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
export function formatHistoryDate (date: Date): string {
|
||||
return moment(date).format('llll')
|
||||
}
|
||||
|
||||
export interface V1HistoryEntry {
|
||||
id: string;
|
||||
text: string;
|
||||
time: number;
|
||||
tags: string[];
|
||||
pinned: boolean;
|
||||
}
|
||||
|
||||
export function convertV1History (oldHistory: V1HistoryEntry[]): HistoryEntry[] {
|
||||
return oldHistory.map((entry: V1HistoryEntry) => {
|
||||
return {
|
||||
id: entry.id,
|
||||
title: entry.text,
|
||||
lastVisited: moment(entry.time).toDate(),
|
||||
tags: entry.tags,
|
||||
pinned: entry.pinned
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function loadHistoryFromLocalStore (): HistoryEntry[] {
|
||||
const historyJsonString = window.localStorage.getItem('history')
|
||||
|
||||
if (!historyJsonString) {
|
||||
// if localStorage["history"] is empty we check the old localStorage["notehistory"]
|
||||
// and convert it to the new format
|
||||
const oldHistoryJsonString = window.localStorage.getItem('notehistory')
|
||||
const oldHistory = oldHistoryJsonString ? JSON.parse(JSON.parse(oldHistoryJsonString)) as V1HistoryEntry[] : []
|
||||
return convertV1History(oldHistory)
|
||||
} else {
|
||||
return JSON.parse(historyJsonString) as HistoryEntry[]
|
||||
}
|
||||
}
|
||||
|
||||
export function setHistoryToLocalStore (entries: HistoryEntry[]): void {
|
||||
window.localStorage.setItem('history', JSON.stringify(entries))
|
||||
}
|
||||
|
||||
export function downloadHistory (dataObject: HistoryJson): void {
|
||||
const data = 'data:text/json;charset=utf-8;base64,' + Buffer.from(JSON.stringify(dataObject)).toString('base64')
|
||||
const downloadLink = document.createElement('a')
|
||||
downloadLink.setAttribute('href', data)
|
||||
downloadLink.setAttribute('download', `history_${(new Date()).getTime()}.json`)
|
||||
document.body.appendChild(downloadLink)
|
||||
downloadLink.click()
|
||||
downloadLink.remove()
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export const slugify = (url:string) => {
|
||||
return encodeURIComponent(String(url).trim().toLowerCase().replace(/\s+/g, '-'))
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
import { createStore } from 'redux'
|
||||
import { allReducers } from '../redux'
|
||||
|
||||
export const store = createStore(allReducers)
|
Loading…
Add table
Add a link
Reference in a new issue