Skip to content

Commit

Permalink
feat: add tag for shared content
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Dec 1, 2024
1 parent aba7b20 commit 4d04105
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/i18n/localization/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
"Title": "Preference",
"ClearBrowsingData": "Clear Browsing Data (git isn't affected)",
"General": "UI & Interact",
"Shared": "Shared",
"Sync": "Sync & Backup",
"SyncInterval": "Sync/Backup Interval",
"SyncIntervalDescription": "After this length of time, it will automatically start backing up to Github, if is a local workspace it will create a local git backup (take effect after restart app)",
Expand Down Expand Up @@ -517,7 +518,9 @@
"Share": {
"SharedContent": "Shared Content",
"TidGiMobileShare": "Shared from TidGi Mobile",
"ImportSuccess": "Import Success"
"ImportSuccess": "Import Success",
"TagForSharedContent": "Tag for shared content",
"Clipped": "Clipped"
},
"Description": "Description",
"Tags": "Tags",
Expand Down
6 changes: 5 additions & 1 deletion src/i18n/localization/locales/zh_CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"DefaultUserName": "默认编辑者名",
"Token": "Git身份凭证",
"TokenDescription": "用于向Git服务器验证身份并同步内容的凭证,可通过登录在线存储服务(如Github)来取得,也可以手动获取「Personal Access Token」后填到这里。",
"Shared": "分享",
"Sync": "同步和备份",
"SyncInterval": "同步/备份间隔",
"SyncIntervalDescription": "每经过这段长度的时间后,就会自动开始备份到 Github,如果工作区是本地工作区则会创建本地备份(重启后生效)",
Expand Down Expand Up @@ -502,7 +503,10 @@
"Share": {
"SharedContent": "分享内容",
"TidGiMobileShare": "太记移动版分享",
"ImportSuccess": "导入成功"
"ImportSuccess": "导入成功",
"TagForSharedContent": "分享内容标签",
"TagForSharedContentDescription": "分享给太记移动端的内容,会自动加上这个标签。留空时表示不加任何标签。",
"Clipped": "剪藏"
},
"Import": {
"ImportWiki": "导入Wiki"
Expand Down
38 changes: 38 additions & 0 deletions src/pages/Config/Shared.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import useDebouncedCallback from 'beautiful-react-hooks/useDebouncedCallback';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { styled } from 'styled-components/native';

import { TextInput, Text } from 'react-native-paper';
import { useConfigStore } from '../../store/config';

const StyledTextInput = styled(TextInput)`
margin-top: 10px;
`;

export function Shared(): JSX.Element {
const { t } = useTranslation();

const [initialTagForSharedContent] = useConfigStore(state => [state.tagForSharedContent]);
const [tagForSharedContent, tagForSharedContentSetter] = useState(initialTagForSharedContent);
const setConfig = useConfigStore(state => state.set);

const tagForSharedContentOnChange = useDebouncedCallback((newText: string) => {
setConfig({ tagForSharedContent: newText });
}, []);

return (
<>
<StyledTextInput
label={t('Share.TagForSharedContent')}
value={tagForSharedContent}
defaultValue={t('Share.Clipped')}
onChangeText={(newText: string) => {
tagForSharedContentSetter(newText);
tagForSharedContentOnChange(newText);
}}
/>
<Text>{t('Share.TagForSharedContentDescription')}</Text>
</>
);
}
2 changes: 2 additions & 0 deletions src/pages/Config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { General } from './General';
import { Language } from './Language';
import { Performance } from './Performance';
import { ServerAndSync } from './ServerAndSync';
import { Shared } from './Shared';
import { TiddlyWiki } from './TiddlyWiki';

const PreferencesList = styled.SectionList`
Expand All @@ -32,6 +33,7 @@ export const Config: FC<StackScreenProps<RootStackParameterList, 'Config'>> = ()
{ title: t('Preference.Performance'), data: [Performance] },
{ title: t('Preference.TiddlyWiki'), data: [TiddlyWiki] },
{ title: t('Preference.Sync'), data: [ServerAndSync] },
{ title: t('Preference.Shared'), data: [Shared] },
{ title: t('Preference.Languages'), data: [Language] },
{ title: t('ContextMenu.About'), data: [About] },
{ title: t('Preference.DeveloperTools'), data: [Developer] },
Expand Down
7 changes: 6 additions & 1 deletion src/services/NativeService/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useEffect, useState } from 'react';
import { Snackbar } from 'react-native-paper';
import { useRegisterProxy } from 'react-native-postmessage-cat';
import i18n from '../../i18n';
import { useConfigStore } from '../../store/config';
import { IWikiWorkspace, useWorkspaceStore } from '../../store/workspace';
import { WikiStorageService } from '../WikiStorageService';
import { nativeService } from '.';
Expand Down Expand Up @@ -38,6 +39,7 @@ export function useRegisterReceivingShareIntent() {
{i18n.t('Share.ImportSuccess')}
</Snackbar>
);
const [tagForSharedContent] = useConfigStore(state => [state.tagForSharedContent]);

/** If you get error on development:
* ```
Expand Down Expand Up @@ -75,11 +77,14 @@ export function useRegisterReceivingShareIntent() {
// put into default workspace's database, with random title
const storageOfDefaultWorkspace = new WikiStorageService(defaultWiki);
const randomTitle = `${i18n.t('Share.SharedContent')}-${Date.now()}`;
const created = format(new Date(), 'yyyyMMddHHmmssSSS');
await storageOfDefaultWorkspace.saveTiddler(shareIntent.meta?.title ?? randomTitle, {
text: shareIntent.text,
url: shareIntent.webUrl,
created: format(new Date(), 'yyyyMMddHHmmssSSS'),
created,
modified: created,
creator: i18n.t('Share.TidGiMobileShare'),
tags: [tagForSharedContent ?? i18n.t('Share.Clipped')],
});
setImportSuccessSnackBarVisible(true);
}
Expand Down
5 changes: 3 additions & 2 deletions src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export interface ConfigState {
syncInBackground: boolean;
syncInterval: number;
syncIntervalBackground: number;
/** Undefined means unset, use default value. If is empty string, then means user deleted the default value, then don't set the tag. */
tagForSharedContent?: string;
theme: ColorSchemeName | 'default';
translucentStatusBar?: boolean;
userName: string;
}
const defaultConfig: ConfigState = {
autoOpenDefaultWiki: undefined,
Expand All @@ -30,7 +31,7 @@ const defaultConfig: ConfigState = {
syncIntervalBackground: 60 * 30 * 1000,
theme: 'default',
translucentStatusBar: true,
userName: '',
tagForSharedContent: undefined,
};
interface ConfigActions {
set: (newConfig: Partial<ConfigState>) => void;
Expand Down

0 comments on commit 4d04105

Please sign in to comment.