mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-26 19:25:47 +03:00
Respect your preferences
This commit is contained in:
parent
2cd235a069
commit
91aeed5fe6
3 changed files with 36 additions and 4 deletions
10
src/app.jsx
10
src/app.jsx
|
@ -42,7 +42,13 @@ import Public from './pages/public';
|
||||||
import Settings from './pages/settings';
|
import Settings from './pages/settings';
|
||||||
import Status from './pages/status';
|
import Status from './pages/status';
|
||||||
import Welcome from './pages/welcome';
|
import Welcome from './pages/welcome';
|
||||||
import { api, initAccount, initClient, initInstance } from './utils/api';
|
import {
|
||||||
|
api,
|
||||||
|
initAccount,
|
||||||
|
initClient,
|
||||||
|
initInstance,
|
||||||
|
initPreferences,
|
||||||
|
} from './utils/api';
|
||||||
import { getAccessToken } from './utils/auth';
|
import { getAccessToken } from './utils/auth';
|
||||||
import states, { getStatus, saveStatus } from './utils/states';
|
import states, { getStatus, saveStatus } from './utils/states';
|
||||||
import store from './utils/store';
|
import store from './utils/store';
|
||||||
|
@ -92,6 +98,7 @@ function App() {
|
||||||
initInstance(masto),
|
initInstance(masto),
|
||||||
initAccount(masto, instanceURL, accessToken),
|
initAccount(masto, instanceURL, accessToken),
|
||||||
]);
|
]);
|
||||||
|
initPreferences(masto);
|
||||||
|
|
||||||
setIsLoggedIn(true);
|
setIsLoggedIn(true);
|
||||||
setUIState('default');
|
setUIState('default');
|
||||||
|
@ -101,6 +108,7 @@ function App() {
|
||||||
if (account) {
|
if (account) {
|
||||||
store.session.set('currentAccount', account.info.id);
|
store.session.set('currentAccount', account.info.id);
|
||||||
const { masto } = api({ account });
|
const { masto } = api({ account });
|
||||||
|
initPreferences(masto);
|
||||||
(async () => {
|
(async () => {
|
||||||
await initInstance(masto);
|
await initInstance(masto);
|
||||||
setIsLoggedIn(true);
|
setIsLoggedIn(true);
|
||||||
|
|
|
@ -148,6 +148,8 @@ function Compose({
|
||||||
const [mediaAttachments, setMediaAttachments] = useState([]);
|
const [mediaAttachments, setMediaAttachments] = useState([]);
|
||||||
const [poll, setPoll] = useState(null);
|
const [poll, setPoll] = useState(null);
|
||||||
|
|
||||||
|
const prefs = store.account.get('preferences') || {};
|
||||||
|
|
||||||
const customEmojis = useRef();
|
const customEmojis = useRef();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
@ -194,7 +196,7 @@ function Compose({
|
||||||
}
|
}
|
||||||
focusTextarea();
|
focusTextarea();
|
||||||
setVisibility(visibility);
|
setVisibility(visibility);
|
||||||
setLanguage(language || DEFAULT_LANG);
|
setLanguage(language || prefs.postingDefaultLanguage || DEFAULT_LANG);
|
||||||
setSensitive(sensitive);
|
setSensitive(sensitive);
|
||||||
}
|
}
|
||||||
if (draftStatus) {
|
if (draftStatus) {
|
||||||
|
@ -217,7 +219,7 @@ function Compose({
|
||||||
focusTextarea();
|
focusTextarea();
|
||||||
spoilerTextRef.current.value = spoilerText;
|
spoilerTextRef.current.value = spoilerText;
|
||||||
setVisibility(visibility);
|
setVisibility(visibility);
|
||||||
setLanguage(language || DEFAULT_LANG);
|
setLanguage(language || prefs.postingDefaultLanguage || DEFAULT_LANG);
|
||||||
setSensitive(sensitive);
|
setSensitive(sensitive);
|
||||||
setPoll(composablePoll);
|
setPoll(composablePoll);
|
||||||
setMediaAttachments(mediaAttachments);
|
setMediaAttachments(mediaAttachments);
|
||||||
|
@ -243,7 +245,7 @@ function Compose({
|
||||||
focusTextarea();
|
focusTextarea();
|
||||||
spoilerTextRef.current.value = spoilerText;
|
spoilerTextRef.current.value = spoilerText;
|
||||||
setVisibility(visibility);
|
setVisibility(visibility);
|
||||||
setLanguage(language || DEFAULT_LANG);
|
setLanguage(language || presf.postingDefaultLanguage || DEFAULT_LANG);
|
||||||
setSensitive(sensitive);
|
setSensitive(sensitive);
|
||||||
setPoll(composablePoll);
|
setPoll(composablePoll);
|
||||||
setMediaAttachments(mediaAttachments);
|
setMediaAttachments(mediaAttachments);
|
||||||
|
@ -256,6 +258,16 @@ function Compose({
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
focusTextarea();
|
focusTextarea();
|
||||||
|
console.log('Apply prefs', prefs);
|
||||||
|
if (prefs.postingDefaultVisibility) {
|
||||||
|
setVisibility(prefs.postingDefaultVisibility);
|
||||||
|
}
|
||||||
|
if (prefs.postingDefaultLanguage) {
|
||||||
|
setLanguage(prefs.postingDefaultLanguage);
|
||||||
|
}
|
||||||
|
if (prefs.postingDefaultSensitive) {
|
||||||
|
setSensitive(prefs.postingDefaultSensitive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [draftStatus, editStatus, replyToStatus]);
|
}, [draftStatus, editStatus, replyToStatus]);
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,18 @@ export async function initAccount(client, instance, accessToken) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get preferences
|
||||||
|
export async function initPreferences(client) {
|
||||||
|
try {
|
||||||
|
const masto = client;
|
||||||
|
const preferences = await masto.v1.preferences.fetch();
|
||||||
|
store.account.set('preferences', preferences);
|
||||||
|
} catch (e) {
|
||||||
|
// silently fail
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the masto instance
|
// Get the masto instance
|
||||||
// If accountID is provided, get the masto instance for that account
|
// If accountID is provided, get the masto instance for that account
|
||||||
export function api({ instance, accessToken, accountID, account } = {}) {
|
export function api({ instance, accessToken, accountID, account } = {}) {
|
||||||
|
|
Loading…
Reference in a new issue