Refactor get/set accounts

pull/1176/head
Lim Chee Aun 2025-05-28 08:20:21 +08:00
rodzic e1c61ad09e
commit 63a6206c35
5 zmienionych plików z 179 dodań i 162 usunięć

Wyświetl plik

@ -27,7 +27,12 @@ import showCompose from '../utils/show-compose';
import showToast from '../utils/show-toast'; import showToast from '../utils/show-toast';
import states from '../utils/states'; import states from '../utils/states';
import store from '../utils/store'; import store from '../utils/store';
import { getCurrentAccountID, updateAccount } from '../utils/store-utils'; import {
getAccounts,
getCurrentAccountID,
saveAccounts,
updateAccount,
} from '../utils/store-utils';
import supports from '../utils/supports'; import supports from '../utils/supports';
import AccountBlock from './account-block'; import AccountBlock from './account-block';
@ -224,7 +229,7 @@ function AccountInfo({
info?.url info?.url
); );
if (isSelf && instance && infoHasEssentials) { if (isSelf && instance && infoHasEssentials) {
const accounts = store.local.getJSON('accounts'); const accounts = getAccounts();
let updated = false; let updated = false;
accounts.forEach((account) => { accounts.forEach((account) => {
if (account.info.id === info.id && account.instanceURL === instance) { if (account.info.id === info.id && account.instanceURL === instance) {
@ -234,7 +239,7 @@ function AccountInfo({
}); });
if (updated) { if (updated) {
console.log('Updated account info', info); console.log('Updated account info', info);
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
} }
} }
}, [isSelf, info, instance]); }, [isSelf, info, instance]);

Wyświetl plik

@ -12,7 +12,7 @@ import { getLists } from '../utils/lists';
import safeBoundingBoxPadding from '../utils/safe-bounding-box-padding'; import safeBoundingBoxPadding from '../utils/safe-bounding-box-padding';
import states from '../utils/states'; import states from '../utils/states';
import store from '../utils/store'; import store from '../utils/store';
import { getCurrentAccountID } from '../utils/store-utils'; import { getAccounts, getCurrentAccountID } from '../utils/store-utils';
import supports from '../utils/supports'; import supports from '../utils/supports';
import Avatar from './avatar'; import Avatar from './avatar';
@ -27,7 +27,7 @@ function NavMenu(props) {
const { masto, instance, authenticated } = api(); const { masto, instance, authenticated } = api();
const [currentAccount, moreThanOneAccount] = useMemo(() => { const [currentAccount, moreThanOneAccount] = useMemo(() => {
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
const acc = const acc =
accounts.find((account) => account.info.id === getCurrentAccountID()) || accounts.find((account) => account.info.id === getCurrentAccountID()) ||
accounts[0]; accounts[0];

282
src/locales/en.po wygenerowano
Wyświetl plik

@ -28,12 +28,12 @@ msgid "Last posted: {0}"
msgstr "" msgstr ""
#: src/components/account-block.jsx:163 #: src/components/account-block.jsx:163
#: src/components/account-info.jsx:705 #: src/components/account-info.jsx:710
msgid "Automated" msgid "Automated"
msgstr "" msgstr ""
#: src/components/account-block.jsx:170 #: src/components/account-block.jsx:170
#: src/components/account-info.jsx:710 #: src/components/account-info.jsx:715
#: src/components/status.jsx:589 #: src/components/status.jsx:589
msgid "Group" msgid "Group"
msgstr "" msgstr ""
@ -43,17 +43,17 @@ msgid "Mutual"
msgstr "" msgstr ""
#: src/components/account-block.jsx:184 #: src/components/account-block.jsx:184
#: src/components/account-info.jsx:1870 #: src/components/account-info.jsx:1875
msgid "Requested" msgid "Requested"
msgstr "" msgstr ""
#: src/components/account-block.jsx:188 #: src/components/account-block.jsx:188
#: src/components/account-info.jsx:1861 #: src/components/account-info.jsx:1866
msgid "Following" msgid "Following"
msgstr "" msgstr ""
#: src/components/account-block.jsx:192 #: src/components/account-block.jsx:192
#: src/components/account-info.jsx:1175 #: src/components/account-info.jsx:1180
msgid "Follows you" msgid "Follows you"
msgstr "" msgstr ""
@ -62,52 +62,52 @@ msgid "{followersCount, plural, one {# follower} other {# followers}}"
msgstr "" msgstr ""
#: src/components/account-block.jsx:209 #: src/components/account-block.jsx:209
#: src/components/account-info.jsx:753 #: src/components/account-info.jsx:758
msgid "Verified" msgid "Verified"
msgstr "" msgstr ""
#. placeholder {0}: niceDateTime(createdAt, { hideTime: true, }) #. placeholder {0}: niceDateTime(createdAt, { hideTime: true, })
#. placeholder {0}: niceDateTime(createdAt, { hideTime: true, }) #. placeholder {0}: niceDateTime(createdAt, { hideTime: true, })
#: src/components/account-block.jsx:224 #: src/components/account-block.jsx:224
#: src/components/account-info.jsx:855 #: src/components/account-info.jsx:860
msgid "Joined <0>{0}</0>" msgid "Joined <0>{0}</0>"
msgstr "" msgstr ""
#: src/components/account-info.jsx:58 #: src/components/account-info.jsx:63
msgid "Forever" msgid "Forever"
msgstr "" msgstr ""
#: src/components/account-info.jsx:398 #: src/components/account-info.jsx:403
msgid "Unable to load account." msgid "Unable to load account."
msgstr "" msgstr ""
#: src/components/account-info.jsx:413 #: src/components/account-info.jsx:418
msgid "Go to account page" msgid "Go to account page"
msgstr "" msgstr ""
#: src/components/account-info.jsx:442 #: src/components/account-info.jsx:447
#: src/components/account-info.jsx:775 #: src/components/account-info.jsx:780
#: src/components/account-info.jsx:805 #: src/components/account-info.jsx:810
msgid "Followers" msgid "Followers"
msgstr "" msgstr ""
#. js-lingui-explicit-id #. js-lingui-explicit-id
#: src/components/account-info.jsx:446 #: src/components/account-info.jsx:451
#: src/components/account-info.jsx:815 #: src/components/account-info.jsx:820
#: src/components/account-info.jsx:834 #: src/components/account-info.jsx:839
msgid "following.stats" msgid "following.stats"
msgstr "Following" msgstr "Following"
#: src/components/account-info.jsx:449 #: src/components/account-info.jsx:454
#: src/components/account-info.jsx:851 #: src/components/account-info.jsx:856
#: src/pages/account-statuses.jsx:482 #: src/pages/account-statuses.jsx:482
#: src/pages/search.jsx:344 #: src/pages/search.jsx:344
#: src/pages/search.jsx:491 #: src/pages/search.jsx:491
msgid "Posts" msgid "Posts"
msgstr "" msgstr ""
#: src/components/account-info.jsx:457 #: src/components/account-info.jsx:462
#: src/components/account-info.jsx:1231 #: src/components/account-info.jsx:1236
#: src/components/compose.jsx:2783 #: src/components/compose.jsx:2783
#: src/components/media-alt-modal.jsx:55 #: src/components/media-alt-modal.jsx:55
#: src/components/media-modal.jsx:359 #: src/components/media-modal.jsx:359
@ -117,7 +117,7 @@ msgstr ""
#: src/components/status.jsx:2598 #: src/components/status.jsx:2598
#: src/components/status.jsx:2601 #: src/components/status.jsx:2601
#: src/pages/account-statuses.jsx:526 #: src/pages/account-statuses.jsx:526
#: src/pages/accounts.jsx:113 #: src/pages/accounts.jsx:118
#: src/pages/hashtag.jsx:202 #: src/pages/hashtag.jsx:202
#: src/pages/list.jsx:171 #: src/pages/list.jsx:171
#: src/pages/public.jsx:116 #: src/pages/public.jsx:116
@ -127,56 +127,56 @@ msgstr ""
msgid "More" msgid "More"
msgstr "" msgstr ""
#: src/components/account-info.jsx:469 #: src/components/account-info.jsx:474
msgid "<0>{displayName}</0> has indicated that their new account is now:" msgid "<0>{displayName}</0> has indicated that their new account is now:"
msgstr "" msgstr ""
#: src/components/account-info.jsx:614 #: src/components/account-info.jsx:619
#: src/components/account-info.jsx:1459 #: src/components/account-info.jsx:1464
msgid "Handle copied" msgid "Handle copied"
msgstr "Handle copied" msgstr "Handle copied"
#: src/components/account-info.jsx:617 #: src/components/account-info.jsx:622
#: src/components/account-info.jsx:1462 #: src/components/account-info.jsx:1467
msgid "Unable to copy handle" msgid "Unable to copy handle"
msgstr "Unable to copy handle" msgstr "Unable to copy handle"
#: src/components/account-info.jsx:623 #: src/components/account-info.jsx:628
#: src/components/account-info.jsx:1468 #: src/components/account-info.jsx:1473
msgid "Copy handle" msgid "Copy handle"
msgstr "" msgstr ""
#: src/components/account-info.jsx:629 #: src/components/account-info.jsx:634
msgid "Go to original profile page" msgid "Go to original profile page"
msgstr "" msgstr ""
#: src/components/account-info.jsx:647 #: src/components/account-info.jsx:652
msgid "View profile image" msgid "View profile image"
msgstr "" msgstr ""
#: src/components/account-info.jsx:665 #: src/components/account-info.jsx:670
msgid "View profile header" msgid "View profile header"
msgstr "" msgstr ""
#: src/components/account-info.jsx:681 #: src/components/account-info.jsx:686
#: src/components/account-info.jsx:1769 #: src/components/account-info.jsx:1774
#: src/components/account-info.jsx:2295 #: src/components/account-info.jsx:2300
msgid "Edit profile" msgid "Edit profile"
msgstr "" msgstr ""
#: src/components/account-info.jsx:700 #: src/components/account-info.jsx:705
msgid "In Memoriam" msgid "In Memoriam"
msgstr "" msgstr ""
#: src/components/account-info.jsx:782 #: src/components/account-info.jsx:787
#: src/components/account-info.jsx:825 #: src/components/account-info.jsx:830
msgid "This user has chosen to not make this information available." msgid "This user has chosen to not make this information available."
msgstr "This user has chosen to not make this information available." msgstr "This user has chosen to not make this information available."
#. placeholder {0}: ( postingStats.originals / postingStats.total ).toLocaleString(i18n.locale || undefined, { style: 'percent', }) #. placeholder {0}: ( postingStats.originals / postingStats.total ).toLocaleString(i18n.locale || undefined, { style: 'percent', })
#. placeholder {1}: ( postingStats.replies / postingStats.total ).toLocaleString(i18n.locale || undefined, { style: 'percent', }) #. placeholder {1}: ( postingStats.replies / postingStats.total ).toLocaleString(i18n.locale || undefined, { style: 'percent', })
#. placeholder {2}: ( postingStats.boosts / postingStats.total ).toLocaleString(i18n.locale || undefined, { style: 'percent', }) #. placeholder {2}: ( postingStats.boosts / postingStats.total ).toLocaleString(i18n.locale || undefined, { style: 'percent', })
#: src/components/account-info.jsx:880 #: src/components/account-info.jsx:885
msgid "{0} original posts, {1} replies, {2} boosts" msgid "{0} original posts, {1} replies, {2} boosts"
msgstr "{0} original posts, {1} replies, {2} boosts" msgstr "{0} original posts, {1} replies, {2} boosts"
@ -187,22 +187,22 @@ msgstr "{0} original posts, {1} replies, {2} boosts"
#. placeholder {4}: postingStats.total #. placeholder {4}: postingStats.total
#. placeholder {5}: postingStats.total #. placeholder {5}: postingStats.total
#. placeholder {6}: postingStats.daysSinceLastPost #. placeholder {6}: postingStats.daysSinceLastPost
#: src/components/account-info.jsx:896 #: src/components/account-info.jsx:901
msgid "{0, plural, one {{1, plural, one {Last 1 post in the past 1 day} other {Last 1 post in the past {2} days}}} other {{3, plural, one {Last {4} posts in the past 1 day} other {Last {5} posts in the past {6} days}}}}" msgid "{0, plural, one {{1, plural, one {Last 1 post in the past 1 day} other {Last 1 post in the past {2} days}}} other {{3, plural, one {Last {4} posts in the past 1 day} other {Last {5} posts in the past {6} days}}}}"
msgstr "" msgstr ""
#. placeholder {0}: postingStats.total #. placeholder {0}: postingStats.total
#. placeholder {1}: postingStats.total #. placeholder {1}: postingStats.total
#: src/components/account-info.jsx:912 #: src/components/account-info.jsx:917
msgid "{0, plural, one {Last 1 post in the past year(s)} other {Last {1} posts in the past year(s)}}" msgid "{0, plural, one {Last 1 post in the past year(s)} other {Last {1} posts in the past year(s)}}"
msgstr "" msgstr ""
#: src/components/account-info.jsx:937 #: src/components/account-info.jsx:942
#: src/pages/catchup.jsx:70 #: src/pages/catchup.jsx:70
msgid "Original" msgid "Original"
msgstr "" msgstr ""
#: src/components/account-info.jsx:941 #: src/components/account-info.jsx:946
#: src/components/status.jsx:2382 #: src/components/status.jsx:2382
#: src/pages/catchup.jsx:71 #: src/pages/catchup.jsx:71
#: src/pages/catchup.jsx:1448 #: src/pages/catchup.jsx:1448
@ -212,7 +212,7 @@ msgstr ""
msgid "Replies" msgid "Replies"
msgstr "" msgstr ""
#: src/components/account-info.jsx:945 #: src/components/account-info.jsx:950
#: src/pages/catchup.jsx:72 #: src/pages/catchup.jsx:72
#: src/pages/catchup.jsx:1450 #: src/pages/catchup.jsx:1450
#: src/pages/catchup.jsx:2073 #: src/pages/catchup.jsx:2073
@ -220,234 +220,234 @@ msgstr ""
msgid "Boosts" msgid "Boosts"
msgstr "" msgstr ""
#: src/components/account-info.jsx:951 #: src/components/account-info.jsx:956
msgid "Post stats unavailable." msgid "Post stats unavailable."
msgstr "" msgstr ""
#: src/components/account-info.jsx:982 #: src/components/account-info.jsx:987
msgid "View post stats" msgid "View post stats"
msgstr "" msgstr ""
#. placeholder {0}: niceDateTime(lastStatusAt, { hideTime: true, }) #. placeholder {0}: niceDateTime(lastStatusAt, { hideTime: true, })
#: src/components/account-info.jsx:1179 #: src/components/account-info.jsx:1184
msgid "Last post: <0>{0}</0>" msgid "Last post: <0>{0}</0>"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1193 #: src/components/account-info.jsx:1198
msgid "Muted" msgid "Muted"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1198 #: src/components/account-info.jsx:1203
msgid "Blocked" msgid "Blocked"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1207 #: src/components/account-info.jsx:1212
msgid "Private note" msgid "Private note"
msgstr "Private note" msgstr "Private note"
#: src/components/account-info.jsx:1264 #: src/components/account-info.jsx:1269
msgid "Mention <0>@{username}</0>" msgid "Mention <0>@{username}</0>"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1276 #: src/components/account-info.jsx:1281
msgid "Translate bio" msgid "Translate bio"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1287 #: src/components/account-info.jsx:1292
msgid "Edit private note" msgid "Edit private note"
msgstr "Edit private note" msgstr "Edit private note"
#: src/components/account-info.jsx:1287 #: src/components/account-info.jsx:1292
msgid "Add private note" msgid "Add private note"
msgstr "Add private note" msgstr "Add private note"
#: src/components/account-info.jsx:1307 #: src/components/account-info.jsx:1312
msgid "Notifications enabled for @{username}'s posts." msgid "Notifications enabled for @{username}'s posts."
msgstr "Notifications enabled for @{username}'s posts." msgstr "Notifications enabled for @{username}'s posts."
#: src/components/account-info.jsx:1308 #: src/components/account-info.jsx:1313
msgid " Notifications disabled for @{username}'s posts." msgid " Notifications disabled for @{username}'s posts."
msgstr " Notifications disabled for @{username}'s posts." msgstr " Notifications disabled for @{username}'s posts."
#: src/components/account-info.jsx:1320 #: src/components/account-info.jsx:1325
msgid "Disable notifications" msgid "Disable notifications"
msgstr "Disable notifications" msgstr "Disable notifications"
#: src/components/account-info.jsx:1321 #: src/components/account-info.jsx:1326
msgid "Enable notifications" msgid "Enable notifications"
msgstr "Enable notifications" msgstr "Enable notifications"
#: src/components/account-info.jsx:1338 #: src/components/account-info.jsx:1343
msgid "Boosts from @{username} enabled." msgid "Boosts from @{username} enabled."
msgstr "Boosts from @{username} enabled." msgstr "Boosts from @{username} enabled."
#: src/components/account-info.jsx:1339 #: src/components/account-info.jsx:1344
msgid "Boosts from @{username} disabled." msgid "Boosts from @{username} disabled."
msgstr "Boosts from @{username} disabled." msgstr "Boosts from @{username} disabled."
#: src/components/account-info.jsx:1350 #: src/components/account-info.jsx:1355
msgid "Disable boosts" msgid "Disable boosts"
msgstr "Disable boosts" msgstr "Disable boosts"
#: src/components/account-info.jsx:1350 #: src/components/account-info.jsx:1355
msgid "Enable boosts" msgid "Enable boosts"
msgstr "Enable boosts" msgstr "Enable boosts"
#: src/components/account-info.jsx:1369 #: src/components/account-info.jsx:1374
msgid "@{username} is no longer featured on your profile." msgid "@{username} is no longer featured on your profile."
msgstr "@{username} is no longer featured on your profile." msgstr "@{username} is no longer featured on your profile."
#: src/components/account-info.jsx:1379 #: src/components/account-info.jsx:1384
msgid "@{username} is now featured on your profile." msgid "@{username} is now featured on your profile."
msgstr "@{username} is now featured on your profile." msgstr "@{username} is now featured on your profile."
#: src/components/account-info.jsx:1387 #: src/components/account-info.jsx:1392
msgid "Unable to unfeature @{username} on your profile." msgid "Unable to unfeature @{username} on your profile."
msgstr "Unable to unfeature @{username} on your profile." msgstr "Unable to unfeature @{username} on your profile."
#: src/components/account-info.jsx:1391 #: src/components/account-info.jsx:1396
msgid "Unable to feature @{username} on your profile." msgid "Unable to feature @{username} on your profile."
msgstr "Unable to feature @{username} on your profile." msgstr "Unable to feature @{username} on your profile."
#: src/components/account-info.jsx:1400 #: src/components/account-info.jsx:1405
msgid "Don't feature on profile" msgid "Don't feature on profile"
msgstr "Don't feature on profile" msgstr "Don't feature on profile"
#: src/components/account-info.jsx:1401 #: src/components/account-info.jsx:1406
#: src/pages/hashtag.jsx:331 #: src/pages/hashtag.jsx:331
msgid "Feature on profile" msgid "Feature on profile"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1410 #: src/components/account-info.jsx:1415
msgid "Show featured profiles" msgid "Show featured profiles"
msgstr "Show featured profiles" msgstr "Show featured profiles"
#: src/components/account-info.jsx:1425 #: src/components/account-info.jsx:1430
#: src/components/account-info.jsx:1435 #: src/components/account-info.jsx:1440
#: src/components/account-info.jsx:2041 #: src/components/account-info.jsx:2046
msgid "Add/Remove from Lists" msgid "Add/Remove from Lists"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1485 #: src/components/account-info.jsx:1490
#: src/components/status.jsx:1257 #: src/components/status.jsx:1257
msgid "Link copied" msgid "Link copied"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1488 #: src/components/account-info.jsx:1493
#: src/components/status.jsx:1260 #: src/components/status.jsx:1260
msgid "Unable to copy link" msgid "Unable to copy link"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1494 #: src/components/account-info.jsx:1499
#: src/components/shortcuts-settings.jsx:1059 #: src/components/shortcuts-settings.jsx:1059
#: src/components/status.jsx:1266 #: src/components/status.jsx:1266
#: src/components/status.jsx:3376 #: src/components/status.jsx:3376
msgid "Copy" msgid "Copy"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1509 #: src/components/account-info.jsx:1514
#: src/components/shortcuts-settings.jsx:1077 #: src/components/shortcuts-settings.jsx:1077
#: src/components/status.jsx:1282 #: src/components/status.jsx:1282
msgid "Sharing doesn't seem to work." msgid "Sharing doesn't seem to work."
msgstr "" msgstr ""
#: src/components/account-info.jsx:1515 #: src/components/account-info.jsx:1520
#: src/components/status.jsx:1288 #: src/components/status.jsx:1288
msgid "Share…" msgid "Share…"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1535 #: src/components/account-info.jsx:1540
msgid "Unmuted @{username}" msgid "Unmuted @{username}"
msgstr "Unmuted @{username}" msgstr "Unmuted @{username}"
#: src/components/account-info.jsx:1547 #: src/components/account-info.jsx:1552
msgid "Unmute <0>@{username}</0>" msgid "Unmute <0>@{username}</0>"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1563 #: src/components/account-info.jsx:1568
msgid "Mute <0>@{username}</0>…" msgid "Mute <0>@{username}</0>…"
msgstr "" msgstr ""
#. placeholder {0}: typeof MUTE_DURATIONS_LABELS[duration] === 'function' ? MUTE_DURATIONS_LABELS[duration]() : _(MUTE_DURATIONS_LABELS[duration]) #. placeholder {0}: typeof MUTE_DURATIONS_LABELS[duration] === 'function' ? MUTE_DURATIONS_LABELS[duration]() : _(MUTE_DURATIONS_LABELS[duration])
#: src/components/account-info.jsx:1595 #: src/components/account-info.jsx:1600
msgid "Muted @{username} for {0}" msgid "Muted @{username} for {0}"
msgstr "Muted @{username} for {0}" msgstr "Muted @{username} for {0}"
#: src/components/account-info.jsx:1607 #: src/components/account-info.jsx:1612
msgid "Unable to mute @{username}" msgid "Unable to mute @{username}"
msgstr "Unable to mute @{username}" msgstr "Unable to mute @{username}"
#: src/components/account-info.jsx:1628 #: src/components/account-info.jsx:1633
msgid "Remove <0>@{username}</0> from followers?" msgid "Remove <0>@{username}</0> from followers?"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1648 #: src/components/account-info.jsx:1653
msgid "@{username} removed from followers" msgid "@{username} removed from followers"
msgstr "@{username} removed from followers" msgstr "@{username} removed from followers"
#: src/components/account-info.jsx:1660 #: src/components/account-info.jsx:1665
msgid "Remove follower…" msgid "Remove follower…"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1671 #: src/components/account-info.jsx:1676
msgid "Block <0>@{username}</0>?" msgid "Block <0>@{username}</0>?"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1695 #: src/components/account-info.jsx:1700
msgid "Unblocked @{username}" msgid "Unblocked @{username}"
msgstr "Unblocked @{username}" msgstr "Unblocked @{username}"
#: src/components/account-info.jsx:1703 #: src/components/account-info.jsx:1708
msgid "Blocked @{username}" msgid "Blocked @{username}"
msgstr "Blocked @{username}" msgstr "Blocked @{username}"
#: src/components/account-info.jsx:1711 #: src/components/account-info.jsx:1716
msgid "Unable to unblock @{username}" msgid "Unable to unblock @{username}"
msgstr "Unable to unblock @{username}" msgstr "Unable to unblock @{username}"
#: src/components/account-info.jsx:1713 #: src/components/account-info.jsx:1718
msgid "Unable to block @{username}" msgid "Unable to block @{username}"
msgstr "Unable to block @{username}" msgstr "Unable to block @{username}"
#: src/components/account-info.jsx:1723 #: src/components/account-info.jsx:1728
msgid "Unblock <0>@{username}</0>" msgid "Unblock <0>@{username}</0>"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1732 #: src/components/account-info.jsx:1737
msgid "Block <0>@{username}</0>…" msgid "Block <0>@{username}</0>…"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1749 #: src/components/account-info.jsx:1754
msgid "Report <0>@{username}</0>…" msgid "Report <0>@{username}</0>…"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1805 #: src/components/account-info.jsx:1810
msgid "Withdraw follow request?" msgid "Withdraw follow request?"
msgstr "Withdraw follow request?" msgstr "Withdraw follow request?"
#. placeholder {0}: info.acct || info.username #. placeholder {0}: info.acct || info.username
#: src/components/account-info.jsx:1806 #: src/components/account-info.jsx:1811
msgid "Unfollow @{0}?" msgid "Unfollow @{0}?"
msgstr "Unfollow @{0}?" msgstr "Unfollow @{0}?"
#: src/components/account-info.jsx:1864 #: src/components/account-info.jsx:1869
msgid "Unfollow…" msgid "Unfollow…"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1873 #: src/components/account-info.jsx:1878
msgid "Withdraw…" msgid "Withdraw…"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1880 #: src/components/account-info.jsx:1885
#: src/components/account-info.jsx:1884 #: src/components/account-info.jsx:1889
#: src/pages/hashtag.jsx:264 #: src/pages/hashtag.jsx:264
msgid "Follow" msgid "Follow"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1981 #: src/components/account-info.jsx:1986
#: src/components/account-info.jsx:2036 #: src/components/account-info.jsx:2041
#: src/components/account-info.jsx:2170 #: src/components/account-info.jsx:2175
#: src/components/account-info.jsx:2290 #: src/components/account-info.jsx:2295
#: src/components/account-sheet.jsx:38 #: src/components/account-sheet.jsx:38
#: src/components/compose.jsx:891 #: src/components/compose.jsx:891
#: src/components/compose.jsx:2739 #: src/components/compose.jsx:2739
@ -469,7 +469,7 @@ msgstr ""
#: src/components/status.jsx:3100 #: src/components/status.jsx:3100
#: src/components/status.jsx:3340 #: src/components/status.jsx:3340
#: src/components/status.jsx:3849 #: src/components/status.jsx:3849
#: src/pages/accounts.jsx:40 #: src/pages/accounts.jsx:45
#: src/pages/catchup.jsx:1584 #: src/pages/catchup.jsx:1584
#: src/pages/filters.jsx:225 #: src/pages/filters.jsx:225
#: src/pages/list.jsx:302 #: src/pages/list.jsx:302
@ -480,85 +480,85 @@ msgstr ""
msgid "Close" msgid "Close"
msgstr "" msgstr ""
#: src/components/account-info.jsx:1986 #: src/components/account-info.jsx:1991
msgid "Translated Bio" msgid "Translated Bio"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2081 #: src/components/account-info.jsx:2086
msgid "Unable to remove from list." msgid "Unable to remove from list."
msgstr "Unable to remove from list." msgstr "Unable to remove from list."
#: src/components/account-info.jsx:2082 #: src/components/account-info.jsx:2087
msgid "Unable to add to list." msgid "Unable to add to list."
msgstr "Unable to add to list." msgstr "Unable to add to list."
#: src/components/account-info.jsx:2101 #: src/components/account-info.jsx:2106
#: src/pages/lists.jsx:131 #: src/pages/lists.jsx:131
msgid "Unable to load lists." msgid "Unable to load lists."
msgstr "" msgstr ""
#: src/components/account-info.jsx:2105 #: src/components/account-info.jsx:2110
msgid "No lists." msgid "No lists."
msgstr "" msgstr ""
#: src/components/account-info.jsx:2116 #: src/components/account-info.jsx:2121
#: src/components/list-add-edit.jsx:41 #: src/components/list-add-edit.jsx:41
#: src/pages/lists.jsx:62 #: src/pages/lists.jsx:62
msgid "New list" msgid "New list"
msgstr "" msgstr ""
#. placeholder {0}: account?.username || account?.acct #. placeholder {0}: account?.username || account?.acct
#: src/components/account-info.jsx:2175 #: src/components/account-info.jsx:2180
msgid "Private note about <0>@{0}</0>" msgid "Private note about <0>@{0}</0>"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2205 #: src/components/account-info.jsx:2210
msgid "Unable to update private note." msgid "Unable to update private note."
msgstr "Unable to update private note." msgstr "Unable to update private note."
#: src/components/account-info.jsx:2228 #: src/components/account-info.jsx:2233
#: src/components/account-info.jsx:2526 #: src/components/account-info.jsx:2531
msgid "Cancel" msgid "Cancel"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2233 #: src/components/account-info.jsx:2238
msgid "Save & close" msgid "Save & close"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2350 #: src/components/account-info.jsx:2355
msgid "Unable to update profile." msgid "Unable to update profile."
msgstr "Unable to update profile." msgstr "Unable to update profile."
#: src/components/account-info.jsx:2357 #: src/components/account-info.jsx:2362
msgid "Header picture" msgid "Header picture"
msgstr "Header picture" msgstr "Header picture"
#: src/components/account-info.jsx:2409 #: src/components/account-info.jsx:2414
msgid "Profile picture" msgid "Profile picture"
msgstr "Profile picture" msgstr "Profile picture"
#: src/components/account-info.jsx:2461 #: src/components/account-info.jsx:2466
#: src/components/list-add-edit.jsx:106 #: src/components/list-add-edit.jsx:106
msgid "Name" msgid "Name"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2474 #: src/components/account-info.jsx:2479
msgid "Bio" msgid "Bio"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2487 #: src/components/account-info.jsx:2492
msgid "Extra fields" msgid "Extra fields"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2493 #: src/components/account-info.jsx:2498
msgid "Label" msgid "Label"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2496 #: src/components/account-info.jsx:2501
msgid "Content" msgid "Content"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2529 #: src/components/account-info.jsx:2534
#: src/components/list-add-edit.jsx:152 #: src/components/list-add-edit.jsx:152
#: src/components/shortcuts-settings.jsx:715 #: src/components/shortcuts-settings.jsx:715
#: src/pages/filters.jsx:570 #: src/pages/filters.jsx:570
@ -566,20 +566,20 @@ msgstr ""
msgid "Save" msgid "Save"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2583 #: src/components/account-info.jsx:2588
msgid "username" msgid "username"
msgstr "" msgstr ""
#: src/components/account-info.jsx:2587 #: src/components/account-info.jsx:2592
msgid "server domain name" msgid "server domain name"
msgstr "" msgstr ""
#. placeholder {0}: info.username #. placeholder {0}: info.username
#: src/components/account-info.jsx:2653 #: src/components/account-info.jsx:2658
msgid "Profiles featured by @{0}" msgid "Profiles featured by @{0}"
msgstr "Profiles featured by @{0}" msgstr "Profiles featured by @{0}"
#: src/components/account-info.jsx:2679 #: src/components/account-info.jsx:2684
msgid "No featured profiles." msgid "No featured profiles."
msgstr "No featured profiles." msgstr "No featured profiles."
@ -1076,7 +1076,7 @@ msgstr ""
#: src/components/generic-accounts.jsx:154 #: src/components/generic-accounts.jsx:154
#: src/components/notification.jsx:449 #: src/components/notification.jsx:449
#: src/pages/accounts.jsx:45 #: src/pages/accounts.jsx:50
#: src/pages/search.jsx:334 #: src/pages/search.jsx:334
#: src/pages/search.jsx:367 #: src/pages/search.jsx:367
msgid "Accounts" msgid "Accounts"
@ -1983,12 +1983,12 @@ msgid "Not available in current view mode"
msgstr "" msgstr ""
#: src/components/shortcuts-settings.jsx:351 #: src/components/shortcuts-settings.jsx:351
#: src/pages/accounts.jsx:183 #: src/pages/accounts.jsx:188
msgid "Move up" msgid "Move up"
msgstr "" msgstr ""
#: src/components/shortcuts-settings.jsx:367 #: src/components/shortcuts-settings.jsx:367
#: src/pages/accounts.jsx:198 #: src/pages/accounts.jsx:203
msgid "Move down" msgid "Move down"
msgstr "" msgstr ""
@ -2690,49 +2690,49 @@ msgstr ""
msgid "Month" msgid "Month"
msgstr "" msgstr ""
#: src/pages/accounts.jsx:59 #: src/pages/accounts.jsx:64
msgid "Current" msgid "Current"
msgstr "" msgstr ""
#: src/pages/accounts.jsx:105 #: src/pages/accounts.jsx:110
msgid "Default" msgid "Default"
msgstr "" msgstr ""
#: src/pages/accounts.jsx:127 #: src/pages/accounts.jsx:132
msgid "Switch to this account" msgid "Switch to this account"
msgstr "Switch to this account" msgstr "Switch to this account"
#: src/pages/accounts.jsx:136 #: src/pages/accounts.jsx:141
msgid "Switch in new tab/window" msgid "Switch in new tab/window"
msgstr "Switch in new tab/window" msgstr "Switch in new tab/window"
#: src/pages/accounts.jsx:150 #: src/pages/accounts.jsx:155
msgid "View profile…" msgid "View profile…"
msgstr "" msgstr ""
#: src/pages/accounts.jsx:168 #: src/pages/accounts.jsx:173
msgid "Set as default" msgid "Set as default"
msgstr "" msgstr ""
#. placeholder {0}: account.info.acct #. placeholder {0}: account.info.acct
#: src/pages/accounts.jsx:210 #: src/pages/accounts.jsx:215
msgid "Log out <0>@{0}</0>?" msgid "Log out <0>@{0}</0>?"
msgstr "" msgstr ""
#: src/pages/accounts.jsx:239 #: src/pages/accounts.jsx:244
msgid "Log out…" msgid "Log out…"
msgstr "" msgstr ""
#. placeholder {0}: niceDateTime(account.createdAt) #. placeholder {0}: niceDateTime(account.createdAt)
#: src/pages/accounts.jsx:246 #: src/pages/accounts.jsx:251
msgid "Connected on {0} (<0/>)" msgid "Connected on {0} (<0/>)"
msgstr "Connected on {0} (<0/>)" msgstr "Connected on {0} (<0/>)"
#: src/pages/accounts.jsx:263 #: src/pages/accounts.jsx:268
msgid "Add an existing account" msgid "Add an existing account"
msgstr "" msgstr ""
#: src/pages/accounts.jsx:270 #: src/pages/accounts.jsx:275
msgid "Note: <0>Default</0> account will always be used for first load. Switched accounts will persist during the session." msgid "Note: <0>Default</0> account will always be used for first load. Switched accounts will persist during the session."
msgstr "" msgstr ""

Wyświetl plik

@ -18,7 +18,12 @@ import { revokeAccessToken } from '../utils/auth';
import niceDateTime from '../utils/nice-date-time'; import niceDateTime from '../utils/nice-date-time';
import states from '../utils/states'; import states from '../utils/states';
import store from '../utils/store'; import store from '../utils/store';
import { getCurrentAccountID, setCurrentAccountID } from '../utils/store-utils'; import {
getAccounts,
getCurrentAccountID,
saveAccounts,
setCurrentAccountID,
} from '../utils/store-utils';
const isStandalone = window.matchMedia('(display-mode: standalone)').matches; const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
@ -26,7 +31,7 @@ function Accounts({ onClose }) {
const { t } = useLingui(); const { t } = useLingui();
const { masto } = api(); const { masto } = api();
// Accounts // Accounts
const accounts = store.local.getJSON('accounts'); const accounts = getAccounts();
const currentAccount = getCurrentAccountID(); const currentAccount = getCurrentAccountID();
const moreThanOneAccount = accounts.length > 1; const moreThanOneAccount = accounts.length > 1;
@ -70,7 +75,7 @@ function Accounts({ onClose }) {
.fetch(); .fetch();
console.log('fetched account info', info); console.log('fetched account info', info);
account.info = info; account.info = info;
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
reload(); reload();
} catch (e) {} } catch (e) {}
} }
@ -159,7 +164,7 @@ function Accounts({ onClose }) {
// Move account to the top of the list // Move account to the top of the list
accounts.splice(i, 1); accounts.splice(i, 1);
accounts.unshift(account); accounts.unshift(account);
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
reload(); reload();
}} }}
> >
@ -174,7 +179,7 @@ function Accounts({ onClose }) {
// Move account one position up // Move account one position up
accounts.splice(i, 1); accounts.splice(i, 1);
accounts.splice(i - 1, 0, account); accounts.splice(i - 1, 0, account);
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
reload(); reload();
}} }}
> >
@ -189,7 +194,7 @@ function Accounts({ onClose }) {
// Move account one position down // Move account one position down
accounts.splice(i, 1); accounts.splice(i, 1);
accounts.splice(i + 1, 0, account); accounts.splice(i + 1, 0, account);
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
reload(); reload();
}} }}
> >
@ -229,7 +234,7 @@ function Accounts({ onClose }) {
token: account.accessToken, token: account.accessToken,
}); });
accounts.splice(i, 1); accounts.splice(i, 1);
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
// location.reload(); // location.reload();
location.href = location.pathname || '/'; location.href = location.pathname || '/';
}} }}

Wyświetl plik

@ -1,23 +1,31 @@
import store from './store'; import store from './store';
export function getAccounts() {
return store.local.getJSON('accounts') || [];
}
export function saveAccounts(accounts) {
store.local.setJSON('accounts', accounts);
}
export function getAccount(id) { export function getAccount(id) {
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
if (!id) return accounts[0]; if (!id) return accounts[0];
return accounts.find((a) => a.info.id === id) || accounts[0]; return accounts.find((a) => a.info.id === id) || accounts[0];
} }
export function getAccountByAccessToken(accessToken) { export function getAccountByAccessToken(accessToken) {
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
return accounts.find((a) => a.accessToken === accessToken); return accounts.find((a) => a.accessToken === accessToken);
} }
export function getAccountByInstance(instance) { export function getAccountByInstance(instance) {
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
return accounts.find((a) => a.instanceURL === instance); return accounts.find((a) => a.instanceURL === instance);
} }
export function hasAccountInInstance(instance) { export function hasAccountInInstance(instance) {
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
return accounts.some((a) => a.instanceURL === instance); return accounts.some((a) => a.instanceURL === instance);
} }
@ -69,7 +77,7 @@ export function getCurrentAccountNS() {
} }
export function saveAccount(account) { export function saveAccount(account) {
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
const acc = accounts.find((a) => a.info.id === account.info.id); const acc = accounts.find((a) => a.info.id === account.info.id);
if (acc) { if (acc) {
acc.info = account.info; acc.info = account.info;
@ -79,13 +87,12 @@ export function saveAccount(account) {
} else { } else {
accounts.push(account); accounts.push(account);
} }
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
setCurrentAccountID(account.info.id);
} }
export function updateAccount(accountInfo) { export function updateAccount(accountInfo) {
// Only update if displayName or avatar or avatar_static is different // Only update if displayName or avatar or avatar_static is different
const accounts = store.local.getJSON('accounts') || []; const accounts = getAccounts();
const acc = accounts.find((a) => a.info.id === accountInfo.id); const acc = accounts.find((a) => a.info.id === accountInfo.id);
if (acc) { if (acc) {
if ( if (
@ -97,7 +104,7 @@ export function updateAccount(accountInfo) {
...acc.info, ...acc.info,
...accountInfo, ...accountInfo,
}; };
store.local.setJSON('accounts', accounts); saveAccounts(accounts);
} }
} }
} }