Skip to content

Instantly share code, notes, and snippets.

@precyx
precyx / Comments
Last active November 27, 2019 10:02
Several Data Mapping Examples, usually in useEffect scope
useEffect(() => {
if (!selectedQuestionId) return;
if (!commentsRaw.data) return;
let newComments = [];
let numComments = 0;
// filter comments by selected question / forum
newComments = commentsRaw.data.filter(comment => {
if (
comment.parentType == currentCommentType &&
@precyx
precyx / MockComments
Last active November 27, 2019 09:55
Mocking a Comments Object with replies Random data powered by faker.js
var faker = require("faker");
export function between(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
const randomPick = arr => {
return arr[Math.floor(Math.random() * arr.length)];
};
@precyx
precyx / ColorService
Created November 27, 2019 09:56
Service for generating unique colors for a key. (Future improvement: Caching colors in local storage)
let instance = null;
let ColorMap = {};
export const ColorService = function() {
return {
getInstance: () => {
if (instance != null) return instance;
else {
ColorMap = {};
instance = {
@precyx
precyx / for.js
Last active December 27, 2019 13:59
# JS - Fundamentals ## Basic JS Operators and Functions **Files Overview:** - forEach.js - for.js
/**
* Simple for
**/
var arr = new Array("a","c","c");
for(var i=0; i<arr.length; i++) {
var value = arr[i];
alert(i =") "+value);
}
@precyx
precyx / ListService.ts
Last active December 18, 2019 20:35
# Sharepoint HTTP Clients - SPHttpClient - PNP HttpClient
import { SPHttpClient } from "@pnp/sp";
export interface IHttpResponseValue {
parameter: string;
}
export const getServiceUrl = async (
baseUrl: string,
listName: string,
paramName: string
@precyx
precyx / UserService.ts
Last active December 19, 2019 08:35
# Get UserID in Modern Sharepoint by context.
import { WebPartContext } from "@microsoft/sp-webpart-base";
import { SPHttpClient } from "@microsoft/sp-http";
export const getUserId = (context: WebPartContext) => {
const payload: string = JSON.stringify({
logonName: context.pageContext.user.loginName
});
var postData = {
body: payload
export const getUrlParameter = (name: string) => {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var results = regex.exec(location.search);
return results === null
? ""
: decodeURIComponent(results[1].replace(/\+/g, " "));
};
# Search query examples
## Search Query Keywords
**Filter by ContentType**`(ContentType:"PLA Prozesslink" OR ContentType:"PLA Fachbereichslink")`
## Query template
Disable Ignorecase (changing case marks files as changed).
`git config core.ignorecase false`
Reenable Ignorecase (changing case doesn't mark files as changed)
`git config core.ignorecase true`
# Debugging in SPFX:
@see: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/debug-modern-pages
## Debug URL Parameter:
?loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js
_**@note choose correct port**_