diff --git a/public/locales/ar.json b/public/locales/ar.json index 59c5c1db3..b7f967438 100644 --- a/public/locales/ar.json +++ b/public/locales/ar.json @@ -25,7 +25,7 @@ "Import history": "استيراد التاريخ", "Clear history": "مسح التاريخ", "Refresh history": "حدث التاريخ", - "No history": "ليس هناك سِجِل", + "noHistory": "ليس هناك سِجِل", "Import from browser": "استيراد من المتصفح", "releases": "إصدارات", "Are you sure?": "هل أنت واثق؟", diff --git a/public/locales/ca.json b/public/locales/ca.json index 276fa49a5..a0bc835ff 100644 --- a/public/locales/ca.json +++ b/public/locales/ca.json @@ -25,7 +25,7 @@ "Import history": "Importar historial", "Clear history": "Borrar historial", "Refresh history": "Actualitzar historial", - "No history": "Cap historial", + "noHistory": "Cap historial", "Import from browser": "Importar del navegador", "releases": "Versions", "Are you sure?": "Estas segur?", diff --git a/public/locales/cs.json b/public/locales/cs.json index dbf1af43b..9993af1c5 100644 --- a/public/locales/cs.json +++ b/public/locales/cs.json @@ -25,7 +25,7 @@ "Import history": "Importovat historii", "Clear history": "Odstranit historii", "Refresh history": "Aktualizovat historii", - "No history": "Žádná historie", + "noHistory": "Žádná historie", "Import from browser": "Importovat z prohlížeče", "releases": "Vydání", "Are you sure?": "Jste si jisti?", diff --git a/public/locales/da.json b/public/locales/da.json index 82a8e60ae..0f79ee827 100644 --- a/public/locales/da.json +++ b/public/locales/da.json @@ -25,7 +25,7 @@ "Import history": "Importér historik", "Clear history": "Ryd hsitorik", "Refresh history": "Genindlæs historik", - "No history": "Ingen historik", + "noHistory": "Ingen historik", "Import from browser": "Importér fra browser", "releases": "Releases", "Are you sure?": "Er du sikker?", diff --git a/public/locales/de.json b/public/locales/de.json index 21b49f4f6..de2618195 100644 --- a/public/locales/de.json +++ b/public/locales/de.json @@ -25,7 +25,7 @@ "Import history": "Verlauf importieren", "Clear history": "Verlauf löschen", "Refresh history": "Verlauf aktualisieren", - "No history": "Kein Verlauf", + "noHistory": "Kein Verlauf", "Import from browser": "Vom Browser importieren", "releases": "Versionen", "Are you sure?": "Sind Sie sicher?", diff --git a/public/locales/el.json b/public/locales/el.json index bc4b8af1a..e6c28ceda 100644 --- a/public/locales/el.json +++ b/public/locales/el.json @@ -25,7 +25,7 @@ "Import history": "Εισαγωγή ιστορίας", "Clear history": "Καθαρισμός Ιστορίας", "Refresh history": "Ανανέωση ιστορίας", - "No history": "Δεν υπάρχει ιστορία", + "noHistory": "Δεν υπάρχει ιστορία", "Import from browser": "Εισαγωγή απο τον περιηγητή", "releases": "Κυκλοφορίες", "Are you sure?": "Είστε σίγουρος?", diff --git a/public/locales/en.json b/public/locales/en.json index 69f465c13..e6ce4ac35 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -25,7 +25,7 @@ "Import history": "Import history", "Clear history": "Clear history", "Refresh history": "Refresh history", - "No history": "No history", + "noHistory": "No history", "Import from browser": "Import from browser", "releases": "Releases", "Are you sure?": "Are you sure?", diff --git a/public/locales/eo.json b/public/locales/eo.json index fc6edd5f8..a768afe82 100644 --- a/public/locales/eo.json +++ b/public/locales/eo.json @@ -25,7 +25,7 @@ "Import history": "Alportu historion", "Clear history": "Malplenigu historion", "Refresh history": "Refreŝigu historion", - "No history": "Neniu historio", + "noHistory": "Neniu historio", "Import from browser": "Alportu de retumilo", "releases": "Eldonoj", "Are you sure?": "Ĉu vi certas?", diff --git a/public/locales/es.json b/public/locales/es.json index 07f1882a0..7ad270795 100644 --- a/public/locales/es.json +++ b/public/locales/es.json @@ -25,7 +25,7 @@ "Import history": "Importar historial", "Clear history": "Borrar historial", "Refresh history": "Actualizar historial", - "No history": "Ningún historial", + "noHistory": "Ningún historial", "Import from browser": "Importar del navegador", "releases": "Versiones", "Are you sure?": "¿Estás seguro?", diff --git a/public/locales/fr.json b/public/locales/fr.json index c65179a59..edc49848d 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -25,7 +25,7 @@ "Import history": "Importer l'historique", "Clear history": "Effacer l'historique", "Refresh history": "Actualiser l'historique", - "No history": "Pas d'historique", + "noHistory": "Pas d'historique", "Import from browser": "Importer depuis le navigateur", "releases": "Versions", "Are you sure?": "Ëtes-vous sûr ?", diff --git a/public/locales/hi.json b/public/locales/hi.json index f470dab07..367a7d83e 100644 --- a/public/locales/hi.json +++ b/public/locales/hi.json @@ -25,7 +25,7 @@ "Import history": "इतिहास को आयात करें", "Clear history": "इतिहास मिटा दें", "Refresh history": "इतिहास ताज़ा करे", - "No history": "इतिहास न रखें", + "noHistory": "इतिहास न रखें", "Import from browser": "ब्राउज़र से आयात", "releases": "विज्ञप्ति", "Are you sure?": "क्या आपको यकीन है?", diff --git a/public/locales/hr.json b/public/locales/hr.json index 2cdd42b91..908a46c38 100644 --- a/public/locales/hr.json +++ b/public/locales/hr.json @@ -25,7 +25,7 @@ "Import history": "Uvezi povijest", "Clear history": "Očisti povijest", "Refresh history": "Osvježi povijest", - "No history": "Nema povijesti", + "noHistory": "Nema povijesti", "Import from browser": "Uvezi iz preglednika", "releases": "Izdanja", "Are you sure?": "Jeste li sigurni?", diff --git a/public/locales/id.json b/public/locales/id.json index f6ee9d096..4c3ced340 100644 --- a/public/locales/id.json +++ b/public/locales/id.json @@ -25,7 +25,7 @@ "Import history": "Impor Riwayat", "Clear history": "Bersihkan Riwayat", "Refresh history": "Muat-ulang Riwayat", - "No history": "Tidak ada riwayat", + "noHistory": "Tidak ada riwayat", "Import from browser": "Impor dari browser", "releases": "Penerbitan", "Are you sure?": "Apakah anda yakin?", diff --git a/public/locales/it.json b/public/locales/it.json index 717d753ae..5fe8b398b 100644 --- a/public/locales/it.json +++ b/public/locales/it.json @@ -25,7 +25,7 @@ "Import history": "Importa cronologia", "Clear history": "Cancella cronologia", "Refresh history": "Aggiorna cronologia", - "No history": "Nessuna cronologia", + "noHistory": "Nessuna cronologia", "Import from browser": "Importa da browser", "releases": "Versioni", "Are you sure?": "Sei sicuro?", diff --git a/public/locales/ja.json b/public/locales/ja.json index a1de80f90..4bb6f26bd 100644 --- a/public/locales/ja.json +++ b/public/locales/ja.json @@ -25,7 +25,7 @@ "Import history": "履歴をインポート", "Clear history": "履歴をクリア", "Refresh history": "履歴を更新", - "No history": "履歴はありません", + "noHistory": "履歴はありません", "Import from browser": "ブラウザからインポート", "releases": "リリース", "Are you sure?": "本当にいいですか?", diff --git a/public/locales/ko.json b/public/locales/ko.json index 020cd477b..7acbcc150 100644 --- a/public/locales/ko.json +++ b/public/locales/ko.json @@ -25,7 +25,7 @@ "Import history": "기록 불러오기", "Clear history": "기록 초기화", "Refresh history": "기록 새로고침", - "No history": "기록 없음", + "noHistory": "기록 없음", "Import from browser": "브라우저에서 불러오기", "releases": "릴리즈", "Are you sure?": "확실합니까?", diff --git a/public/locales/nl.json b/public/locales/nl.json index c64cccded..e5bc1f358 100644 --- a/public/locales/nl.json +++ b/public/locales/nl.json @@ -25,7 +25,7 @@ "Import history": "Importeer geschiedenis", "Clear history": "Verwijder geschiedenis", "Refresh history": "Ververs geschiedenis", - "No history": "Geen geschidenis gevonden", + "noHistory": "Geen geschidenis gevonden", "Import from browser": "Importeer van browser", "releases": "Versies", "Are you sure?": "Weet je het zeker?", diff --git a/public/locales/pl.json b/public/locales/pl.json index 461fbce96..7d83ad4cf 100644 --- a/public/locales/pl.json +++ b/public/locales/pl.json @@ -25,7 +25,7 @@ "Import history": "Importuj historię", "Clear history": "Wyczyść historię", "Refresh history": "Odśwież historię", - "No history": "Brak historii", + "noHistory": "Brak historii", "Import from browser": "Importuj z przeglądarki", "releases": "Wydania", "Are you sure?": "Jesteś pewny?", diff --git a/public/locales/pt.json b/public/locales/pt.json index 481fe0721..8bb357cc1 100644 --- a/public/locales/pt.json +++ b/public/locales/pt.json @@ -25,7 +25,7 @@ "Import history": "Importar histórico", "Clear history": "Apagar histórico", "Refresh history": "Atualizar histórico", - "No history": "Nenhum histórico", + "noHistory": "Nenhum histórico", "Import from browser": "Importar do navegador", "releases": "Lançamentos", "Are you sure?": "Tem certeza?", diff --git a/public/locales/ru.json b/public/locales/ru.json index 3e025fb97..5c3f0b854 100644 --- a/public/locales/ru.json +++ b/public/locales/ru.json @@ -25,7 +25,7 @@ "Import history": "Импорт истории", "Clear history": "Очистить историю", "Refresh history": "Обновить историю", - "No history": "Нет истории", + "noHistory": "Нет истории", "Import from browser": "Импорт из браузера", "releases": "Релизы", "Are you sure?": "Вы уверены?", diff --git a/public/locales/sk.json b/public/locales/sk.json index 893ca59cf..3afff194a 100644 --- a/public/locales/sk.json +++ b/public/locales/sk.json @@ -25,7 +25,7 @@ "Import history": "Importovať históriu", "Clear history": "Odstrániť históriu", "Refresh history": "Aktualizovať históriu", - "No history": "Žiadna história", + "noHistory": "Žiadna história", "Import from browser": "Importovať z prehliadača", "releases": "Vydania", "Are you sure?": "Ste si istý?", diff --git a/public/locales/sr.json b/public/locales/sr.json index ddc43f3d5..4c409fef6 100644 --- a/public/locales/sr.json +++ b/public/locales/sr.json @@ -25,7 +25,7 @@ "Import history": "Увези историјат", "Clear history": "Очисти историју", "Refresh history": "Освежи историју", - "No history": "Нема историје", + "noHistory": "Нема историје", "Import from browser": "Увези из прегледача", "releases": "Издања", "Are you sure?": "Јесте ли сигурни?", diff --git a/public/locales/sv.json b/public/locales/sv.json index 917aae4a1..4ce285763 100644 --- a/public/locales/sv.json +++ b/public/locales/sv.json @@ -25,7 +25,7 @@ "Import history": "Importhistorik", "Clear history": "Rensa historik", "Refresh history": "Uppdatera historik", - "No history": "Ingen historik", + "noHistory": "Ingen historik", "Import from browser": "Importera från webbläsare", "releases": "Lanseringar", "Are you sure?": "Är du säker?", diff --git a/public/locales/tr.json b/public/locales/tr.json index 492c126a8..be610eabb 100644 --- a/public/locales/tr.json +++ b/public/locales/tr.json @@ -25,7 +25,7 @@ "Import history": "Geçmişi içe aktar", "Clear history": "Geçmişi temizle", "Refresh history": "Geçmişi yenile", - "No history": "Geçmiş yok", + "noHistory": "Geçmiş yok", "Import from browser": "Tarayıcıdan içe aktar", "releases": "Sürümler", "Are you sure?": "Emin misiniz?", diff --git a/public/locales/uk.json b/public/locales/uk.json index 7e6aece22..eaf5b38eb 100644 --- a/public/locales/uk.json +++ b/public/locales/uk.json @@ -25,7 +25,7 @@ "Import history": "Імпортувати історію", "Clear history": "Очистити історію", "Refresh history": "Оновити історію", - "No history": "Історія відсутня", + "noHistory": "Історія відсутня", "Import from browser": "Імпортувати з браузера", "releases": "Релізи", "Are you sure?": "Ви впевнені?", diff --git a/public/locales/vi.json b/public/locales/vi.json index 54071d02f..d67013670 100644 --- a/public/locales/vi.json +++ b/public/locales/vi.json @@ -25,7 +25,7 @@ "Import history": "Nhập lịch sử", "Clear history": "Xóa lịch sử", "Refresh history": "Làm mới lịch sử", - "No history": "Không có lịch sử", + "noHistory": "Không có lịch sử", "Import from browser": "Nhập từ trình duyệt", "releases": "Xuất bản", "Are you sure?": "Bạn có chắc chắn không ?", diff --git a/public/locales/zh-CN.json b/public/locales/zh-CN.json index 2f4979473..a8605fa24 100644 --- a/public/locales/zh-CN.json +++ b/public/locales/zh-CN.json @@ -25,7 +25,7 @@ "Import history": "导入历史", "Clear history": "清空历史", "Refresh history": "刷新历史", - "No history": "无历史记录", + "noHistory": "无历史记录", "Import from browser": "从浏览器导入", "releases": "版本", "Are you sure?": "您确定吗?", diff --git a/public/locales/zh-TW.json b/public/locales/zh-TW.json index e3bb5ad44..d74e8424f 100644 --- a/public/locales/zh-TW.json +++ b/public/locales/zh-TW.json @@ -25,7 +25,7 @@ "Import history": "匯入紀錄", "Clear history": "清空紀錄", "Refresh history": "更新紀錄", - "No history": "沒有紀錄", + "noHistory": "沒有紀錄", "Import from browser": "從瀏覽器匯入", "releases": "版本", "Are you sure?": "你確定嗎?", diff --git a/src/components/landing/pages/history/common/close-button.scss b/src/components/landing/pages/history/common/close-button.scss new file mode 100644 index 000000000..70ba9e95b --- /dev/null +++ b/src/components/landing/pages/history/common/close-button.scss @@ -0,0 +1,7 @@ +.history-close { + opacity: 0.5; + + &:hover { + opacity: 1; + } +} \ No newline at end of file diff --git a/src/components/landing/pages/history/common/close-button.tsx b/src/components/landing/pages/history/common/close-button.tsx index 348dd1663..9f84b2b66 100644 --- a/src/components/landing/pages/history/common/close-button.tsx +++ b/src/components/landing/pages/history/common/close-button.tsx @@ -1,5 +1,6 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import React from "react"; +import "./close-button.scss" const CloseButton: React.FC = () => { return ( diff --git a/src/components/landing/pages/history/common/button.scss b/src/components/landing/pages/history/common/pin-button.scss similarity index 73% rename from src/components/landing/pages/history/common/button.scss rename to src/components/landing/pages/history/common/pin-button.scss index 49fecea12..e9a3e00b5 100644 --- a/src/components/landing/pages/history/common/button.scss +++ b/src/components/landing/pages/history/common/pin-button.scss @@ -11,11 +11,3 @@ opacity: 1; } } - -.history-close { - opacity: 0.5; - - &:hover { - opacity: 1; - } -} \ No newline at end of file diff --git a/src/components/landing/pages/history/common/pin-button.tsx b/src/components/landing/pages/history/common/pin-button.tsx index 3609ae6e1..8bdc22b93 100644 --- a/src/components/landing/pages/history/common/pin-button.tsx +++ b/src/components/landing/pages/history/common/pin-button.tsx @@ -1,17 +1,18 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import React from "react"; +import "./pin-button.scss" export interface PinButtonProps { pin: boolean; - onPinChange: () => void; + onPinClick: () => void; } -const PinButton: React.FC = ({pin, onPinChange}) => { +const PinButton: React.FC = ({pin, onPinClick}) => { return ( ); } diff --git a/src/components/landing/pages/history/history-card/history-card-list.tsx b/src/components/landing/pages/history/history-card/history-card-list.tsx new file mode 100644 index 000000000..23bf7465c --- /dev/null +++ b/src/components/landing/pages/history/history-card/history-card-list.tsx @@ -0,0 +1,18 @@ +import React, {Fragment} from 'react' +import {HistoryEntriesProps} from "../history-content/history-content"; +import {HistoryCard} from "./history-card"; + +export const HistoryCardList: React.FC = ({entries, onPinClick}) => { + return ( + + { + entries.map((entry) => ( + )) + } + + ) +} diff --git a/src/components/landing/pages/history/history-card/history-card.tsx b/src/components/landing/pages/history/history-card/history-card.tsx index 40b53445c..33b385674 100644 --- a/src/components/landing/pages/history/history-card/history-card.tsx +++ b/src/components/landing/pages/history/history-card/history-card.tsx @@ -1,32 +1,34 @@ import React from 'react' -import {HistoryInput} from '../history' import {Badge, Card} from 'react-bootstrap' import {FontAwesomeIcon} from '@fortawesome/react-fontawesome' -import "../common/button.scss" import {PinButton} from "../common/pin-button"; import {CloseButton} from "../common/close-button"; import moment from "moment"; import {useTranslation} from "react-i18next"; +import {HistoryEntryProps} from "../history-content/history-content"; +import {formatHistoryDate} from "../../../../../utils/historyUtils"; -export const HistoryCard: React.FC = ({pinned, title, lastVisited, tags, onPinChange}) => { +export const HistoryCard: React.FC = ({entry, onPinClick}) => { useTranslation() return (
- - {title} + { + onPinClick(entry.id) + }}/> + {entry.title}
- {moment(lastVisited).fromNow()}
- {moment(lastVisited).format("llll")} -
{tag}) - } - /> + {moment(entry.lastVisited).fromNow()}
+ {formatHistoryDate(entry.lastVisited)} +
+ { + entry.tags.map((tag) => {tag}) + } +
diff --git a/src/components/landing/pages/history/history-content/history-content.tsx b/src/components/landing/pages/history/history-content/history-content.tsx new file mode 100644 index 000000000..10edf1203 --- /dev/null +++ b/src/components/landing/pages/history/history-content/history-content.tsx @@ -0,0 +1,41 @@ +import React from "react"; +import {HistoryEntry, pinClick, ViewStateEnum} from "../history"; +import {HistoryTable} from "../history-table/history-table"; +import {Alert} from "react-bootstrap"; +import {Trans} from "react-i18next"; +import {HistoryCardList} from "../history-card/history-card-list"; + +export interface HistoryContentProps { + viewState: ViewStateEnum + entries: HistoryEntry[] + onPinClick: pinClick +} + +export interface HistoryEntryProps { + entry: HistoryEntry, + onPinClick: pinClick +} + +export interface HistoryEntriesProps { + entries: HistoryEntry[] + onPinClick: pinClick +} + +export const HistoryContent: React.FC = ({viewState, entries, onPinClick}) => { + + if (entries.length === 0) { + return ( + + + + ); + } + + switch (viewState) { + default: + case ViewStateEnum.card: + return + case ViewStateEnum.table: + return ; + } +} \ No newline at end of file diff --git a/src/components/landing/pages/history/history-table/history-table-row.tsx b/src/components/landing/pages/history/history-table/history-table-row.tsx index d4a6c44b9..ca9b72283 100644 --- a/src/components/landing/pages/history/history-table/history-table-row.tsx +++ b/src/components/landing/pages/history/history-table/history-table-row.tsx @@ -1,16 +1,20 @@ import React from "react"; -import {HistoryInput} from "../history"; import {PinButton} from "../common/pin-button"; import {CloseButton} from "../common/close-button"; -import moment from "moment"; +import {useTranslation} from "react-i18next"; +import {HistoryEntryProps} from "../history-content/history-content"; +import {formatHistoryDate} from "../../../../../utils/historyUtils"; -export const HistoryTableRow: React.FC = ({pinned, title, lastVisited, onPinChange}) => { +export const HistoryTableRow: React.FC = ({entry, onPinClick}) => { + useTranslation() return ( - {title} - {moment(lastVisited).format("llll")} + {entry.title} + {formatHistoryDate(entry.lastVisited)} - + { + onPinClick(entry.id) + }}/>   diff --git a/src/components/landing/pages/history/history-table/history-table.tsx b/src/components/landing/pages/history/history-table/history-table.tsx index e277d910e..780e4941a 100644 --- a/src/components/landing/pages/history/history-table/history-table.tsx +++ b/src/components/landing/pages/history/history-table/history-table.tsx @@ -1,21 +1,30 @@ import React from "react"; import {Table} from "react-bootstrap" +import {HistoryTableRow} from "./history-table-row"; +import {HistoryEntriesProps} from "../history-content/history-content"; -const HistoryTable: React.FC = ({children}) => { +const HistoryTable: React.FC = ({entries, onPinClick}) => { return ( - - - - - + + + + + - {children} + { + entries.map((entry) => + ) + }
TitleLast visitedActions
TitleLast visitedActions
) } -export { HistoryTable } +export {HistoryTable} diff --git a/src/components/landing/pages/history/history.tsx b/src/components/landing/pages/history/history.tsx index 80cb675f9..8327821c3 100644 --- a/src/components/landing/pages/history/history.tsx +++ b/src/components/landing/pages/history/history.tsx @@ -1,26 +1,14 @@ import React, {Fragment, useEffect, useState} from 'react' -import {HistoryCard} from "./history-card/history-card"; -import {HistoryTable} from "./history-table/history-table"; -import {HistoryTableRow} from './history-table/history-table-row'; import {ToggleButton, ToggleButtonGroup} from 'react-bootstrap'; -import moment from "moment"; +import {HistoryContent} from './history-content/history-content'; +import {loadHistoryFromLocalStore, sortAndFilterEntries} from "../../../../utils/historyUtils"; -interface HistoryChange { - onPinChange: () => void, -} - -interface ViewState { - viewState: ViewStateEnum -} - -enum ViewStateEnum { +export enum ViewStateEnum { card, table } -export type HistoryInput = HistoryEntry & HistoryChange - -interface HistoryEntry { +export interface HistoryEntry { id: string, title: string, lastVisited: Date, @@ -28,101 +16,44 @@ interface HistoryEntry { pinned: boolean } -interface OldHistoryEntry { - id: string; - text: string; - time: number; - tags: string[]; - pinned: boolean; -} +export type pinClick = (entryId: string) => void; -function loadHistoryFromLocalStore() { - const historyJsonString = window.localStorage.getItem("history"); - if (historyJsonString === null) { - // 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)) : []; - return oldHistory.map((entry: OldHistoryEntry) => { - return { - id: entry.id, - title: entry.text, - lastVisited: moment(entry.time).toDate(), - tags: entry.tags, - pinned: entry.pinned, - } - }) - } else { - return JSON.parse(historyJsonString) - } -} - -const History: React.FC = () => { +export const History: React.FC = () => { const [historyEntries, setHistoryEntries] = useState([]) - const [viewState, setViewState] = useState({ - viewState: ViewStateEnum.card - }) + const [viewState, setViewState] = useState(ViewStateEnum.card) useEffect(() => { const history = loadHistoryFromLocalStore(); setHistoryEntries(history); }, []) + useEffect(() => { + window.localStorage.setItem("history", JSON.stringify(historyEntries)); + }, [historyEntries]) + + const pinClick: pinClick = (entryId: string) => { + setHistoryEntries((entries) => { + return entries.map((entry) => { + if (entry.id === entryId) { + entry.pinned = !entry.pinned; + } + return entry; + }); + }) + } + return (

History

setViewState(() => ({viewState: newState}))}> + onChange={(newState: ViewStateEnum) => setViewState(newState)}> Card Table - { - viewState.viewState === ViewStateEnum.card ? ( -
- { - historyEntries.length === 0 ? - '' - : - historyEntries.map((entry) => - { - // setHistoryEntries((prev: HistoryEntry) => { - // return {...prev, pinned: !prev.pinned}; - // }); - }} - />) - } -
- ) : ( - - { - historyEntries.length === 0 ? - '' - : - historyEntries.map((entry) => - { - // setEntry((prev: HistoryEntry) => { - // return {...prev, pinned: !prev.pinned}; - // }); - }} - />) - } - - ) - } +
+ +
) -} - -export {History} +} \ No newline at end of file diff --git a/src/utils/historyUtils.ts b/src/utils/historyUtils.ts new file mode 100644 index 000000000..b970cf40e --- /dev/null +++ b/src/utils/historyUtils.ts @@ -0,0 +1,57 @@ +import {HistoryEntry} from "../components/landing/pages/history/history"; +import moment from "moment"; + +export function sortAndFilterEntries(entries: HistoryEntry[]): HistoryEntry[] { + return sortEntries(entries); +} + +function sortEntries(entries: HistoryEntry[]): HistoryEntry[] { + return entries.sort((a, b) => { + if (a.pinned && !b.pinned) { + return -1; + } + if (!a.pinned && b.pinned) { + return 1; + } + if (a.lastVisited < b.lastVisited) { + return -1; + } + if (a.lastVisited > b.lastVisited) { + return 1; + } + return 0; + }) +} + +export function formatHistoryDate(date: Date) { + return moment(date).format("llll") +} + +export interface OldHistoryEntry { + id: string; + text: string; + time: number; + tags: string[]; + pinned: boolean; +} + +export function loadHistoryFromLocalStore(): HistoryEntry[] { + const historyJsonString = window.localStorage.getItem("history"); + if (historyJsonString === null) { + // 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)) : []; + return oldHistory.map((entry: OldHistoryEntry) => { + return { + id: entry.id, + title: entry.text, + lastVisited: moment(entry.time).toDate(), + tags: entry.tags, + pinned: entry.pinned, + } + }) + } else { + return JSON.parse(historyJsonString) + } +} \ No newline at end of file