Commit 81b9b785 authored by Phil Hughes's avatar Phil Hughes

Created a isLoggedIn utils method

Converted similar uses to use the utils isLoggedIn method
parent 61b90085
<script> <script>
/* eslint-disable vue/no-v-html */ /* eslint-disable vue/no-v-html */
import { memoize } from 'lodash'; import { memoize } from 'lodash';
import { isLoggedIn } from '~/lib/utils/common_utils';
import { import {
PARALLEL_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE,
CONFLICT_MARKER_THEIR, CONFLICT_MARKER_THEIR,
...@@ -16,8 +17,6 @@ import { ...@@ -16,8 +17,6 @@ import {
import DiffGutterAvatars from './diff_gutter_avatars.vue'; import DiffGutterAvatars from './diff_gutter_avatars.vue';
import * as utils from './diff_row_utils'; import * as utils from './diff_row_utils';
const isLoggedIn = () => Boolean(window.gon?.current_user_id);
export default { export default {
DiffGutterAvatars, DiffGutterAvatars,
CodeQualityGutterIcon: () => import('ee_component/diffs/components/code_quality_gutter_icon.vue'), CodeQualityGutterIcon: () => import('ee_component/diffs/components/code_quality_gutter_icon.vue'),
......
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
import { isLoggedIn } from '~/lib/utils/common_utils';
import { getGroups, getProjects } from '~/rest_api'; import { getGroups, getProjects } from '~/rest_api';
import { getTopFrequentItems } from '../utils'; import { getTopFrequentItems } from '../utils';
import * as types from './mutation_types'; import * as types from './mutation_types';
...@@ -51,7 +52,7 @@ export const fetchSearchedItems = ({ state, dispatch }, searchQuery) => { ...@@ -51,7 +52,7 @@ export const fetchSearchedItems = ({ state, dispatch }, searchQuery) => {
const params = { const params = {
simple: true, simple: true,
per_page: 20, per_page: 20,
membership: Boolean(gon.current_user_id), membership: isLoggedIn(),
}; };
let searchFunction; let searchFunction;
......
...@@ -763,3 +763,5 @@ export const isFeatureFlagEnabled = (flag) => window.gon.features?.[flag]; ...@@ -763,3 +763,5 @@ export const isFeatureFlagEnabled = (flag) => window.gon.features?.[flag];
* @returns {Array[String]} Converted array * @returns {Array[String]} Converted array
*/ */
export const convertArrayToCamelCase = (array) => array.map((i) => convertToCamelCase(i)); export const convertArrayToCamelCase = (array) => array.map((i) => convertToCamelCase(i));
export const isLoggedIn = () => Boolean(window.gon?.current_user_id);
...@@ -4,6 +4,7 @@ import { mapActions, mapGetters } from 'vuex'; ...@@ -4,6 +4,7 @@ import { mapActions, mapGetters } from 'vuex';
import DraftNote from '~/batch_comments/components/draft_note.vue'; import DraftNote from '~/batch_comments/components/draft_note.vue';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { clearDraft, getDiscussionReplyKey } from '~/lib/utils/autosave'; import { clearDraft, getDiscussionReplyKey } from '~/lib/utils/autosave';
import { isLoggedIn } from '~/lib/utils/common_utils';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import diffLineNoteFormMixin from '~/notes/mixins/diff_line_note_form'; import diffLineNoteFormMixin from '~/notes/mixins/diff_line_note_form';
import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue'; import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue';
...@@ -85,7 +86,7 @@ export default { ...@@ -85,7 +86,7 @@ export default {
return this.getUserData; return this.getUserData;
}, },
isLoggedIn() { isLoggedIn() {
return Boolean(gon.current_user_id); return isLoggedIn();
}, },
autosaveKey() { autosaveKey() {
return getDiscussionReplyKey(this.firstNote.noteable_type, this.discussion.id); return getDiscussionReplyKey(this.firstNote.noteable_type, this.discussion.id);
......
...@@ -5,6 +5,7 @@ import BlobContent from '~/blob/components/blob_content.vue'; ...@@ -5,6 +5,7 @@ import BlobContent from '~/blob/components/blob_content.vue';
import BlobHeader from '~/blob/components/blob_header.vue'; import BlobHeader from '~/blob/components/blob_header.vue';
import { SIMPLE_BLOB_VIEWER, RICH_BLOB_VIEWER } from '~/blob/components/constants'; import { SIMPLE_BLOB_VIEWER, RICH_BLOB_VIEWER } from '~/blob/components/constants';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { isLoggedIn } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import blobInfoQuery from '../queries/blob_info.query.graphql'; import blobInfoQuery from '../queries/blob_info.query.graphql';
import BlobEdit from './blob_edit.vue'; import BlobEdit from './blob_edit.vue';
...@@ -90,7 +91,7 @@ export default { ...@@ -90,7 +91,7 @@ export default {
}, },
computed: { computed: {
isLoggedIn() { isLoggedIn() {
return Boolean(gon.current_user_id); return isLoggedIn();
}, },
isLoading() { isLoading() {
return this.$apollo.queries.project.loading; return this.$apollo.queries.project.loading;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlIcon, GlLoadingIcon, GlToggle, GlTooltipDirective } from '@gitlab/ui'; import { GlIcon, GlLoadingIcon, GlToggle, GlTooltipDirective } from '@gitlab/ui';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { IssuableType } from '~/issue_show/constants'; import { IssuableType } from '~/issue_show/constants';
import { isLoggedIn } from '~/lib/utils/common_utils';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue'; import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue';
import { subscribedQueries } from '~/sidebar/constants'; import { subscribedQueries } from '~/sidebar/constants';
...@@ -102,7 +103,7 @@ export default { ...@@ -102,7 +103,7 @@ export default {
}); });
}, },
isLoggedIn() { isLoggedIn() {
return Boolean(gon.current_user_id); return isLoggedIn();
}, },
canSubscribe() { canSubscribe() {
return this.emailsDisabled || !this.isLoggedIn; return this.emailsDisabled || !this.isLoggedIn;
......
<script> <script>
import { GlButton, GlLoadingIcon, GlTooltipDirective, GlIcon } from '@gitlab/ui'; import { GlButton, GlLoadingIcon, GlTooltipDirective, GlIcon } from '@gitlab/ui';
import { isLoggedIn } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import ApplySuggestion from './apply_suggestion.vue'; import ApplySuggestion from './apply_suggestion.vue';
...@@ -73,7 +74,7 @@ export default { ...@@ -73,7 +74,7 @@ export default {
return __('Applying suggestions...'); return __('Applying suggestions...');
}, },
isLoggedIn() { isLoggedIn() {
return Boolean(gon.current_user_id); return isLoggedIn();
}, },
}, },
methods: { methods: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment