mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
use alias from item
This commit is contained in:
@@ -48,7 +48,7 @@ const TagItem = React.memo(
|
|||||||
>
|
>
|
||||||
#
|
#
|
||||||
</Heading>
|
</Heading>
|
||||||
{db.tags.alias(item.id)}
|
{item.alias}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Paragraph
|
<Paragraph
|
||||||
color={colors.icon}
|
color={colors.icon}
|
||||||
|
|||||||
@@ -16,17 +16,13 @@ import { Synced } from './synced';
|
|||||||
import { Tags } from './tags';
|
import { Tags } from './tags';
|
||||||
import { Topics } from './topics';
|
import { Topics } from './topics';
|
||||||
import SearchService from '../../services/search';
|
import SearchService from '../../services/search';
|
||||||
|
import { COLORS_NOTE } from '../../utils/color-scheme';
|
||||||
|
|
||||||
export const Properties = ({ close = () => {}, item, buttons = [], getRef }) => {
|
export const Properties = ({ close = () => {}, item, buttons = [], getRef }) => {
|
||||||
const colors = useThemeStore(state => state.colors);
|
const colors = useThemeStore(state => state.colors);
|
||||||
|
|
||||||
const alias = item
|
const alias = item.alias || item.title;
|
||||||
? item.type === 'tag'
|
const isColor = !!COLORS_NOTE[item.title];
|
||||||
? db.tags.alias(item.id)
|
|
||||||
: item.type === 'color'
|
|
||||||
? db.colors.alias(item.id)
|
|
||||||
: item.title
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const onScrollEnd = () => {
|
const onScrollEnd = () => {
|
||||||
getRef().current?.handleChildScrollEnd();
|
getRef().current?.handleChildScrollEnd();
|
||||||
@@ -62,7 +58,11 @@ export const Properties = ({ close = () => {}, item, buttons = [], getRef }) =>
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Heading size={SIZE.lg}>
|
<Heading size={SIZE.lg}>
|
||||||
{item.type === 'tag' ? '#' : null}
|
{item.type === 'tag' && !isColor ? (
|
||||||
|
<Heading size={SIZE.xl} color={colors.accent}>
|
||||||
|
#
|
||||||
|
</Heading>
|
||||||
|
) : null}
|
||||||
{alias}
|
{alias}
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export const TagsSection = React.memo(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const renderItem = ({ item, index }) => {
|
const renderItem = ({ item, index }) => {
|
||||||
let alias = item ? (item.type === 'tag' ? db.tags.alias(item.title) : item.title) : null;
|
let alias = item.alias || item.title;
|
||||||
return <PinItem item={item} index={index} alias={alias} onPress={onPress} />;
|
return <PinItem item={item} index={index} alias={alias} onPress={onPress} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ export const PinItem = React.memo(
|
|||||||
({ item, index, onPress, placeholder, alias }) => {
|
({ item, index, onPress, placeholder, alias }) => {
|
||||||
const colors = useThemeStore(state => state.colors);
|
const colors = useThemeStore(state => state.colors);
|
||||||
const setMenuPins = useMenuStore(state => state.setMenuPins);
|
const setMenuPins = useMenuStore(state => state.setMenuPins);
|
||||||
alias = !item ? '' : item.type === 'tag' ? db.tags.alias(item.title) : item.title;
|
alias = item?.alias || item?.title;
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [headerTextState, setHeaderTextState] = useState(null);
|
const [headerTextState, setHeaderTextState] = useState(null);
|
||||||
const color = headerTextState?.id === item.id ? colors.accent : colors.pri;
|
const color = headerTextState?.id === item.id ? colors.accent : colors.pri;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export const Home = ({ navigation, route }: NavigationProps<'Notes'>) => {
|
|||||||
const loading = useNoteStore(state => state.loading);
|
const loading = useNoteStore(state => state.loading);
|
||||||
const isFocused = useNavigationFocus(navigation, {
|
const isFocused = useNavigationFocus(navigation, {
|
||||||
onFocus: prev => {
|
onFocus: prev => {
|
||||||
|
console.log('updating', route.name, 'on focus');
|
||||||
Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
|
Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
|
||||||
useNavigationStore.getState().update({
|
useNavigationStore.getState().update({
|
||||||
name: route.name
|
name: route.name
|
||||||
|
|||||||
@@ -15,13 +15,8 @@ export function toCamelCase(title: string) {
|
|||||||
export function getAlias(params: NotesScreenParams) {
|
export function getAlias(params: NotesScreenParams) {
|
||||||
if (!params) return '';
|
if (!params) return '';
|
||||||
const { item } = params;
|
const { item } = params;
|
||||||
let alias =
|
//@ts-ignore
|
||||||
item.type === 'tag'
|
return item.alias || item.title;
|
||||||
? db.tags?.alias(item.id)
|
|
||||||
: item.type === 'color'
|
|
||||||
? db.colors?.alias(item.id)
|
|
||||||
: params?.title;
|
|
||||||
return alias || item.title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openMonographsWebpage() {
|
export function openMonographsWebpage() {
|
||||||
@@ -78,7 +73,6 @@ export function isSynced(params: NotesScreenParams) {
|
|||||||
|
|
||||||
async function onNoteCreated(id: string, params: FirstSaveData) {
|
async function onNoteCreated(id: string, params: FirstSaveData) {
|
||||||
if (!params) return;
|
if (!params) return;
|
||||||
|
|
||||||
switch (params.type) {
|
switch (params.type) {
|
||||||
case 'topic': {
|
case 'topic': {
|
||||||
await db.notes?.move(
|
await db.notes?.move(
|
||||||
|
|||||||
@@ -50,6 +50,14 @@ export interface RouteProps<T extends RouteName> extends NavigationProps<T> {
|
|||||||
rightButtons?: (params: NotesScreenParams) => HeaderRightButton[];
|
rightButtons?: (params: NotesScreenParams) => HeaderRightButton[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getItemType(routeName: RouteName) {
|
||||||
|
if (routeName === 'TaggedNotes') return 'tag';
|
||||||
|
if (routeName === 'ColoredNotes') return 'color';
|
||||||
|
if (routeName === 'TopicNotes') return 'topic';
|
||||||
|
if (routeName === 'Monographs') return 'monograph';
|
||||||
|
return 'note';
|
||||||
|
}
|
||||||
|
|
||||||
const NotesPage = ({
|
const NotesPage = ({
|
||||||
route,
|
route,
|
||||||
navigation,
|
navigation,
|
||||||
@@ -108,7 +116,7 @@ const NotesPage = ({
|
|||||||
|
|
||||||
!isMonograph &&
|
!isMonograph &&
|
||||||
setOnFirstSave({
|
setOnFirstSave({
|
||||||
type: item.type,
|
type: getItemType(route.name),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
color: item.title,
|
color: item.title,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ function clearRouteFromQueue(routeName: Route) {
|
|||||||
* Check if a route needs update
|
* Check if a route needs update
|
||||||
*/
|
*/
|
||||||
function routeNeedsUpdate(routeName: Route, callback: () => void) {
|
function routeNeedsUpdate(routeName: Route, callback: () => void) {
|
||||||
console.log('routeName', routesUpdateQueue);
|
console.log('routeNeedsUpdate', routesUpdateQueue, routesUpdateQueue.indexOf(routeName));
|
||||||
if (routesUpdateQueue.indexOf(routeName) > -1) {
|
if (routesUpdateQueue.indexOf(routeName) > -1) {
|
||||||
clearRouteFromQueue(routeName);
|
clearRouteFromQueue(routeName);
|
||||||
console.log('CALL ROUTE UPDATE');
|
console.log('CALL ROUTE UPDATE');
|
||||||
@@ -120,13 +120,16 @@ function routeNeedsUpdate(routeName: Route, callback: () => void) {
|
|||||||
function queueRoutesForUpdate(...routes: Route[]) {
|
function queueRoutesForUpdate(...routes: Route[]) {
|
||||||
console.log('updating routes', routes);
|
console.log('updating routes', routes);
|
||||||
const currentScreen = useNavigationStore.getState().currentScreen;
|
const currentScreen = useNavigationStore.getState().currentScreen;
|
||||||
const routeHistory = rootNavigatorRef.getState()?.history || [{ key: currentScreen.name }];
|
const routeHistory = rootNavigatorRef.current?.getRootState()?.routes || [
|
||||||
|
{ key: currentScreen.name }
|
||||||
|
];
|
||||||
|
|
||||||
// filter out routes that are not rendered to prevent unnecessary updates
|
// filter out routes that are not rendered to prevent unnecessary updates
|
||||||
routes = routes.filter(
|
routes = routes.filter(
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
routeName => routeHistory?.findIndex(route => route.key?.startsWith(routeName)) > -1
|
routeName => routeHistory?.findIndex(route => route.key?.startsWith(routeName)) > -1
|
||||||
);
|
);
|
||||||
console.log('routes to update: ', routes, routeHistory, currentScreen.name);
|
|
||||||
if (routes.indexOf(currentScreen.name) > -1) {
|
if (routes.indexOf(currentScreen.name) > -1) {
|
||||||
console.log('updating current route');
|
console.log('updating current route');
|
||||||
routeUpdateFunctions[currentScreen.name]();
|
routeUpdateFunctions[currentScreen.name]();
|
||||||
@@ -138,6 +141,7 @@ function queueRoutesForUpdate(...routes: Route[]) {
|
|||||||
|
|
||||||
routesUpdateQueue = routesUpdateQueue.concat(routes);
|
routesUpdateQueue = routesUpdateQueue.concat(routes);
|
||||||
routesUpdateQueue = [...new Set(routesUpdateQueue)];
|
routesUpdateQueue = [...new Set(routesUpdateQueue)];
|
||||||
|
console.log(routesUpdateQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigate<T extends RouteName>(screen: CurrentScreen, params: RouteParams[T]) {
|
function navigate<T extends RouteName>(screen: CurrentScreen, params: RouteParams[T]) {
|
||||||
|
|||||||
@@ -47,12 +47,7 @@ export const useActions = ({ close = () => {}, item }) => {
|
|||||||
console.log(item.readonly, 'readonly');
|
console.log(item.readonly, 'readonly');
|
||||||
const user = useUserStore(state => state.user);
|
const user = useUserStore(state => state.user);
|
||||||
const [notifPinned, setNotifPinned] = useState(null);
|
const [notifPinned, setNotifPinned] = useState(null);
|
||||||
const alias =
|
const alias = item.alias || item.title;
|
||||||
item.type === 'tag'
|
|
||||||
? db.tags.alias(item.id)
|
|
||||||
: item.type === 'color'
|
|
||||||
? db.colors.alias(item.id)
|
|
||||||
: item.title;
|
|
||||||
|
|
||||||
const isPublished = item.type === 'note' && db.monographs.isPublished(item.id);
|
const isPublished = item.type === 'note' && db.monographs.isPublished(item.id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user